Asked — Edited

Capture Photos From Camera Stream

Kindly I am having an inquiry about how to use the Camera.GetCurrentBitmap to get the current frame that is shown by a camera device on a PictureBox Control in a C# Form?

When I use the C# code to access the current frame from camera stream, to get a captured image, It always give me a NullReferenceException that the Bitmap Object that is returned from Camera.GetCurrentBitmap method call is just not instantiated.


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
USA
#1  

@Saadjareer:

  1. This is almost a duplicated question, please search or scroll down the forum page.

post #1 (3 weeks ago):

https://synthiam.com/Community/Questions/9259

post #2 (1 day ago):

https://synthiam.com/Community/Questions/9321

  1. Aren't you working with Shaimaabes ?
PRO
Synthiam
#2  
  1. ensure you have the latest sdk

  2. read the help summary for the method. The bitmap is only available in the event.

PRO
USA
#3  

@Saadjareer:

post #1 (3 weeks ago)

I've created an Example Project and is publicly available, if you study/spend some time understanding the project you see the following code:


//wait 10 seconds for the first camera frame
if (this.frameEventObject.WaitOne(10000))
{
    this.camera.SaveImageAsJPEG(this.ImageFileNameTB.Text);
    this.WriteDebug("Picture done!");
}

i wait 10 seconds for a frame before saving the picture, when you connect to the camera, the execution is async, there other things going after and when the call returns the camera is not ready.

if you try immediately to get a bitmap or save an image you will get an exception

post #2 (1 day ago)

DJ's wrote:

Quote:

The camera.GetCurrentBitmap() is only available within the CameraOnOnNewFrame() event. Because until CameraOnOnNewFrame() is raised, there are no images to "get".

i was surprised with DJ's comment and if that was the reason to start post #2:


private void CameraOnOnNewFrame()
{
    this.frameEventObject.Set();
    ....
}

PRO
Synthiam
#4  

Yeah - the onNewFrame event is when a new frame arrives. There cannot be an image before that event is raised. The point to the event is as the name implies, a new frame exists. So attempting to get the bitmap/image outside of that event does not provide any verification that a frame exists. Does that make sense?

Not sure how else to explain it - the event is raised for every new frame. If you try to read a bitmap image outside of the frame event, there is no way to know if a frame is actually there or not.