OpenCV capturing desktop screen live

浪尽此生 提交于 2019-12-07 09:57:07

问题


I'm using OpenCV for a c++ coding project. I'm having some difficulty with some of the limitations in OpenCV, I want to analyse a video file and detect certain objects. This works perfectly, but now I want it to analyse a section of my desktop screen. (live)

Does anybody have a clue how to accomplish this? I thought of making a webcam simulator that captures my desktop screen but I think thats way to complicated and it should be much more easy.


回答1:


If you're targeting Windows OS, the option recommended by Engine seems ideal.

For Linux I ended up using an RTSP server(FFSERVER) as a VideoCapture input, then screencasting using FFMPEG with "x11grab".

FFMPEG for Windows will accept the "screen-capture-recorder" application as an input, but I don't have any experience setting up an RTSP server on windows.

For my setup this translated to code that looked like this:

cv::VideoCapture cap;
cap.open("http://localhost:8090/live.flv"); // open the default camera
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('F', 'L', 'V', '1'));

and

cv::resize(frame, frame, cv::Size(200, 200));
cv::VideoWriter outStream("http://localhost:8090/feed2.ffm",
CV_FOURCC('F', 'L', 'V', '1'), 10, cv::Size(200, 200), true);

The 200x200 resolution was necessary to minimize latency so if you can grab the screen buffer directly to avoid unnecessary screencasting/encoding that sounds better from a performance standpoint...



来源:https://stackoverflow.com/questions/26888605/opencv-capturing-desktop-screen-live

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!