简体   繁体   中英

Wrong size of VideoCapture using OpenCv in C++

I'm trying to make a Real-Time Tracking Application in C++ using OpenCv. My Code works so far, but the displayed camera Resolution is too small. If I take a picture/video using the Windows Camera Application the Resolution is 1280x720, the displayed resolution in my program is 639x479. This is my code:

using namespace cv;
using namespace std;

int main(int argc)
{
    VideoCapture camera(0);
    if (!camera.isOpened()) {
        cerr << "ERROR: Could not open camera" << endl;
        return 1;
    }

    namedWindow("Webcam");

    Mat frame;

    while (1) {
        camera >> frame;
        imshow("Webcam", frame);
        if (waitKey(1) >= 0) {
            break;
        }
    }

    return 0;
}

I tried using resizeWindow("Webcam", 1280, 720) but the window autosizes back to 639x479. If I put the Window in Fullscreen, the camera resolution is still 639x479. I think the problem is some VideoCapture default, but I'm not sure. How can I set the captured and displayed resolution to 1280x720?

This could also be a driver problem (see answers.opencv, the problem occurs often). Also you can try camera.set(CAP_PROP_FRAME_WIDTH, 1280.0) and the same for the height.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM