Beispiel #1
0
void CMUCamera::setFeature(CameraFeature Feature, int Value, bool bIgnoreOldValue)
{
    if (bIgnoreOldValue || m_Features[Feature] != Value) {
        m_Features[Feature] = Value;
        if (Feature == CAM_FEATURE_STROBE_DURATION) {
            if (m_pCamera->HasStrobe()) {
                C1394CameraControlStrobe* pControl = m_pCamera->GetStrobeControl(0);
                int err = pControl->SetValue(Value);
                checkCMUWarning(err == CAM_SUCCESS, "Error setting camera strobe.");
            } else {
                AVG_TRACE(Logger::WARNING, "Camera does not support strobe.");
            }
        } else {
            CAMERA_FEATURE cmuFeature = getFeatureID(Feature);
            if (m_pCamera->HasFeature(cmuFeature)) {
                bool bAuto = (Value == -1);
                
                C1394CameraControl* pControl = m_pCamera->GetCameraControl(cmuFeature);
                int err1 = pControl->SetAutoMode(bAuto);
                int err2 = CAM_SUCCESS;
                if (!bAuto) {
                    err2 = pControl->SetValue(Value);
                }
                checkCMUWarning(err1 == CAM_SUCCESS && err2 == CAM_SUCCESS, 
                        string("Error setting camera feature: ") + 
                        cameraFeatureToString(Feature));
            } else {
                AVG_TRACE(Logger::WARNING, string("Camera does not support feature: ") + 
                        cameraFeatureToString(Feature));
            }
        }
    }
}
Beispiel #2
0
/*! 
   Disable auto shutter and set the shutter to the requested value. 

   \sa setAutoShutter()
   */
void vp1394CMUGrabber::setShutter(unsigned short shutter)
{
  initCamera();

  _shutter = shutter;

  unsigned short min,max;
  C1394CameraControl *Control;

  Control = camera->GetCameraControl(FEATURE_SHUTTER);
  Control->Inquire();
  Control->GetRange(&min,&max);

  if (_shutter < min)
  {
    _shutter = min;
    std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be less than " << _shutter << std::endl;
  }
  else if (_shutter > max)
  {
    _shutter = max;
    std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be greater than " << _shutter << std::endl;
  }
  Control->SetAutoMode(false);
  if(Control->SetValue(_shutter) != CAM_SUCCESS)
  {
    std::cout << "vp1394CMUGrabber warning: Can't set exposure time register value of IEEE 1394 camera number " << index << std::endl;
  }
}
Beispiel #3
0
/*! 
   Disable auto gain and set the gain to the requested value. 

   \sa setAutoGain()
   */
void vp1394CMUGrabber::setGain(unsigned short gain)
{
  initCamera();
  _gain = gain;

  unsigned short min,max;
  C1394CameraControl *Control;

  Control = camera->GetCameraControl(FEATURE_GAIN);
  Control->Inquire();
  Control->GetRange(&min,&max);

  if (_gain < min)
  {
    _gain = min;
    std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be less than " << _gain << std::endl;
  } 
  else if (_gain > max)
  {
    _gain = max;
    std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be greater than " << _gain << std::endl;
  }
  
  Control->SetAutoMode(false);
  if(Control->SetValue(_gain) != CAM_SUCCESS)
  {
    std::cout << "vp1394CMUGrabber warning: Can't set gain register value of IEEE 1394 camera number " << index << std::endl;
  }
}
Beispiel #4
0
void CMUCamera::setWhitebalance(int u, int v, bool bIgnoreOldValue)
{
    if (bIgnoreOldValue || m_WhitebalanceU != u || m_WhitebalanceV != v) {
        m_WhitebalanceU = u;
        m_WhitebalanceV = v;
        CAMERA_FEATURE cmuFeature = getFeatureID(CAM_FEATURE_WHITE_BALANCE);
        if (m_pCamera->HasFeature(FEATURE_WHITE_BALANCE)) {
            bool bAuto = (u == -1);
            
            C1394CameraControl* pControl = m_pCamera->GetCameraControl(cmuFeature);
            int err1 = pControl->SetAutoMode(bAuto);
            int err2 = CAM_SUCCESS;
            if (!bAuto) {
                err2 = pControl->SetValue(u, v);
            }
            checkCMUWarning(err1 == CAM_SUCCESS && err2 == CAM_SUCCESS,
                    string("Error setting camera feature: ") + 
                    cameraFeatureToString(CAM_FEATURE_WHITE_BALANCE));
        } else {
            AVG_TRACE(Logger::WARNING, string("Camera does not support feature: ") + 
                    cameraFeatureToString(CAM_FEATURE_WHITE_BALANCE));
        }
    }
}
Beispiel #5
0
bool Sync1394Camera::InitCamera(int cameraID, SyncCamParams m_config, float x_offset, float y_offset, float yaw_offset, float fudge) 
{
	C1394Camera* camptr;
	
	isRunning = false;
	Sync1394Camera::config = m_config;	
	int effWidth = config.partialWidth;
	int effHeight = config.partialHeight;
	
	camptr = &camera;

	if (config.isColor) 
		size = effWidth * effHeight * 3;
	else	
		size = effWidth * effHeight;
	if (config.BitDepth16) size *= 2;

	buf = new unsigned char[size];

	if(camptr->RefreshCameraList() == 0 ) 
	{ 
		printf("RefreshCameraList failed.\n");
		return false; 
	} 
	if (cameraID == 0)
	{
		start_tick = clock();
	}
	//artagLoc->initARtagPose(640, 480, 200.0, x_offset, y_offset, yaw_offset, fudge);
	artagLoc->initARtagPose(640, 480, 180.0, x_offset, y_offset, yaw_offset, fudge);
	//artagLoc->initARtagPose(640, 480, 160.0, x_offset, y_offset, yaw_offset, fudge);
	if(camptr->SelectCamera(cameraID)!=CAM_SUCCESS)	
	{ 
		printf("Could not select camera\n" ); 
		return false; 
	}
	camId = cameraID;
	if(camptr->InitCamera(true)!=CAM_SUCCESS)	
	{	
		printf("Could not init camera\n" ); 
		return false; 
	}	
	if(camptr->SetVideoFormat(config.videoFormat)!=CAM_SUCCESS)								
	{ 
		printf("Could not SetVideoFormat on camera\n" ); 
	}
	if(camptr->SetVideoMode(config.videoMode)!=CAM_SUCCESS)										
	{ 
		printf("Could not SetVideoMode on camera\n"); 
	}
	if (config.usePartialScan == false)
	{
		if(camptr->SetVideoFrameRate(config.videoFrameRate)!=CAM_SUCCESS)														
		{ 
			printf("Could not set video frame rate!");	
			return false;
		} //30 fps
	}
	else if (config.usePartialScan)
	{
		unsigned short w, h; 
		C1394CameraControlSize* p_size_control = camptr->GetCameraControlSize();
		p_size_control->GetSizeLimits(&w, &h);
		if ((w>effWidth) || (h>effHeight))																			
		{ 
			printf("FATAL: Bad Partial Scan Size Specified! Specified w:%d h:%d, Max: w:%d h:%d",effWidth,effHeight,w,h);	
			return false;
		} 
		if (config.isColor)
		{
			if( p_size_control->SetColorCode(COLOR_CODE_YUV422) != CAM_SUCCESS ) 	
			{ 
				printf("SetColorCode failed.\n"); 
				return false; 
			} 
		}
		else
		{
			if( p_size_control->SetColorCode(config.BitDepth16?COLOR_CODE_Y16:COLOR_CODE_Y8) != CAM_SUCCESS ) 
			{ 
				printf("SetColorCode failed (BW).\n"); 
				return false; 
			} 
		}
		if( p_size_control->SetSize(effWidth,effHeight) != CAM_SUCCESS )	
		{ 
			printf("SetSize failed.\n"); 
			return false; 
		} 
		if( p_size_control->SetPos(config.partialLeft,config.partialTop) != CAM_SUCCESS )
		{ 
			printf("SetPos failed.\n"); 
			return false; 
		} 
		if (p_size_control->SetBytesPerPacket (config.bytesPerPacket) != CAM_SUCCESS)
		{ 
			printf("SetBytesPerPacket failed.\n"); 
			return false; 
		} 

		float interval=0.0; p_size_control->GetFrameInterval (&interval);
		if (((float)config.syncFPS) > (1.0f/interval))													
		{ 
			printf("WARNING: SyncFPS (%f) is greater than the actual camera FPS (%f)\n",(float)config.syncFPS,(1.0f/interval));
		}
		printf("Frame Interval is: %f",interval);
	}
	if (config.isSlave)	
	{ 
		printf("Using SLAVE configuration.\n");
	}

	if (!config.AutoGain)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_GAIN);
		if (ctrl->SetAutoMode(false) != CAM_SUCCESS)
		{	
			printf("Gain SetManualMode failed.\n");
		}
		ctrl->SetValue(GAINVAL);
		if (ctrl->StatusAutoMode() == true)
		{	
			printf("I HAVE AUTOGAIN ASSHOLE");
		}
		unsigned short gainval = 0;
		ctrl->GetValue(&gainval);
		if (DEBUG_SYNC1394) printf("gain: %d\n",gainval);
	}
	else
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_GAIN);
		ctrl->SetValue(GAINVAL);
		if (ctrl->SetAutoMode(true) != CAM_SUCCESS)
		{	
			printf("Gain SetAutoMode failed.\n");
		}
		if (ctrl->StatusAutoMode() == true)
		{	
			if (DEBUG_SYNC1394) printf("AutoGain successfully set!\n");
		}
	}
	
	minGain=0;
	maxGain=0;
	GetGainMinMax( camptr, &minGain, &maxGain);
	if (DEBUG_SYNC1394) printf("Min gain: %d, Max gain: %d\n",minGain,maxGain);
	
	if (!config.AutoShutter)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_SHUTTER);
		if (ctrl->SetAutoMode(false) != CAM_SUCCESS)
		{	
			printf("Shutter SetManualMode failed.\n");
		}
		ctrl->SetValue(SHUTTERVAL);
		/*if (ctrl->SetValue(530) != CAM_SUCCESS)
		{	
			printf("Shutter SetValue failed.\n");
		}*/
		if (ctrl->StatusAutoMode() == true)
		{	
			printf("I HAVE AUTOSHUTTER ASSHOLE");
		}
	}
	else
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_SHUTTER);
		ctrl->SetValue(SHUTTERVAL);
		if (ctrl->SetAutoMode(true) != CAM_SUCCESS)
		{	
			printf("Shutter SetAutoMode failed.\n");
		}
		if (ctrl->StatusAutoMode() == true)
		{	
			if (DEBUG_SYNC1394) printf("AutoShutter successfully set!\n");
		}
	}

	if (!config.AutoBrightness)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_BRIGHTNESS);
		if (ctrl->SetAutoMode(false) != CAM_SUCCESS)
		{	
			printf("Brightness SetManualMode failed.\n");
		}
		ctrl->SetValue(154);
		if (ctrl->StatusAutoMode() == true)
		{	
			printf("I HAVE AUTOBRIGHTNESS ASSHOLE");
		}
		unsigned short bval = 0;
		ctrl->GetValue(&bval);
		if (DEBUG_SYNC1394) printf("brightness: %d\n",bval);
	}
	else
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_BRIGHTNESS);
		ctrl->SetValue(154);
		if (ctrl->SetAutoMode(true) != CAM_SUCCESS)
		{	
			printf("Brightness SetAutoMode failed.\n");
		}
		if (ctrl->StatusAutoMode() == true)
		{	
			if (DEBUG_SYNC1394) printf("AutoBrightness successfully set!\n");
		}
	}
	
	if (config.gammaEnable)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_GAMMA);
		if (ctrl->SetOnOff(true) != CAM_SUCCESS)
		{	
			printf("Gamma SetOnOff failed.\n");
		}
		if (ctrl->SetValue(1) != CAM_SUCCESS)
		{
			printf("Gamma SetValue failed.\n");
		}
	}

	minShutter=0;
	maxShutter=0;
	GetShutterMinMax(camptr, &minShutter, &maxShutter);
	if (DEBUG_SYNC1394) printf("Min shutter: %d, Max shutter: %d\n",minShutter,maxShutter);

	if (config.adjWB)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_WHITE_BALANCE);
		if (ctrl->SetValue(WHITEBALANCE_VALUE1,WHITEBALANCE_VALUE2) != CAM_SUCCESS)
		{
			printf("WhiteBalance SetValue failed.\n");
		}
	}
	
	printf("Completed Init of Camera %d\n", camId);

	if (config.eTrigEnabled)
	{
		C1394CameraControlTrigger* trig = camptr->GetCameraControlTrigger();
		if (trig->SetTriggerSource (config.syncCamInput)!=CAM_SUCCESS)
			printf("Could Not Set Trigger Source!\n");
		else
		{
			if (trig->SetMode (0))
				printf("Could Not Set Trigger Mode!\n");
			else
			{
				if (trig->SetOnOff (true))
					printf("Could Not Set Trigger ON!\n");
				else
				{
					trig->Status();
					printf("External Trigger Initialized.\n");
				}
			}
		}
	}
	else
	{
		if (config.syncEnabled)
		{
			udp_params paramsRX  = udp_params(); 
			paramsRX.remote_ip = inet_addr(UDP_BROADCAST_IP);
			paramsRX.local_port = UDP_BROADCAST_PORT;
			paramsRX.reuse_addr = 1;
			try
			{		
				udpRX = new udp_connection(paramsRX);  
			}
			catch (exception)
			{
				printf("Couldn't init UDP RX on  %s:%d  \n",UDP_BROADCAST_IP,paramsRX.local_port);
				return false;
			}

			udpRX->set_callback(MakeDelegate(this,&Sync1394Camera::UDPCallback), udpRX);

			udp_params paramsTX  =  udp_params(); 

			try
			{		
				udpTX = new udp_connection(paramsTX);  
			}
			catch (exception)
			{
				printf("Couldn't init UDP TX on port %d\n",paramsTX.local_port);
				return false;
			}

			if (config.isSlave == false)
			{
				char regmsg[] = {CAMERA_MSG_REGISTER, config.syncID & 0xFF, 0x00, 0x00, 0x00, 0x00,(paramsRX.local_port>>8)&0xff, paramsRX.local_port&0xff}; //register message
				udpTX->send_message (regmsg,8,UDP_CONTROL_IP,UDP_CONTROL_PORT);
				Sleep(100);
				char fpsmsg[] = {CAMERA_MSG_SETFPS, config.syncID & 0xff, config.syncFPS &0xff};
				udpTX->send_message (fpsmsg,3,UDP_CONTROL_IP,UDP_CONTROL_PORT);
				Sleep(100);
				char initmsg[] = {CAMERA_START, config.syncID & 0xFF}; //start message
				udpTX->send_message (initmsg,2,UDP_CONTROL_IP,UDP_CONTROL_PORT);
				if (config.ghettoSync == false)
				{
					C1394CameraControlTrigger* trig = camptr->GetCameraControlTrigger ();

					unsigned short modein=0; unsigned short modeparam =0; unsigned short trigsrc=0;
					if (trig->SetTriggerSource (config.syncCamInput)!=CAM_SUCCESS)
						printf("Could Not Set Trigger Source!\n");
					if (trig->SetMode (0))
						printf("Could Not Set Trigger Mode!\n");
					if (trig->SetOnOff (true))
						printf("Could Not Set Trigger ON!\n");
				}
			}
			if (DEBUG_SYNC1394) printf("Timing Initialized.\n");	
		}
/*!
 Init the selected camera.
 */
void 
vp1394CMUGrabber::initCamera()
{
  int camerror;
  unsigned long width, height;


  if (camera->CheckLink() != CAM_SUCCESS)
  {
    vpERROR_TRACE("C1394Camera error: Found no cameras on the 1394 bus");
    throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"The is no detected camera") );
  }

  camerror = camera->InitCamera();
  if ( camerror != CAM_SUCCESS )
  {
    switch (camerror)
    {
      case CAM_ERROR_NOT_INITIALIZED:
        vpERROR_TRACE("vp1394CMUGrabber error: No camera selected",index);
        throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"The is no selected camera") );
        break;
      case CAM_ERROR_BUSY:
        vpERROR_TRACE("vp1394CMUGrabber error: The camera %i is busy",index);
        throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"The required camera is in use by other application") );
        break;
      case CAM_ERROR:
        vpERROR_TRACE("vp1394CMUGrabber error: General I/O error when selecting camera number %i",index);
        throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"Resolve camera can not be used") );
        break;
    }
    close();
  }

  if (camera->Has1394b())
    camera->Set1394b(TRUE);

  // Set format and mode
  if ((_format != -1) && (_mode != -1))
  {
    if (!camera->HasVideoMode(_format, _mode))
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: The image format is not supported by the IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Video mode not supported") );
    }

    if (camera->SetVideoFormat(_format) != CAM_SUCCESS)
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: Can't set video format of IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Can't set video format") );
    }

    if (camera->SetVideoMode(_mode) != CAM_SUCCESS)
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: Can't set video mode of IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Can't set video mode") );
    }
  }
  else {
    // Get the current format and mode
    _format = camera->GetVideoFormat();
    _mode = camera->GetVideoMode();
  }

  // Update the color coding
  _color = getVideoColorCoding();
  //std::cout << "color coding: " << _color << std::endl;

  // Set fps
  if (_fps!=-1)
  {
    if (!camera->HasVideoFrameRate(_format,_mode,_fps))
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: The frame rate is not supported by the IEEE 1394 camera number %i for the selected image format",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"The frame rate is not supported") );
    }

    if (camera->SetVideoFrameRate(_fps) != CAM_SUCCESS)
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: Can't set video frame rate of IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Can't set video frame rate") );
    }
  }

  // Set shutter and gain
  if ( _modeauto == false )
  {
    unsigned short min,max;
    C1394CameraControl *Control;

    Control = camera->GetCameraControl(FEATURE_GAIN);
    Control->Inquire();
    Control->GetRange(&min,&max);

    if (_gain<min)
    {
      _gain = min;
      std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be less than " << _gain << std::endl;
    } else
      if (_gain>max)
      {
        _gain = max;
        std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be greater than " << _gain << std::endl;
      }

    Control->SetAutoMode(false);
    if(Control->SetValue(_gain) != CAM_SUCCESS)
    {
      std::cout << "vp1394CMUGrabber warning: Can't set gain register value of IEEE 1394 camera number " << index << std::endl;
    }

    Control = camera->GetCameraControl(FEATURE_SHUTTER);
    Control->Inquire();
    Control->GetRange(&min,&max);

    if (_shutter<min)
    {
      _shutter = min;
      std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be less than " << _shutter << std::endl;
    }
    else if (_shutter>max)
    {
      _shutter = max;
      std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be greater than " << _shutter << std::endl;
    }
    Control->SetAutoMode(false);
    if(Control->SetValue(_shutter) != CAM_SUCCESS)
    {
      std::cout << "vp1394CMUGrabber warning: Can't set exposure time register value of IEEE 1394 camera number " << index << std::endl;
    }
  }
  else
  {
    camera->GetCameraControl(FEATURE_SHUTTER)->SetAutoMode(true);
    camera->GetCameraControl(FEATURE_GAIN)->SetAutoMode(true);
  }

  // Set trigger off
  camera->GetCameraControlTrigger()->SetOnOff(false);


  camera->GetVideoFrameDimensions(&width,&height);
  this->height = height;
  this->width = width;

  init = true;

} // end camera init