Load, Modify, and Save an Image

转载 2013年12月03日 08:00:11

In this tutorial you will learn how to:

  • Load an image using imread
  • Transform an image from BGR to Grayscale format by using cvtColor
  • Save your transformed image in a file on disk (using imwrite)




#include <cv.h>
#include <highgui.h>

using namespace cv;

int main( int argc, char** argv )
{
 char* imageName = argv[1];

 Mat image;
 image = imread( imageName, 1 );

 if( argc != 2 || !image.data )
 {
   printf( " No image data \n " );
   return -1;
 }

 Mat gray_image;
 cvtColor( image, gray_image, CV_BGR2GRAY );

 imwrite( "../../images/Gray_Image.jpg", gray_image );

 namedWindow( imageName, CV_WINDOW_AUTOSIZE );
 namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );

 imshow( imageName, image );
 imshow( "Gray image", gray_image );

 waitKey(0);

 return 0;
}



  1. Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice function to do this kind of transformations:

    cvtColor( image, gray_image, CV_BGR2GRAY );
    

    As you can see, cvtColor takes as arguments:

    • a source image (image)
    • a destination image (gray_image), in which we will save the converted image.
    • an additional parameter that indicates what kind of transformation will be performed. In this case we use CV_BGR2GRAY (because of imread has BGR default channel order in case of color images).





相关文章推荐

Opencv2.4.3_tutorials(学习指南)——load and display an Image

1 #include 2 #include 3 #include 4 5 using namespace cv; 6 using namespace std; 7 8 int main( int...

Modify a prepackaged image and Use YUM to install software

Modify a prepackaged image Posted: Mon, 08/09/2010 - 05:26 Hi all, I follow the instructions in...

scull-scull.init , scripts as an alternative to scull_load and scull_unload

#!/bin/bash # Sample init script for the a driver module DEVICE="scull" SECTION="misc" # The list...

16. 26. 3. 装入想要尺寸的图片 Load Image and scale it

import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.event.ActionEvent...

论文笔记:An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application

1.历史方法 1)基于字符的DCNN,比如photoOCR.单个字符的检测与识别。要求单个字符的检测器性能很强,crop的足够好。 2)直接对图片进行分类。9万个单词,组合成无数的单词,无法直接应用 ...

BaiXiang——【arXi2015】An End-to-End Trainable Neural Network for Image-based Sequence Recognition and

BaiXiang的CRNN论文阅读,主要解决单词图像识别问题,利用CNN提取特征,RNN(BLSTM+CTC)进行序列识别

Send an image from the iPhone using ASIHTTP and UIImagePicker

First you need to save the image and keep track of the filename or filepath. Here I used a time inte...

Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural

Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neur...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)