Capturing and saving/manipulating a single frame from a camera.

asked 2016-01-18 10:08:15 -0600

BartBB2 gravatar image

Hi there,

What I am trying to do sounds pretty basic to me, I just can't quite do it.

I saw code online showing how to connect to the camera and stream through it, so I thought, maybe I'll just take this specific frame and do something with it, but apparently that doesn't work.

I used VideoCapture cap and then cap.open to check if it can connect to it. Then, in a loop, something like this:

Mat frame; camp >> frame;

Then according to the code I found online, they refresh a window with the new frame taken every time in the loop. So I thought, as I said before, maybe I could use this one frame and whatnot. But whenever I try to show one specific frame in a window (additional window) the window is blank while the other window still shows the video.

The way I tried showing one frame is by creating another window and using imshow when I was halfway through the loop, just to be sure that the frame is fine and all.

Anyway! I just need to get one frame from this camera, that is it, how do I do it?

edit retag flag offensive close merge delete

Comments

If you post your code, maybe we're able to help you

LorenaGdL gravatar imageLorenaGdL ( 2016-01-18 14:11:24 -0600 )edit

If you need just one frame, use the code you posted, without loop:

Mat frame; cap>>frame; imshow("Look what I captured",frame);

If you need to capture continuously, but to keep just one frame, put it in a loop, and when you want to keep a frame, copy it to a new Mat:

int count; Mat frame,keep; while(1){cap>>frame; if(count++==100) frame>>copyto(keep);imshow("kept frame",keep);} }

(this code keeps the 100th frame, but captures continuously)

kbarni gravatar imagekbarni ( 2016-01-19 04:03:18 -0600 )edit