<< return to Pixycam.com

Grabbing successive frames

Hello,

I’m trying to grab successive frames from the pixy, but I seem to be running into issues if I try to grab more than one frame. I’m using this code snippet that I found on another forum post:

  for(;;){
    int return_value = pixy_command("cam_getFrame", // String id for remote procedure
      0x01, 0x21, // mode
      0x02, 0, // X-offset
      0x02, 0, // Y-offset
      0x02, 320, // width
      0x02, 200, // height
      END, // separator
      &response, // pointer to the memory address for return value
      &fourcc,
      &renderflags,
      &width,
      &height,
      &numPixels,
      &pixels, // pointer to memory address for returned frame
      END);

    printf("return value: %d\n", return_value);
    printf("response value :%d\n", response);
    printf("num pixels: %d\n", numPixels);
    usleep(1000000);
  }

Here is an example of the output that I get:

return value: 0
response value :0
num pixels: 64000
return value: 0
response value :0
num pixels: 64000
return value: -1
response value :0
num pixels: 64000
return value: -1
response value :0
num pixels: 64000
return value: -3
response value :0
num pixels: 64000
return value: -3
response value :0
num pixels: 64000

It seems that the initial frame gets pulled down just fine, but somewhat non-deterministically the I am unable to grab frames from the camera after that. Am I using the api wrong? Thanks in advance.

So I actually overcame this issue by changing what program the pixy was running:

pixy_command("runprog", 0x01, 8, END, &response, END);

but the rate at which I am able to grab frames from the pixy with the method described above seems to be very slow. Could someone point me in the direction of how the video is rendered from the pixymon application? I’m having some trouble digging through the source code. Thanks in advance.

Hi John,

Processing frames for trained colors is much different than sending full frames to the desktop over USB. We’re able to process the frames on-chip very quickly due to the fast algorithm and memory, but transferring the entire image over USB is a different story. This is pretty slow since the image is uncompressed (and compressing them would take away from the processing speed). So this is why you’re experiencing a slower framerate.

Scott

Hi Scott,

It seems that the frame rate of the raw data in pixymon is pretty reasonable though. Using the code I showed above I am only able to grab about 2fps with the “cam_getFrame” command. What does pixymon do to get a better frame rate over USB?

Hmm ya that is pretty low. Pixymon and libpixyusb should be making similar calls to Pixy to get a frame. I’ll look in to it. What version of Pixy firmware, Pixymon, and libpixyusb are you using? Thanks!

Scott

Hi Scott,

I’m using the “1.0.2beta” firmware. I should mention that I’ve hacked together something that works, but I had to abandon using the “cam_getFrame” message commands. Basically what I did was just sent a “runprog 8” command and then listened for “BA81” messages to come back. I think I have a misunderstanding about what “runprog” state the camera should be in.

Hi John!

I’m currently working on a project where I need to do something similar, and in order to save some time, can I have a look at your code please? :slight_smile:

Thanks in advance!