Asked — Edited
Resolved Resolved by ptp!

Outputting Snapshop From Videostream In C++

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);
ezbCam->SaveImageAsJPEG("c:\test.jpg");

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?

Best, Lars


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

PRO
USA
#9  

Lars,

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

#10  

Cmake to generate the vs solution, after that vs to build and run

PRO
USA
#11  

some guesses as usual ...

  1. EZB relies on windows libraries, one of them is the System.Drawing, if not in your dll references, please add.

  2. If is still not working, check the current bitmap and try to save:

c# code, convert to equivalent c++/cli:


Bitmap bitmap = cam.GetCurrentBitmap;
bitmap.Save(&quot;c:\\test1.jpg&quot;);

let me know if you got success with any of the steps.

PRO
Synthiam
#12  

Can you post the content from the ezb log before the program ends?

Get it from this property...


ezb-&gt;GetLastErrorMsg

#13  

DJ and ptp, I got caught up in something else and will be at a demo (with a few EZ-B's) all day tomorrow. I'll get back to you on sunday, monday at the latest. Thanks for you help so far!

PRO
Synthiam
#14  

Sounds good! Keep in touch!

#15  

Okay

@Sures: This is the output from GetLastErrorMsg:


Camera on? 1
image size: 10764
07-02-2016 19:59 - Object Recognition Initialized.
07-02-2016 19:59 - Camera Initialized: EZB://192.168.1.1 @ 320x240
07-02-2016 19:59 - Save Image (c:\test.jpg) Error: System.NullReferenceException: Object reference not set to an instance of an object.
   at EZ_B.Camera.SaveImageAsJPEG(String filename)
07-02-2016 19:59 - Camera Disabled

Using this source:


EZ_B::EZB ^ezb;
ezb = gcnew EZ_B::EZB(&quot;MyEZB&quot;);
EZ_B::Camera ^ezbCam;
ezbCam = gcnew EZ_B::Camera(ezb);

ezbCam-&gt;StartCamera(EZ_B::Camera::GetVideoCaptureDevices()[1], 320, 240);
Sleep(1000);
cout &lt;&lt; &quot;Camera on? &quot; &lt;&lt; ezbCam-&gt;Camera::IsActive &lt;&lt; &quot;\n&quot;;
cout &lt;&lt; &quot;image size: &quot; &lt;&lt; ezbCam-&gt;GetEZBv4CameraImageSize &lt;&lt; &quot;\n&quot;;
ezbCam-&gt;SaveImageAsJPEG(&quot;c:\\test.jpg&quot;);
ezbCam-&gt;StopCamera();

#16  

@ptp: yes the System.Drawing dll is in the references.

So I tried this:


Bitmap^ image = gcnew Bitmap(ezbCam-&gt;GetCurrentBitmap);

which compiles fine, but gives an unhandles exception and complains that object reference is not set to instance of an object at:


EZ_B.Camera.get_GetCurrentBitmap()

Thus, more or less the same error I get when running SaveAsJPEG.