How to capture still image from webcam on linux

前端 未结 4 846
逝去的感伤
逝去的感伤 2021-02-04 08:24

I am trying to write a C++/Qt program for linux, where I take a still image photo from a webcam, make some transformations to a photo (cropping, resizing, etc.), and save it to

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 09:01

    What about this program?

    #include
    using namespace cv;
    int main()
    {
        VideoCapture webcam;
        webcam.open(0);
        Mat frame;
        char key;
    
        while(true)
        {
            webcam >> frame;
            imshow("My Webcam",frame);
            key = waitKey(10);
    
            if(key=='s')
            break;
        }
        imwrite("webcam_capture.jpg", frame);
        webcam.release();
        return 0;
    }
    

    This will capture a picture of maximum size allowed by your webcam. Now you can add effects or resize the captured image with Qt. And OpenCV is very very easy to integrate with Qt, :)

提交回复
热议问题