color conversion of an image using c

asked 2014-01-23 03:48:01 -0600

CV_guy gravatar image

updated 2020-10-23 03:46:37 -0600

Hello, I'm using opencv2.7 and i tried to take a colored image convert it into gray scale and store it..But when i execute it says:

editimg.c: In function ‘main’:
editimg.c:10:2: error: unknown type name ‘Mat’
editimg.c:13:25: error: request for member ‘data’ in something not a structure or union
editimg.c:15:4: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
editimg.c:19:2: error: unknown type name ‘Mat’

And here is my code:

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

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( "/home/sumukha/sumukha/opencvsamples/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;
}
edit retag flag offensive close merge delete

Comments

1

put :

using namespace cv;

beneath the headers. also:

include <stdio.h>

berak gravatar imageberak ( 2014-01-23 04:10:01 -0600 )edit
2

You'll probably want to include c++ header rather than the old C API. You can do the lazy #include <opencv2/opencv.hpp>, which will include practically every header you ever need, instead of individual headers if you prefer.

Nghia gravatar imageNghia ( 2014-01-23 05:42:11 -0600 )edit