Ask Your Question
0

Does the latest OpenCV handle PNG files *properly*??

asked 2012-10-04 17:41:17 -0600

Cambridge Ray gravatar image

updated 2015-09-30 09:10:45 -0600

For a long time, I have tried to write a very simple OpenCV application, using variations of the code below. I prefer the PNG graphics format, but the code works erratically: sometimes I get a line, sometimes I get a black (empty) rectangle. If I use JPG or BMP, the program works fine.

TIA,

-Ramon

ps: My current version is OpenCV 2.1


IplImage* image = cvCreateImage(cvSize(int(8.5x72), 11x72), IPL_DEPTH_16U, 4);
cvLine(image, cvPoint(22, 44), cvPoint(456, 700), CV_RGB(255, 0, 0));
cvSaveImage("my_image.png", image);
edit retag flag offensive close merge delete

Comments

OpenCV 2.1 is not the latest.

Andrey Kamaev gravatar imageAndrey Kamaev ( 2012-10-05 08:19:41 -0600 )edit

> OpenCV 2.1 is not the latest.

I upgraded to Version 2.4.0 (2.4.2 won't build on Linux) and the inability to deal with PNG files is still present.

Cambridge Ray gravatar imageCambridge Ray ( 2012-10-05 09:27:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-10-05 01:24:47 -0600

updated 2012-10-05 03:10:55 -0600

Maybe the problem is that cvSaveImage is not handling the color depth properly. Have you tried to change the color depth to 8bits per color channel?

IplImage* image = cvCreateImage(cvSize(int(8.5x72), 11x72), IPL_DEPTH_8U, 4);

Also you should initialize all the values of image to something otherwise you can get unexpected behaviors.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-10-04 17:41:17 -0600

Seen: 401 times

Last updated: Oct 05 '12