c++ - OpenCV Convert Color image to Grayscale -


i trying convert color images gray-scale using opencv 2.4.11 c++ visual studio 2012. have used following code convert image grayscale. however, unable because not able read image. message "error reading image" because img empty. have stored required image in debug folder beside exe file. have mentioned image name command argument in debug section of property pages. trying store grayscale image in disk. in advance. code follows:

#include <stdio.h> #include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/nonfree/features2d.hpp"  using namespace cv;    int main(int argc, const char**argv) { mat img=imread("mountain_8-bit_grayscale.jpg", cv_load_image_grayscale);      if(img.empty())     {         std::cout<< " --(!) error reading image " << std::endl;         system("pause");         return -2;     }      namedwindow("mywindow", cv_window_autosize); //create window name "mywindow"     imshow("mywindow", img); //display image stored in 'img' in "mywindow" window      imwrite("image_bw.jpg", img);     waitkey(0);     destroywindow("mywindow");     return 0; 

}

you should try using absolute path image not relative path. other steps fine, image read , image displaying , saving commands given there path problem.


Comments