color conversion of an image using c
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;
}
put :
beneath the headers. also:
include <stdio.h>
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.