Esempio n. 1
0
// wait for a camera to be plugged
void WaitForCamera()
{
    printf("waiting for a camera");
    while(!PvCameraCount())
    {
        printf(".");fflush(stdout);
        Sleep(250);
    }
    printf("\n");
}
Esempio n. 2
0
// wait for camera to be plugged in
void WaitForCamera()
{
    printf("Waiting for a camera ");
    while((PvCameraCount() == 0) && !GCamera.Abort)
    {
        printf(".");
        Sleep(250);
    }
    printf("\n");
}
Esempio n. 3
0
//
// idlPvCameraCount
//
// Return the number of cameras attached to the PvAPI system.
//
// command line arguments
// argv[0]: IN/FLAG debug
int idlPvCameraCount (int argc, char *argv[])
{
  unsigned long count;

  debug = *(IDL_INT *) argv[0];

  count = PvCameraCount();

  return (int) count;
}
Esempio n. 4
0
// wait for a camera to be plugged
void waitForCamera() {
  cout << "waiting for a camera (10s)";
  int index = 0;
  while (!PvCameraCount() && index < 40) {
    cout << "." << flush;
    msleep(250);
    index++;
  }
  cout << endl;
  if (index == 40)
    throw "failed to find a camera\n";
}
Esempio n. 5
0
	bool OmniCamera::connect(void) {
		if(isConnected())
			return true;

		tPvCameraInfoEx info[1];
		 unsigned long frameSize = 0;

		//PvLinkCallbackRegister(CameraEventCB,ePvLinkAdd,NULL);
        //PvLinkCallbackRegister(CameraEventCB,ePvLinkRemove,NULL);        

		if(!PvInitialize()) {

			while(!PvCameraCount()) 
				Sleep(250);


			unsigned long numCameras = PvCameraListEx(info, 1, NULL, sizeof(tPvCameraInfoEx));;
								
			if ((numCameras == 1) && (info[0].PermittedAccess & ePvAccessMaster)) {
				
				_camera.UID = info[0].UniqueId;

				if(!PvCameraOpen(_camera.UID, ePvAccessMaster, &(_camera.handle))) {

					if(!PvAttrUint32Get(_camera.handle,"TotalBytesPerFrame",&frameSize)) {

						_camera.frame.ImageBuffer = new char[frameSize];
						
						unsigned long format=0;
						PvAttrEnumSet(_camera.handle,"PixelFormat","Bayer8");
						char text[100];
						PvAttrEnumGet(_camera.handle,"PixelFormat",text,sizeof(text),&format);
						printf("format %d %s\n",format,text);
						if(_camera.frame.ImageBuffer) {
							_camera.frame.ImageBufferSize = frameSize;
									
							PvAttrUint32Get(_camera.handle,"Width",&_width);
							PvAttrUint32Get(_camera.handle,"Height",&_height);
							PvCaptureStart(_camera.handle);
							PvAttrEnumSet(_camera.handle, "AcquisitionMode", "Continuous");
							PvCommandRun(_camera.handle, "AcquisitionStart");

							_connected = true;
							return true;
						}
					}
				}
			}				
		}
		_connected = false;
		return false;
	}
//--------------------------------------------------------------------
bool ofxVideoGrabberPvAPI::initGrabber(int w, int h, bool setUseTexture){

    width = w;
    height = h;
    tPvErr ret;   //PvAPI return codes
	bUseTexture = setUseTexture;
    memset( &cameraUID, 0, sizeof(cameraUID) );
    memset( &cameraHandle, 0, sizeof(cameraHandle) );
    memset( &cameraFrame, 0, sizeof(cameraFrame) );
    
    
    //---------------------------------- 1 - open the sequence grabber
    // lazy initialization of the Prosilica API
    if( !bPvApiInitiated ){
        ret = PvInitialize();
        if( ret == ePvErrSuccess ) {
            ofLog(OF_LOG_VERBOSE, "PvAPI initialized");
        } else {
            ofLog(OF_LOG_ERROR, "unable to initialize PvAPI");
            return false;
        }
        
        bPvApiInitiated = true;
    }
            
    //---------------------------------- 3 - buffer allocation
    // Create a buffer big enough to hold the video data,
    // make sure the pointer is 32-byte aligned.
    // also the rgb image that people will grab
    
    pixels = new unsigned char[width*height];
    
    // check for any cameras plugged in
    int waitIterations = 0;
    while( PvCameraCount() < 1 ) {
        ofSleepMillis(250);
        waitIterations++;
        
        if( waitIterations > 8 ) {
            ofLog(OF_LOG_ERROR, "error: no camera found");
            return false;        
        }
    }


    //---------------------------------- 4 - device selection
    
    tPvUint32 count, connected;
    tPvCameraInfo list[maxConcurrentCams];

    count = PvCameraList( list, maxConcurrentCams, &connected );
    if(count >= 1) {
        bool bSelectedDevicePresent = false;
        if(bChooseDevice) {
            //check if selected device is available
            for( int i=0; i<count; ++i) {
                if( deviceID == list[i].UniqueId ) {
                    bSelectedDevicePresent = true;
                    cameraUID = list[i].UniqueId;
                }
            }
        }
        
        if( !bSelectedDevicePresent ){
            cameraUID = list[0].UniqueId;
            ofLog(OF_LOG_NOTICE, "cannot find selected camera -> defaulting to first available");
            ofLog(OF_LOG_VERBOSE, "there is currently an arbitrary hard limit of %i concurrent cams", maxConcurrentCams);
        }        
    } else {
        ofLog(OF_LOG_ERROR, "no cameras available");
        return false;     
    }
        
    
    //---------------------------------- 5 - final initialization steps
    
    ret = PvCameraOpen( cameraUID, ePvAccessMaster, &cameraHandle );
    if( ret == ePvErrSuccess ){
        ofLog(OF_LOG_VERBOSE, "camera opened");
    } else {
        if( ret == ePvErrAccessDenied ) {
            ofLog(OF_LOG_ERROR, "camera access denied, probably already in use");
        }
        ofLog(OF_LOG_ERROR, "failed to open camera");
        return false;     
    }


    unsigned long FrameSize = 0;
    ret = PvAttrUint32Get( cameraHandle, "TotalBytesPerFrame", &FrameSize );
    if( ret == ePvErrSuccess ){
        // allocate the buffer for the single frame we need
        cameraFrame.ImageBuffer = new char[FrameSize];
        cameraFrame.ImageBufferSize = FrameSize;    
        ofLog(OF_LOG_VERBOSE, "camera asked for TotalBytesPerFrame");
    } else { 
        ofLog(OF_LOG_ERROR, "failed to allocate capture buffer");
        return false;    
    }    
    
    
    ret = PvCaptureStart(cameraHandle);
    if( ret == ePvErrSuccess ){
        ofLog(OF_LOG_VERBOSE, "camera set to capture mode");
    } else { 
        if( ret == ePvErrUnplugged ){
            ofLog(OF_LOG_ERROR, "cannot start capture, camera was unplugged");
        }
        ofLog(OF_LOG_ERROR, "cannot set to capture mode");
        return false;    
    }
    
    
    ret = PvAttrEnumSet(cameraHandle,"FrameStartTriggerMode","Freerun");
    if( ret == ePvErrSuccess ){
        ofLog(OF_LOG_VERBOSE, "camera set to continuous mode");
    } else {
        ofLog(OF_LOG_ERROR, "cannot set to continous mode");
        return false;    
    }    
    
    
    ret = PvCommandRun(cameraHandle,"AcquisitionStart");
    if( ret == ePvErrSuccess ){
        ofLog(OF_LOG_VERBOSE, "camera continuous acquisition started");
    } else {
        // if that fail, we reset the camera to non capture mode
        PvCaptureEnd(cameraHandle) ;
        ofLog(OF_LOG_ERROR, "cannot start continuous acquisition");
        return false;    
    }
    
    bGrabberInited = true;
    //loadSettings();    
    ofLog(OF_LOG_NOTICE,"camera is ready now");  
                
                
    //---------------------------------- 6 - setup texture if needed

    if (bUseTexture){
        // create the texture, set the pixels to black and
        // upload them to the texture (so at least we see nothing black the callback)
        tex.allocate(width,height,GL_LUMINANCE);
        memset(pixels, 0, width*height);
        tex.loadData(pixels, width, height, GL_LUMINANCE);
    }

    // we are done
    return true;
}