Esempio n. 1
0
static int
readCamera(moveContext *context)
{
   int ret;

   ret = cameraReadEx (0, &context->camRead);
   switch (ret) {
      case CAMERA_ERRO_NEED_START:
        cameraReset (0);
        ret = gemPrepareCamera (128, 0.5);
        printf ("GemPrepareCamera return %d exposure set to 128 and quality to 0.5 before cameraStart\n",
                ret);
        printf ("lets go!! It's time to look your face in Sony Bravia :P\n");
        ret = cameraStart (0);
        printf ("cameraStart return %d \n", ret);
        printf ("*******************************************\n");
        printf ("* Now make sure you have a Move connected\n");
        printf ("* and point it towards the camera and press\n");
        printf ("* the action button to calibrate\n");
        printf ("*******************************************\n");
        break;

      case 0:
        break;

      default:
        printf ("error %08X ", ret);
        ret = 1;
        break;
     }
   // printf("despues de start return %d \n",ret);
   if (ret == 0 && context->camRead.readcount != 0)
     {
        return context->camRead.readcount;
     }
   else {
        return 0;
     }
}
Esempio n. 2
0
  void camera_eval(void *obj, int argc) {
    tCamera *camera = (tCamera *)obj;
    try {
      ystring_t func = ygets_q(argc-1);
      if(strcmp(func, "start")==0){
	long packetSize=8228;
	if(argc >1)  packetSize = ygets_l(argc-2);
	cameraStart(camera, packetSize);
	cameraSnap(camera);
      } else if(strcmp(func, "stop")==0){
	cameraStop(camera);
      } else if(strcmp(func, "getROI")==0){
	long dims[2]={1, 4};
	long *result = ypush_l(dims);
	tPvUint32 ROI[4];
	cameraGetROI(camera, ROI);
	for(int i=0;i<4;i++)  result[i] = ROI[i];
      } else if(strcmp(func, "setROI")==0){
	long ntot, dims;
	long *result = ygeta_l(argc-2, &ntot, &dims);
	tPvUint32 ROI[4];
	for(int i=0;i<4;i++) ROI[i]=result[i];
	cameraSetROI(camera, ROI);	
      } else if(strcmp(func, "getExpo")==0){
	tPvUint32 expo;
	cameraGetExpo(camera, &expo);
	ypush_long(expo);
     } else if(strcmp(func, "setExpo")==0){
	long expo = ygets_l(argc-2);
	cameraSetExpo(camera, expo);
      } else if(strcmp(func, "fastsnap")==0){
	long param = ygets_l(argc-2);
	unsigned long width = camera->Frame.Width;              // Image width
	unsigned long height= camera->Frame.Height;             // Image height
	long dims[4]={3, width, height, param};
	if(param ==1) dims[0]=2;
	char resValue[16];
	cameraGetPixelFormat(camera, resValue, 16);
	tPvFrame *buff = cameraSnap(camera, param);

	if(strcmp(resValue, "Mono8")==0) {
	  short *frame = ypush_s(dims);
	  for(long pose=0; pose<param; pose++){
	    unsigned char *src = (unsigned char *)buff[pose].ImageBuffer;
	    short *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else if(strcmp(resValue, "Mono16")==0) {
	  int *frame = ypush_i(dims);
	  for(long pose=0; pose<param; pose++){
	    unsigned short *src = (unsigned short *)buff[pose].ImageBuffer;
	    int *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else cout << "bad ppixel size !" << endl;
      } else if(strcmp(func, "snap")==0){
	long param = ygets_l(argc-2);
	unsigned long width = camera->Frame.Width;              // Image width
	unsigned long height= camera->Frame.Height;             // Image height
	long dims[4]={3, width, height, param};
	if(param ==1) dims[0]=2;
	char resValue[16];
	cameraGetPixelFormat(camera, resValue, 16);
	
	if(strcmp(resValue, "Mono8")==0) {
	  short *frame = ypush_s(dims);
	  for(long pose=0; pose<param; pose++){
	    cameraSnap(camera);
	    unsigned char *src = (unsigned char *)camera->Frame.ImageBuffer;
	    short *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else if(strcmp(resValue, "Mono16")==0) {
	  int *frame = ypush_i(dims);
	  for(long pose=0; pose<param; pose++){
	    cameraSnap(camera);
	    unsigned short *src = (unsigned short *)camera->Frame.ImageBuffer;
	    int *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else cout << "bad ppixel size !" << endl;
      } else cout << "F**K !" << endl;

    } catch ( string msg ) {
      y_error(msg.c_str());
    }
    catch ( char const * msg ) {
      y_error(msg);
    }
  }