Congratulations ptp, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Outputting Snapshop From Videostream In C++

Assistance Requested

Help larschrjensen with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

larschrjensen claims to have checked these sources:

Has any one had success with setting up a camera stream and saving a snapshot to a file using c++?

This is what I have so far:


EZ_B::EZB ^ezb;
ezb = gcnew EZ_B::EZB("MyEZB");

EZ_B::Camera ^ezbCam;
ezbCam = gcnew EZ_B::Camera(ezb);

ezbCam->StartCamera(EZ_B::Camera::GetVideoCaptureDevices()[1], 320, 240);

I can confirm that the camera is on by running:


BOOL camOK = ezbCam->Camera::IsActive;
cout << "Camera on? " << camOK << "\n";

What am I missing here?


I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.

Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


Most likely the camera hasn't started immediately following the Start - because it's hardware related which means there is a slight delay for the hardware to kick in.


Ah okay, so you would suggest to insert a delay before calling saveImage?


Actually that might not be your problem at all...

"C:\test.jpg" would escape the \t to be a tab character. I suspect if you checked the ezb log, it would have an error reported that it can't save the file due to the file being c:[tab]est.jpg

you need to escape the \ slash


EZ_B::EZB ^ezb;
ezb = gcnew EZ_B::EZB("MyEZB"Winky;

EZ_B::Camera ^ezbCam;
ezbCam = gcnew EZ_B::Camera(ezb);

ezbCam->StartCamera(EZ_B::Camera::GetVideoCaptureDevices()[1], 320, 240);


Hm well I don't get a warning and escaping it does not change anything. However, when I add



after calling the camera device I can get the camera to return an image size, which it didn't before. It still does not save the file though.

Any other bright ideas?

By the way, what is that smiley doing in my code DJ?


What happens if you use c:test.jpg instead of c:\test.jpg? I'm not certain, but I think DJ is saying the \t part of the c:\test.jpg character sequence is being interpreted as an escape sequence.

The smiley is usually caused by the UBB Parser interpreting the combination of a quote and a right paren as a Winky type emoticon. I just tried to demonstrate that by putting a space between the quote and the right paren to show how you could eliminate it (in my original version of this post) but it didn't do it. Maybe it's been fixed?


I've tried "test.jpg", "c:\\test.jpg", and "c://test.jpg". Same result. No errors or warnings, but also no jpeg.


So you actually tried c:test.jpg?

'test.jpg alone would try to save an image to the current default directory, whatever that may be at any time. Who knows, there may be one there. Unlike, c:\test.jpg which would try to place an image in the root directory of the C-drive, c:test.jpg will try to put one in whatever directory is currently active on the C-drive. The whole idea is to not have a slash of any kind in the path to eliminate the possibility of the slash causing an inadvertent escape to be generated. The image could even be in the directory where your EZ-Builder files are.

Basically, what I'm saying is that there may be a test.jpg image on your computer, just that it may not be in the root directory of the C-drive. Thereby leading you to conclude the image has not been stored.


Yes I realize that, but regardless of how I try to save, it's nowhere on my harddrive. This leads me to think that there is something missing in my code, I just can't figure out what.



Are you using VS to compile & run the code or using cmake to compile and run the program in the command prompt ?