mans
mans

Reputation: 18148

Can not read/write an image in opencv

I have this code to create and write an image in opencv:

  char * outImage="C:/tmp/000014/outimage.jpg";
  Mat gray_image(imageWidth,imageHeight, CV_8UC1, Scalar(255));

  imwrite( outImage, gray_image );

but when I am running thid code, I am getting error that file extension is not known and hence iwrite can not write image.

What is wrong with this code?

edit1

I changed the code to see there is a problem with code or installation. so I have this code now

Mat x=imread("C:/tmp/a.jpg");
imshow("Image", x);
waitKey(0);

I am sure that the file c:/tmp/a.jpg exist.

When I run the application, I am getting this error:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in unknown function, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp, line 2482
C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type

I followed this answer in so to install OpenCV o my system (I use vc11, insteade of vc10 during installation) Installing OpenCV 2.4.3 in Visual C++ 2010 Express

edit 2

The problem was that I mixed the debug and release libraries,

For release use release libraries which don't have d at the end (for example opencv_calib3d243.lib instead od opencv_calib3d243d.lib)

for debug use debug libraries which has d at the end for example opencv_calib3d243d.lib

Make sure that you are using the correct lib name based on the opencv version that you have for example opencv_calib3d245d.lib for opencv 2.4.5.

Upvotes: 2

Views: 2566

Answers (2)

user349026
user349026

Reputation:

Make sure you have not mixed up release and debug DLL's of OpenCV. Plus check whether x86 or x64 DLL's would work. Sometimes x64 DLL's do mess up on x64 machines. Dont know why but I had to switch to x86 version.

Upvotes: 1

Poko
Poko

Reputation: 822

Try this:

void    write(){
    char * outImage="C:/tmp/000014/outimage.jpg";
    Mat img = Mat(Size(imageWidth,imageHeight), CV_8UC1, Scalar(255));
    imwrite(out, img);
}

Please be sure of your output path, imageWidth,imageHeight. MoreOver check your dependance (you need libjpeg8 under Linux):

For Linux

sudo apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg zlib1g zlib1g-dev pngtools libjasper-dev libjasper-runtime libjasper1 libjpeg8 libjpeg8-dbg libjpeg62 libjpeg62-dev libjpeg-progs libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev libswscale0 libswscale-dev openexr libopenexr6 libopenexr-dev

For Windows follow that guide: http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html

Upvotes: 1

Related Questions