简体   繁体   English

在 C++ 中使用 OpenCv 的 VideoCapture 大小错误

[英]Wrong size of VideoCapture using OpenCv in C++

I'm trying to make a Real-Time Tracking Application in C++ using OpenCv.我正在尝试使用 OpenCv 在 C++ 中制作实时跟踪应用程序。 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.如果我使用 Windows 相机应用程序拍摄照片/视频,分辨率为 1280x720,我的程序中显示的分辨率为 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.我尝试使用resizeWindow("Webcam", 1280, 720)但 window 自动调整回 639x479。 If I put the Window in Fullscreen, the camera resolution is still 639x479.如果我把Window全屏,相机分辨率还是639x479。 I think the problem is some VideoCapture default, but I'm not sure.我认为问题是某些 VideoCapture 默认值,但我不确定。 How can I set the captured and displayed resolution to 1280x720?如何将捕获和显示的分辨率设置为 1280x720?

This could also be a driver problem (see answers.opencv, the problem occurs often).这也可能是驱动程序问题(请参阅 answers.opencv,该问题经常发生)。 Also you can try camera.set(CAP_PROP_FRAME_WIDTH, 1280.0) and the same for the height.您也可以尝试camera.set(CAP_PROP_FRAME_WIDTH, 1280.0)和相同的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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