Pelco Developer Network (PDN)

Get single frame with the best quality

Hi,

I am developing an application with Pelco SDK to connect to a Spectra Pro camera.

The main goal of the application is to take a snapshot from the live image of the camera and save it in a specific directory after an event (a button click for example). This image I want to save must have the best quality as possible (doesn’t matter the file size). As I just need one single frame from the camera after the event is trigged, so I wouldn’t like to have live image from the camera in my network all the time.

So, basically, what I am doing is starting the stream in the event trigger and using the raw frame callback function.

 private void button1_Click(object sender, EventArgs e) 
 {
            stream.DecodedMediaFrames += RawFrame;
            stream.Play(Pelco.SDK.Constants.DefaultFrameRate);
  }

Then in the callback function I just get the bitmap from the frame and save it in the directory.

 private void RawFrame(Pelco.SDK.MediaFrame frame)
  {
           saveFrame(frame.Bitmap);
           stream.DecodedMediaFrames -= RawFrame;     
           stream.Stop();
   }

By doing this I am getting a bitmap image with 3MB average size. Then, comes my first question. Am I in the right way to reach my goal? Is there anything else that I can do to improve the image quality?

Another issue is that after the first event happens and stops the stream, then the second one happens and the application gets stuck at command stream.Play. It looks like the program is processing all the existing frames between these two events. That is the reason why it is taking forever to process. What can I do to avoid this? I would like to ignore all the past frames and just get the live one.

I really appreciate any help you can provide,
Eric

Thanks for your question. You've formed the information here well and that certainly helps us to help you out best. Thanks!

I do think that what you are doing could work for your needs, though I do have a question regarding that 3BM file. What is the resolution on that saved bitmap frame?

I ask because it is possible to perform a simple HTTP GET request to a Pelco camera's JPEG URL at [camera_ip]/jpeg (more information is here: Sarix Usage though it's a little old admittedly). This might be more simple than what you are doing if all you want is a JPEG ... however, from what I have discovered with Spectra Pro and Sarix Pro is that JPEG images from those cameras are always going to be 640x480 or 640x352 (depending on if you have the stream set to 4:3 or 16:9 aspect ratio). So this option that I thought of suggesting may not work for your needs -- I wanted to include it if you had not yet seen this information. Typically if all you want is a simple 1-shot image then pulling the JPEG image from the URL would be best ... but Sarix Pro options for this are a bit more limited. If the 3MB bitmap that you are getting is a better resolution than that, you may want to stick with that method if we can get the 2nd part of your post figured out.

What I would expect to happen is that the saved bitmap is a resolution equal to the stream that you are requesting. You can navigate to the camera's web GUI at {camera_ip] and check the stream settings by logging into the GUI and look under A/V Streams-->Video Configuration.

For the 2nd issue ... are you setting up a new _stream prior to that _stream.Play() request? I only ask because I didn't see this line in your code snippets:
_stream = new Pelco.SDK.Stream(camera);

You might try checking out the RawFrames sample in the Samples directory that is installed with Pelco SDK.

One final note ... I must mention that Pelco SDK is no longer under active development. For direct developments with a Pelco camera, we typically advise development using an ONVIF driver (or Pelco API if you must). If you are performing an integration to VideoXpert, then we would instead recommend using the VX SDK and not using the Pelco SDK.

I hope this helps!

Oops! One further thing that I did neglect to mention was yet another possibility:

If you must use Pelco SDK still for your own reasons, the camera object does have a Snapshot method available. This requires a string for the filepath and a DateTime for the time of the snapshot. You might try also investigating that route. The ViewVideo sample does not have a demonstration for this, but could easily be added to the sample for you to test it out if you wanted to try that too.