⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera1394.cc

📁 机器人仿真软件
💻 CC
📖 第 1 页 / 共 3 页
字号:
  }  else if (0==strcmp(str,"1024x768_mono"))  {    this->mode = MODE_1024x768_MONO;    this->format = FORMAT_SVGA_NONCOMPRESSED_1;    this->frameSize = 1024 * 768 * 1;  }  else if (0==strcmp(str,"1024x768_yuv422"))  {    this->mode = MODE_1024x768_YUV422;    this->format = FORMAT_SVGA_NONCOMPRESSED_1;    this->frameSize = 512 * 384 * 3;  }  else if (0==strcmp(str,"1280x960_mono"))  {    this->mode = MODE_1280x960_MONO;    this->format = FORMAT_SVGA_NONCOMPRESSED_2;    this->frameSize = 1280 * 960 * 1;  }  else if (0==strcmp(str,"1280x960_yuv422"))  {    this->mode = MODE_1280x960_YUV422;    this->format = FORMAT_SVGA_NONCOMPRESSED_2;    this->frameSize = 640 * 480 * 3;  }#if LIBDC1394_VERSION == 0200  else if (0==strcmp(str,"FORMAT7_MODE0"))  {    this->mode = MODE_FORMAT7_0;    this->format = FORMAT_7;    this->frameSize = 0;  }#endif  else  {    PLAYER_ERROR1("unknown video mode [%s]", str);    this->SetError(-1);    return;  }  // Many cameras such as the Pt Grey Dragonfly and Bumblebee devices  // don't do onchip colour conversion. Various Bayer colour encoding   // patterns and decoding methods exist. They are now presented to the   // user as config file options.  // check Bayer colour decoding option  str =  cf->ReadString(section, "bayer", "NONE");  this->DoBayerConversion = false;  if (strcmp(str,"NONE"))       {	    if (!strcmp(str,"BGGR"))		 {		      this->DoBayerConversion = true;		      this->BayerPattern = BAYER_PATTERN_BGGR;		 }	    else if (!strcmp(str,"GRBG"))		 {		      this->DoBayerConversion = true;		      this->BayerPattern = BAYER_PATTERN_GRBG;		 }	    else if (!strcmp(str,"RGGB"))		 {		      this->DoBayerConversion = true;		      this->BayerPattern = BAYER_PATTERN_RGGB;		 }	    else if (!strcmp(str,"GBRG"))		 {		      this->DoBayerConversion = true;		      this->BayerPattern = BAYER_PATTERN_GBRG;		 }	    else		 {		      PLAYER_ERROR1("unknown bayer pattern [%s]", str);		      this->SetError(-1);		      return;		 }       }  // Set default Bayer decoding method  if (this->DoBayerConversion)       this->BayerMethod = BAYER_DECODING_DOWNSAMPLE;  else       this->BayerMethod = NO_BAYER_DECODING;  // Check for user selected method  str =  cf->ReadString(section, "method", "NONE");  if (strcmp(str,"NONE"))       {	    if (!this->DoBayerConversion)		 {		      PLAYER_ERROR1("bayer method [%s] specified without enabling bayer conversion", str);		      this->SetError(-1);		      return;		 }	    if (!strcmp(str,"DownSample"))		 {		      this->BayerMethod = BAYER_DECODING_DOWNSAMPLE;		 }	    else if (!strcmp(str,"Nearest"))		 {		      this->BayerMethod = BAYER_DECODING_NEAREST;		 }	    else if (!strcmp(str,"Edge"))		 {		      this->BayerMethod = BAYER_DECODING_EDGE_SENSE;		 }	    else		 {		      PLAYER_ERROR1("unknown bayer method [%s]", str);		      this->SetError(-1);		      return;		 }       }  // Allow the user to set useful camera setting options  // brightness, exposure, redBalance, blueBalance, shutter and gain  // Parse camera settings - default is to leave them alone.   str =  cf->ReadString(section, "brightness", "NONE");  if (strcmp(str,"NONE"))       if (!strcmp(str,"auto"))	    {		 this->setBrightness=true;		 this->autoBrightness=true;	    }       else	    {		 this->setBrightness=true;		 this->autoBrightness=false;		 this->brightness = atoi(str);		 	    }  str =  cf->ReadString(section, "exposure", "NONE");  if (strcmp(str,"NONE"))       if (!strcmp(str,"auto"))	    {		 this->setExposure=true;		 this->autoExposure=true;	    }       else	    {		 this->setExposure=true;		 this->autoExposure=false;		 this->exposure = atoi(str);		 	    }  str =  cf->ReadString(section, "shutter", "NONE");  if (strcmp(str,"NONE"))       if (!strcmp(str,"auto"))	    {		 this->setShutter=true;		 this->autoShutter=true;	    }       else	    {		 this->setShutter=true;		 this->autoShutter=false;		 this->shutter = atoi(str);		 	    }  str =  cf->ReadString(section, "gain", "NONE");  if (strcmp(str,"NONE"))       if (!strcmp(str,"auto"))	    {		 this->setGain=true;		 this->autoGain=true;	    }       else	    {		 this->setGain=true;		 this->autoGain=false;		 this->gain = atoi(str);		 	    }  str =  cf->ReadString(section, "whitebalance", "NONE");  if (strcmp(str,"NONE"))       if(sscanf(str,"%u %u",&this->blueBalance,&this->redBalance)==2)	    this->setWhiteBalance=true;       else	    PLAYER_ERROR1("didn't understand white balance values [%s]", str);  // Force into raw mode  this->forceRaw = cf->ReadInt(section, "force_raw", 0);   // Save frames?  this->save = cf->ReadInt(section, "save", 0);  // Number of DMA buffers?  this->num_dma_buffers = cf->ReadInt(section, "dma_buffers", NUM_DMA_BUFFERS);    return;}////////////////////////////////////////////////////////////////////////////////// Safe Cleanupvoid Camera1394::SafeCleanup(){  delete resized;  resized = NULL;#if LIBDC1394_VERSION == 0200  if (this->camera)  {    dc1394_cleanup_iso_channels_and_bandwidth(camera);    switch (this->method)    {    case methodRaw:      //dc1394_release_camera(this->camera);      break;    case methodVideo:      //dc1394_dma_unlisten(this->camera);      //dc1394_dma_release_camera(this->camera);      break;    }    dc1394_free_camera(this->camera);  }  this->camera = NULL;#else  if (this->handle)  {    switch (this->method)    {    case methodRaw:      dc1394_release_camera(this->handle, &this->camera);      break;    case methodVideo:      dc1394_dma_unlisten(this->handle, &this->camera);      dc1394_dma_release_camera(this->handle, &this->camera);      break;    }    dc1394_destroy_handle(this->handle);  }  this->handle = NULL;#endif}////////////////////////////////////////////////////////////////////////////////// Set up the device (called by server thread).int Camera1394::Setup(){#if LIBDC1394_VERSION == 0200  dc1394speed_t speed;#else  unsigned int channel, speed;#endif  // Create a handle for the given port (port will be zero on most  // machines)#if LIBDC1394_VERSION == 0200  // First we try to find a camera  int err;  dc1394camera_t **dccameras=NULL;  unsigned int camnum=0;	  if ((err=dc1394_find_cameras(&dccameras,&camnum)) != DC1394_SUCCESS)  {    PLAYER_ERROR1("Could not get Camera List: %d\n", err);	    return -1;  }  if (camnum <=0)    return -1;  // we just use the first one returned and then free the rest  camera = dccameras[0];  for (unsigned int i=1;i<camnum;i++)    free(dccameras[i]);  if (camnum>0)	  free(dccameras);	  dc1394_cleanup_iso_channels_and_bandwidth(camera);  if (this->camera == NULL)  {    PLAYER_ERROR("Unable to acquire a dc1394 camera");    this->SafeCleanup();    return -1;  }#else  this->handle = dc1394_create_handle(this->port);  if (this->handle == NULL)  {    PLAYER_ERROR("Unable to acquire a dc1394 handle");    this->SafeCleanup();    return -1;  }  this->camera.node = this->node;  this->camera.port = this->port;#endif  // apply user config file provided camera settings  if (this->setBrightness)  {#if LIBDC1394_VERSION == 0200    if (DC1394_SUCCESS != dc1394_feature_set_mode(this->camera, FEATURE_BRIGHTNESS,this->autoBrightness ? DC1394_FEATURE_MODE_AUTO : DC1394_FEATURE_MODE_MANUAL))#else    if (DC1394_SUCCESS != dc1394_auto_on_off(this->handle, this->camera.node,FEATURE_BRIGHTNESS,this->autoBrightness))#endif    {      PLAYER_ERROR("Unable to set Brightness mode");      this->SafeCleanup();      return -1;    }    if (!this->autoBrightness)    {#if LIBDC1394_VERSION == 0200      if (DC1394_SUCCESS != dc1394_feature_set_value(this->camera, FEATURE_BRIGHTNESS,this->brightness))#else      if (DC1394_SUCCESS != dc1394_set_brightness(this->handle, this->camera.node,this->brightness))#endif      {        PLAYER_ERROR("Unable to set Brightness value");        this->SafeCleanup();        return -1;      }    }  }  if (this->setExposure)  {#if LIBDC1394_VERSION == 0200    if (DC1394_SUCCESS != dc1394_feature_set_mode(this->camera, FEATURE_EXPOSURE,this->autoExposure ? DC1394_FEATURE_MODE_AUTO : DC1394_FEATURE_MODE_MANUAL))#else    if (DC1394_SUCCESS != dc1394_auto_on_off(this->handle, this->camera.node,FEATURE_EXPOSURE,this->autoExposure))#endif    {      PLAYER_ERROR("Unable to set Exposure mode");		  this->SafeCleanup();		  return -1;    }    if (!this->autoExposure)    {#if LIBDC1394_VERSION == 0200      if (DC1394_SUCCESS != dc1394_feature_set_value(this->camera, FEATURE_EXPOSURE,this->exposure))#else      if (DC1394_SUCCESS != dc1394_set_exposure(this->handle, this->camera.node,this->exposure))#endif      {		    PLAYER_ERROR("Unable to set Exposure value");		    this->SafeCleanup();		    return -1;		  }    }  }  if (this->setShutter)  {#if LIBDC1394_VERSION == 0200    if (DC1394_SUCCESS != dc1394_feature_set_mode(this->camera, FEATURE_SHUTTER,this->autoShutter ? DC1394_FEATURE_MODE_AUTO : DC1394_FEATURE_MODE_MANUAL))#else    if (DC1394_SUCCESS != dc1394_auto_on_off(this->handle, this->camera.node,FEATURE_SHUTTER,this->autoShutter))#endif    {		  PLAYER_ERROR("Unable to set Shutter mode");		  this->SafeCleanup();		  return -1;		}	  if (!this->autoShutter)    {#if LIBDC1394_VERSION == 0200      if (DC1394_SUCCESS != dc1394_feature_set_value(this->camera, FEATURE_SHUTTER,this->shutter))#else      if (DC1394_SUCCESS != dc1394_set_shutter(this->handle, this->camera.node,this->shutter))#endif      {		    PLAYER_ERROR("Unable to set Shutter value");		    this->SafeCleanup();		    return -1;		  }    }  }  if (this->setGain)  {#if LIBDC1394_VERSION == 0200    if (DC1394_SUCCESS != dc1394_feature_set_mode(this->camera, FEATURE_GAIN,this->autoGain ? DC1394_FEATURE_MODE_AUTO : DC1394_FEATURE_MODE_MANUAL))#else    if (DC1394_SUCCESS != dc1394_auto_on_off(this->handle, this->camera.node,FEATURE_GAIN,this->autoGain))#endif    {		  PLAYER_ERROR("Unable to set Gain mode");		  this->SafeCleanup();		  return -1;		}	  if (!this->autoShutter)    {#if LIBDC1394_VERSION == 0200      if (DC1394_SUCCESS != dc1394_feature_set_value(this->camera, FEATURE_GAIN,this->gain))#else		  if (DC1394_SUCCESS != dc1394_set_gain(this->handle, this->camera.node,this->gain))#endif      {		    PLAYER_ERROR("Unable to Gain value");		    this->SafeCleanup();		    return -1;		  }    }  }  if (this->setWhiteBalance)  {#if LIBDC1394_VERSION == 0200    if (DC1394_SUCCESS != dc1394_feature_whitebalance_set_value(this->camera,this->blueBalance,this->redBalance))#else    if (DC1394_SUCCESS != dc1394_set_white_balance(this->handle, this->camera.node,this->blueBalance,this->redBalance))#endif		{		  PLAYER_ERROR("Unable to set White Balance");		  this->SafeCleanup();		  return -1;		}  }  // Collects the available features for the camera described by node and  // stores them in features.#if LIBDC1394_VERSION == 0200  if (DC1394_SUCCESS != dc1394_get_camera_feature_set(camera, &this->features))#else  if (DC1394_SUCCESS != dc1394_get_camera_feature_set(this->handle, this->camera.node,                                                       &this->features))#endif  {    PLAYER_ERROR("Unable to get feature set");    this->SafeCleanup();    return -1;  }  // TODO: need to indicate what formats the camera supports somewhere  // Remove; leave?  dc1394_print_feature_set(&this->features);#if LIBDC1394_VERSION == 0200  // if format 7 requested check that it is supported  if (FORMAT_7==this->format && DC1394_SUCCESS!=dc1394_format7_get_modeset(camera, &modeset))  {    bool HasMode7 = false;    for (unsigned int i=0;i<DC1394_VIDEO_MODE_FORMAT7_NUM;i++)     {      if (modeset.mode[i].present!=0)       {        HasMode7 = true;        break;	      }    }    if (!HasMode7)    {      PLAYER_ERROR("Could not set Format 7");      this->SafeCleanup();      return -1;    }  }#endif  // Get the ISO channel and speed of the video#if LIBDC1394_VERSION == 0200  if (DC1394_SUCCESS != dc1394_video_get_iso_speed(this->camera, &speed))#else  if (DC1394_SUCCESS != dc1394_get_iso_channel_and_speed(this->handle, this->camera.node,                                                          &channel, &speed))#endif  {    PLAYER_ERROR("Unable to get iso data; is the camera plugged in?");    this->SafeCleanup();    return -1;  }#if DC1394_DMA_SETUP_CAPTURE_ARGS == 11  // Set camera to use DMA, improves performance.  if (!this->forceRaw &&      dc1394_dma_setup_capture(this->handle, this->camera.node, channel,                               this->format, this->mode, speed,                               this->frameRate, this->num_dma_buffers, 1, NULL,                               &this->camera) == DC1394_SUCCESS)#elif DC1394_DMA_SETUP_CAPTURE_ARGS == 12  // Set camera to use DMA, improves performance.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -