Ask Your Question
1

How to make an array from a screen capture for avi for c++

asked 2019-11-10 08:48:37 -0600

mblackbourne gravatar image

updated 2019-11-10 16:41:47 -0600

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

edit retag flag offensive close merge delete

Comments

1

???? VideoWriter writes Mats. It does not return objects or use parameter src or use class "frame", whatever that is.

mvuori gravatar imagemvuori ( 2019-11-10 09:38:17 -0600 )edit
1

Look at the link I posted. That's the "src" I am talking about. I'm new to opencv.

mblackbourne gravatar imagemblackbourne ( 2019-11-10 09:54:43 -0600 )edit
1

@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 gravatar imageberak ( 2019-11-10 10:21:29 -0600 )edit
2

@berak edited question for clarity.

mblackbourne gravatar imagemblackbourne ( 2019-11-10 10:44:50 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2019-11-10 15:46:05 -0600

the problem on your code is here

video.write(src);

src is 4 channel (BGRA) you need to convert it to BGR

you can find here the sample source i recently updated.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-11-10 08:48:37 -0600

Seen: 2,094 times

Last updated: Nov 10 '19