First time here? Check out the FAQ!

Ask Your Question
0

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

asked Oct 4 '12

Cambridge Ray gravatar image

updated Sep 30 '15

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);
Preview: (hide)

Comments

OpenCV 2.1 is not the latest.

Andrey Kamaev gravatar imageAndrey Kamaev (Oct 5 '12)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 (Oct 5 '12)edit

1 answer

Sort by » oldest newest most voted
2

answered Oct 5 '12

updated Oct 5 '12

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.

Preview: (hide)

Question Tools

Stats

Asked: Oct 4 '12

Seen: 431 times

Last updated: Oct 05 '12