C++ Fast Screenshots in Linux for Use with Opencv

How to take screenshots fast in Java?

u should definitely give a shot to OpenCV

Capture 2 non-consecutive frames using a webcam in OpenCV

If You are working on linux, then You will have to empty the buffer from capturing device. I do it by running a separate thread that reads the frames and remembers only the last one. When I want to take a frame for further processing, I clone the one which is now remembered. But, in Your case it might be a slight overkill.

Also, You might like to do something like this instead of Your current main loop:

cv::Mat temp,img1,img2;
cv::VideoCapture cap(1);
char control=' ';
cv::namedWindow("current",CV_AUTOSIZE);
cv::namedWindow("img1",CV_AUTOSIZE);
cv::namedWindow("img2",CV_AUTOSIZE);
do{
if(49 == control){
img1=temp.clone();
cv::imshow("img1",img1);
}else if(50 == control){
img2=temp.clone();
cv::imshow("img2",img2);
}
cap>>tmp; //emptying buffer all the time
cv::imshow("current",tmp);
control=cv::waitKey(40);//if You are faster than captures fps
}while(27 != control);

Fastest way to take a screenshot with python on windows

You could use win32 APIs directly .

  1. First give the focus to the App that you want to take screenshot of.
    link text

  2. Win32 API can help with the screenshot:

import win32gui
import win32ui
import win32con

w = 1920 # set this
h = 1080 # set this
bmpfilenamename = "out.bmp" #set this

hwnd = win32gui.FindWindow(None, windowname)
wDC = win32gui.GetWindowDC(hwnd)
dcObj=win32ui.CreateDCFromHandle(wDC)
cDC=dcObj.CreateCompatibleDC()
dataBitMap = win32ui.CreateBitmap()
dataBitMap.CreateCompatibleBitmap(dcObj, w, h)
cDC.SelectObject(dataBitMap)
cDC.BitBlt((0,0),(w, h) , dcObj, (0,0), win32con.SRCCOPY)
dataBitMap.SaveBitmapFile(cDC, bmpfilenamename)

# Free Resources
dcObj.DeleteDC()
cDC.DeleteDC()
win32gui.ReleaseDC(hwnd, wDC)
win32gui.DeleteObject(dataBitMap.GetHandle())


Related Topics



Leave a reply



Submit