Data loss from camera stream

asked 2018-08-27 02:51:53 -0500

Kircholm gravatar image

updated 2018-08-27 03:04:52 -0500

Hi, I'm using Logitech 270c which supports 1280x720 resolution. I have set that resolution in "Logitech webcam software", it is even proper read by windowses 10 "camera" tool. To open the camera stream in my C++ program im simply using:

VideoCapture capture;;

if (!capture.isOpened())
    cout << "Cannot open video stream." << endl;
    return -1;

//capture.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
//capture.set(CV_CAP_PROP_FRAME_HEIGHT, 720);

cout << "Resolution: " << capture.get(CV_CAP_PROP_FRAME_WIDTH) << "/" << capture.get (CV_CAP_PROP_FRAME_HEIGHT) << endl;

Mat frame;
namedWindow("Video", WINDOW_AUTOSIZE);
Rect roi(roi_x, roi_y, roi_width, roi_height);

while (capture.isOpened())
    if ( == false)
        cout << "End of video stream" << endl;

    imshow("Video", frame);

    int control_button = waitKey(10);
        if (static_cast<int>('c') == control_button)

But the resolution of camera is set to 640x480 I have tried to use:

capture.set(CV_CAP_PROP_FRAME_WIDTH, 1280); capture.set(CV_CAP_PROP_FRAME_HEIGHT, 720);

The resolution is now set to 1280x720, the Video window seams bigger however it sims like the image it "resized" and ther camera resolution did not change, what is warse the image is cropped and i cant get full image from the camera.

I have searched the Internet looking for solution of this problem but I have not even find any one with it. It is also my first ticket here, so if anything is unclear, there is some missing info pleas do not hesitate to comment.

edit retag flag offensive close merge delete


Opencv version?

"But the resolution of camera is set to 640x480 " and "The resolution is now set to 1280x720," : I don't understand

LBerger gravatar imageLBerger ( 2018-08-27 03:02:06 -0500 )edit

openCV version: 3.4.2

I meant: If i run this commends: capture.set(CV_CAP_PROP_FRAME_WIDTH, 1280); capture.set(CV_CAP_PROP_FRAME_HEIGHT, 720);

the cout << "Resolution: " << capture.get(CV_CAP_PROP_FRAME_WIDTH) << "/" << capture.get (CV_CAP_PROP_FRAME_HEIGHT) << endl;

will return "Resolution: 1280/720" but it has no impact on the stream that i get from, despite bigger "frame" format.

Kircholm gravatar imageKircholm ( 2018-08-27 03:49:19 -0500 )edit

Let give an example: The cammera is looking on whole chess board (8x8 grid). If im using "camera" tool given by Windows 10 there are 2 outcomes:

  • 640x480 rosolution: small image and I only see only 6x8 grid (some parts are missing)
  • 1280x720 resolution: big image and I see full 8x8 grid

If im using opencCV code:

  • 640x480 resolution (which is set when camera is opened) small image and 6x8 grid
  • if i force 1280x720 resolution with given command -> big image but still 6x8 grid is visable :(
Kircholm gravatar imageKircholm ( 2018-08-27 03:50:11 -0500 )edit

when you change resolution on C270, you don't change ROI on CCD surface but only resize image grab by sensor.

LBerger gravatar imageLBerger ( 2018-08-27 09:10:38 -0500 )edit

So is there any chance to set resolution? The same code in java solves the problem :/

Kircholm gravatar imageKircholm ( 2018-12-07 01:35:13 -0500 )edit