How to make an array from a screen capture for avi for c++
I have used the info in this link. To build the base of the screen capture tool. https://stackoverflow.com/questions/1...
I have the imshow working fine along with imwrite. I added the codec for the video write. The understanding is: videowriter processes frames. The src is returned as the "frame". I tried using video.write(InputArray(src)); but that also didn't work. Using python numpy builds the array frame that write reads from. Would it be possible to add src to the Video Capture?
int main(int argc, char** argv)
{
std::cout << "Starting Script" << std::endl;
HWND hwndDesktop = GetDesktopWindow(); //FindWindowEx();
namedWindow("output", WINDOW_NORMAL);
int key = 0;
Mat src = hwnd2mat(hwndDesktop); // src =frame
VideoWriter video("out.avi", cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), 10, Size(src.size()), true); // ctlHeight, ctlWidth
int count = 0;
//video.open();
while (key != 27)
//for(;;)
{
// InputArray img = src;
video.write(src);
//count++;
//imwrite("outer.jpg", src);
imshow("output", src);
key = waitKey(60); // you can change wait time
}
exception();
//ReleaseCapture();
//video.release();
//destroyAllWindows();
return 0;
}
The above is how I am trying to make the capture into a video.
In python to create the array that is passed to the VideoWriter::Write(); looks like the following:
while(True):
img = ImageGrab.grab(bbox=(0, 0, width, height))#testSpec: bbox=(0, 0, 800, 1000)
img_np = np.array(img)
I have tried using the InputArray() included in opencv so the write looks more like:
video.write(InputArray(src));
Which should be similar to
video.write(img_np)
Either way, the above imshow() works perfectly. The Imwrite() works perfectly. but the AVI will not write anything. It creates the file but it is empty.
I also get the error of: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): out.avi in function 'cv::icvExtractPattern
Windows10 vcpkg install 4.1.1
???? VideoWriter writes Mats. It does not return objects or use parameter src or use class "frame", whatever that is.
Look at the link I posted. That's the "src" I am talking about. I'm new to opencv.
@mblackbourne can you ask a real question here, not link to another ?
can we see YOUR code there ?
also, os, opencv version, how did you install it ?
@berak edited question for clarity.