Ask Your Question
0

libpng warning: Image width is zero in IHDR

asked 2015-04-18 04:44:59 -0600

Akki gravatar image

updated 2020-10-26 06:56:58 -0600

hello, I am trying to capture imgae from camera, using code

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int, char**)
{


    VideoCapture cap(0); // open the default camera
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    if(!cap.isOpened())  // check if we succeeded
        return -1;

    for(;;)
    {
        Mat frame;

        cap >> frame; // get a new frame from camera

        imwrite("C:/Users/ankit/Desktop/12.png", frame);

    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

but i am getting error like,

libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data

please give me any suggesitions to solve this error.

Thank you very much in advace.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-04-18 04:56:37 -0600

berak gravatar image

updated 2015-04-18 07:26:21 -0600

that's an empty image. your camera probably needs a 'warmup' time, and delivers empty frames on startup.

try:

for(;;)
{
    Mat frame;

    cap >> frame;      // get a new frame from camera
    if (frame.empty()) // skip invalid images
         continue;

    bool ok = imwrite("C:/Users/ankit/Desktop/12.png", frame);
    // we've written the image, can go home now:
    if (ok)
        break;    
}
edit flag offensive delete link more

Comments

thank you very much for comment. its working fine without error now. but how can i capture one frame and then program should be stop. in my caseits running continuosly. i want to take capture the picture form camera.

Akki gravatar imageAkki ( 2015-04-18 05:58:47 -0600 )edit

ok, please see edit .

berak gravatar imageberak ( 2015-04-18 07:24:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-04-18 04:44:59 -0600

Seen: 10,338 times

Last updated: Apr 18 '15