简体   繁体   中英

How to get frames from c920 camera using OpenCV4 C++

I'm trying to get frames form a Logitec c920 camera and show them. The camera seems to be working but nothing is being shown on the display window.

I tried to configure all the camera settings but nothing. What am I missing???


    #include "pch.h"
    #include <iostream>
    #include "opencv2\imgcodecs.hpp"
    #include "opencv2\core.hpp"
    #include "opencv2\highgui.hpp"
    #include "opencv2\videoio.hpp"

    using namespace std;
    using namespace cv;

    int main()
    {

        VideoCapture camera(CAP_ANY);

        Mat frame;
        namedWindow("x", WINDOW_AUTOSIZE);

        camera.set(CAP_PROP_FOURCC, VideoWriter::fourcc('M', 'J', 'P', 'G'));
        camera.set(CAP_PROP_FRAME_WIDTH, 1920);
        camera.set(CAP_PROP_FRAME_HEIGHT, 1080);


        while (1)
        {

            camera.read(frame);
            imshow("x", frame);

        }

        waitKey(0);
        return 0;

    }

You have to put waitKey(int delay) after each frame. Your while loop should look like this:

while (1)
    {

        camera.read(frame);
        imshow("x", frame);
        waitKey(1);

    }

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