I’m making some progress starting with low resolution frames, but Pixy is returning a frame of all zeros. Below is the code I’m using, cribbed from various forum posts. Is something else required other than initialize the Pixy? I’ve seen references to “start”/“stop” or “run” commands. I believe, but am not certain, that AWB and AEC are set as the default. PixyMon returns a fine image of my workbench, of course.
As always, help is much appreciated!
The current program output, plus an 8x8 pixel block from about the center of the frame, is as follows:
pi@raspberrypi:~/pixy/build/hello_pixy$ sudo ./hello_pixy
initialized Pixy - 0
getFrame return value 0 response 0
returned w 320 h 200 npix 64000
average pixel value 0
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
#include
#include
#include
#include
#include
#include "pixy.h"
void handle_SIGINT(int unused)
{
// On CTRL+C - abort //
printf("\nBye!\n");
exit(0);
}
int main(int argc, char * argv[])
{
int index;
int blocks_copied;
int pixy_init_status;
// Catch CTRL+C (SIGINT) signals //
signal(SIGINT, handle_SIGINT);
// Connect to Pixy //
pixy_init_status = pixy_init();
printf("initialized Pixy - %d\n", pixy_init_status);
// Was there an error initializing pixy? //
if(!pixy_init_status == 0)
{
// Error initializing Pixy //
printf("pixy_init(): ");
pixy_error(pixy_init_status);
return pixy_init_status;
}
// getFrame Example //
{
unsigned char pixels[72000]={0xff};
int32_t response, fourcc;
int8_t renderflags;
int return_value, res;
uint16_t width, height;
uint32_t numPixels;
response = 0;
return_value = pixy_command("cam_getFrame", // String id for remote procedure
0x01, 0x21, // mode
0x02, 0, // xoffset
0x02, 0, // yoffset
0x02, 320, // width
0x02, 200, // height
0, // separator
&response, // pointer to mem address for return value
&fourcc, //for some reason these 5 args are needed, contrary to the docs
&renderflags,
&width,
&height,
&numPixels,
&pixels, // pointer to mem address for returned frame
0);
fprintf(stderr,"getFrame return value %d response %d\n", return_value, response);
printf("returned w %d h %d npix %d \n",width,height,numPixels);
// check success:
if(return_value != 0) return return_value;
// display 8x8 block
unsigned int i,j,ind,start;
unsigned long avg=0;
for(i=0; i<numPixels; i++) avg += pixels[i];
avg = avg/numPixels;
printf(" average pixel value %d \n",avg);
start=100*320+160; //roughly in middle of frame
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
ind=i*width+j+start;
printf(" %02x",pixels[ind]);
}
printf("\n");
}
// Sleep for 1/10 sec //
while(1) usleep(100000);
//(exit on ^C)
}
}