Exemple #1
0
//
// idlCaptureQueueFrame
//
// Place an image buffer onto the frame queue
//
// command line arguments
// argv[0]: IN/FLAG debug
// argv[1]: IN camera index
// argv[2]: IN image buffer
// argv[3]: IN buffersize
// argv[4]: IN flags buffer
int idlPvCaptureQueueFrame (int argc, char *argv[])
{
  unsigned long err;
  unsigned long n;
  char *buf;
  unsigned long buffersize;
  char *flags;

  debug = *(IDL_INT *) argv[0];
  n = *(unsigned long *) argv[1];
  buf = (char *) argv[2];
  buffersize = *(unsigned long *) argv[3];
  flags = (char *) argv[4];

  CHECKINDEX(n);

  memset((void *) &frame, 0, sizeof(tPvFrame));
  //frame.ImageBuffer = ImageBuffer; // using permanently allocated buffer
  //frame.ImageBufferSize = IMGBUFFERSIZE;
  frame.Context[0] = (void *) flags;
  frame.ImageBuffer = buf;
  frame.ImageBufferSize = buffersize;

  err = PvCaptureQueueFrame(camera[n], &frame, NULL);

  return err;
}
//--------------------------------------------------------------------
void ofxVideoGrabberPvAPI::queueFrame(){
    if( PvCaptureQueueFrame( cameraHandle, &cameraFrame, NULL) != ePvErrSuccess ){
        ofLog(OF_LOG_ERROR, "failed to queue frame buffer");
    } else {
        bWaitingForFrame = true;
    }  
}
Exemple #3
0
void Camera::start(FrameStartTriggerMode fmode, AcquisitionMode amode)
{
  //assert( FSTmode_ == None && fmode != None );
  ///@todo verify this assert again
  //assert( fmode == SyncIn1 || fmode == SyncIn2 || fmode == Software || !userCallback_.empty() );
  
  // set camera in acquisition mode
  CHECK_ERR( PvCaptureStart(handle_), "Could not start capture");

  if (fmode == Freerun || fmode == SyncIn1 || fmode == SyncIn2 ||  fmode == FixedRate)
    for (unsigned int i = 0; i < bufferSize_; ++i)
      PvCaptureQueueFrame(handle_, frames_ + i, Camera::frameDone);

  // start capture after setting acquisition and trigger modes
  try {
    ///@todo take this one also as an argument
    CHECK_ERR( PvAttrEnumSet(handle_, "AcquisitionMode", acquisitionModes[amode]),
               "Could not set acquisition mode" );
    CHECK_ERR( PvAttrEnumSet(handle_, "FrameStartTriggerMode", triggerModes[fmode]),
               "Could not set trigger mode" );
    CHECK_ERR( PvCommandRun(handle_, "AcquisitionStart"),
               "Could not start acquisition" );
  } 
  catch (ProsilicaException& e) {
    PvCaptureEnd(handle_); // reset to non capture mode
    throw; // rethrow
  }
  FSTmode_ = fmode;
  Amode_ = amode;
}
Exemple #4
0
// snap and save a frame from the camera
void CameraSnap()
{
    if(!PvCaptureQueueFrame(GCamera.Handle,&(GCamera.Frame),NULL))
    {
        printf("waiting for a frame ...\n");

        while(PvCaptureWaitForFrameDone(GCamera.Handle,&(GCamera.Frame),1500) == ePvErrTimeout)
            printf("still waiting ...\n");

        if(GCamera.Frame.Status == ePvErrSuccess)
        {
            sprintf(GCamera.Filename,"./snap%04lu.tiff",++GCamera.Counter);

            if(!ImageWriteTiff(GCamera.Filename,&(GCamera.Frame)))
                printf("Failed to save the grabbed frame!");
            else
                printf("frame saved\n");
        }
        else
        if(GCamera.Frame.Status != ePvErrCancelled)
            printf("the frame failed to be captured ... %u\n",GCamera.Frame.Status);
    }
    else
        printf("failed to enqueue the frame\n");
}
Exemple #5
0
	void OmniCamera::grab(IplImage *img) {
		//Sleep(400);
		PvCaptureQueueFrame(_camera.handle,&(_camera.frame),0);
		//printf("waiting for the frame ...\n");
        PvCaptureWaitForFrameDone(_camera.handle,&(_camera.frame),PVINFINITE);
		//printf("frame's done ...\n, width %d height %d depth %d size %d\n",_camera.frame.Width,_camera.frame.Height,_camera.frame.BitDepth, _camera.frame.ImageBufferSize);
		
		PvUtilityColorInterpolate(&_camera.frame,&img->imageData[2],&img->imageData[1],&img->imageData[0],2,0);
		
	}
Exemple #6
0
tPvFrame* Camera::grab(unsigned long timeout_ms)
{
  assert( FSTmode_ == Software );
  
  unsigned long time_so_far = 0;
  while (time_so_far < timeout_ms)
  {
    /// @todo This is a hack, it seems that re-commanding the software trigger
    /// too quickly may cause the Prosilica driver to complain that the sequence
    /// of API calls is incorrect.
    boost::this_thread::sleep(boost::posix_time::millisec(400));

    // Queue up a single frame
    tPvFrame* frame = &frames_[0];
    CHECK_ERR( PvCaptureQueueFrame(handle_, frame, NULL), "Couldn't queue frame" );
    
    // Trigger the camera
    CHECK_ERR( PvCommandRun(handle_, "FrameStartTriggerSoftware"),
               "Couldn't trigger capture" );

    // Wait for frame capture to finish. The wait call may timeout in less
    // than the allotted time, so we keep trying until we exceed it.
    tPvErr e = ePvErrSuccess;
    do
    {
      try
      {
        if (e != ePvErrSuccess)
          ROS_DEBUG("Retrying CaptureWait due to error: %s", errorStrings[e]);
        clock_t start_time = clock();
        e = PvCaptureWaitForFrameDone(handle_, frame, timeout_ms - time_so_far);
        if (timeout_ms != PVINFINITE)
          time_so_far += ((clock() - start_time) * 1000) / CLOCKS_PER_SEC;
      } 
      catch (prosilica::ProsilicaException &e) {
        ROS_ERROR("Prosilica exception during grab, will retry: %s\n", e.what());
      }
    } while (e == ePvErrTimeout && time_so_far < timeout_ms);

    if (e != ePvErrSuccess)
      return NULL; // Something bad happened (camera unplugged?)
    
    if (frame->Status == ePvErrSuccess)
      return frame; // Yay!

    ROS_DEBUG("Error in frame: %s", errorStrings[frame->Status]);

    // Retry if data was lost in transmission. Probably no hope on other errors.
    if (frame->Status != ePvErrDataMissing && frame->Status != ePvErrDataLost)
      return NULL;
  }
  
  return NULL;
}
Exemple #7
0
// snap and save a frame from the camera
void cameraSnap(tCamera* camera) {

  if (!PvCaptureQueueFrame(camera->Handle, &(camera->Frame), NULL)) {
    int index = 0;
    while ((PvCaptureWaitForFrameDone(camera->Handle, &(camera->Frame), 100) == ePvErrTimeout)
	   && (index < 10)){
      index++;
    }
    if (camera->Frame.Status != ePvErrSuccess)
      cout << "the frame failed to be captured : "<< cameraGetError(camera->Frame.Status) << endl;
  } else
    cout << "failed to enqueue the frame" << endl;
}
// setup and start streaming
// return value: true == success, false == fail
bool CameraStart()
{
    tPvErr errCode;
	bool failed = false;

    // NOTE: This call sets camera PacketSize to largest sized test packet, up to 8228, that doesn't fail
	// on network card. Some MS VISTA network card drivers become unresponsive if test packet fails. 
	// Use PvUint32Set(handle, "PacketSize", MaxAllowablePacketSize) instead. See network card properties
	// for max allowable PacketSize/MTU/JumboFrameSize. 
	if((errCode = PvCaptureAdjustPacketSize(GCamera.Handle,8228)) != ePvErrSuccess)
	{
		printf("CameraStart: PvCaptureAdjustPacketSize err: %u\n", errCode);
		return false;
	}

    // start driver capture stream 
	if((errCode = PvCaptureStart(GCamera.Handle)) != ePvErrSuccess)
	{
		printf("CameraStart: PvCaptureStart err: %u\n", errCode);
		return false;
	}

    // queue frames with FrameDoneCB callback function. Each frame can use a unique callback function
	// or, as in this case, the same callback function.
	for(int i=0;i<FRAMESCOUNT && !failed;i++)
	{           
		if((errCode = PvCaptureQueueFrame(GCamera.Handle,&(GCamera.Frames[i]),FrameDoneCB)) != ePvErrSuccess)
		{
			printf("CameraStart: PvCaptureQueueFrame err: %u\n", errCode);
			failed = true;
		}
	}

	if (failed)
		return false;
		
	// set the camera to 5 FPS, continuous mode, and start camera receiving triggers					
	if((PvAttrFloat32Set(GCamera.Handle,"FrameRate",5) != ePvErrSuccess) ||
		(PvAttrEnumSet(GCamera.Handle,"FrameStartTriggerMode","FixedRate") != ePvErrSuccess) ||
		(PvAttrEnumSet(GCamera.Handle,"AcquisitionMode","Continuous") != ePvErrSuccess) ||
		(PvCommandRun(GCamera.Handle,"AcquisitionStart") != ePvErrSuccess))
	{		
		printf("CameraStart: failed to set camera attributes\n");
		return false;
	}	

	return true;
}
// trigger and save a frame from the camera
// return value: true == success, false == fail
bool CameraSnap()
{
    tPvErr errCode = ePvErrSuccess;

    //wait for frame to return from camera to host
    printf("Waiting for SyncIn1 trigger input");
	while(!GCamera.Abort && ((errCode = PvCaptureWaitForFrameDone(GCamera.Handle,&(GCamera.Frame),800)) == ePvErrTimeout))
        printf(".");
	printf("\n");

	if(errCode != ePvErrSuccess  || GCamera.Abort)
    { 
		//likely camera unplugged
		GCamera.Abort = true;
		return false;
	}
	
	//check returned Frame.Status
	if(GCamera.Frame.Status == ePvErrSuccess)
    {
		sprintf_s(GCamera.Filename,sizeof(GCamera.Filename),"./snap%04lu.tiff",++GCamera.Counter);
		//save image
		if(!ImageWriteTiff(GCamera.Filename,&(GCamera.Frame)))
		{
			printf("ImageWriteTiff fail.\n");
			GCamera.Abort = true;
			return false;
		}
		printf("snap%04lu.tiff saved.\n", GCamera.Counter);
	}
    else
	{
		if (GCamera.Frame.Status == ePvErrDataMissing)
			printf("Dropped packets. Possible improper network card settings:\nSee GigE Installation Guide.");
		else
			printf("Frame.Status error: %u\n",GCamera.Frame.Status);
	}

	//requeue frame	
	if((errCode = PvCaptureQueueFrame(GCamera.Handle,&(GCamera.Frame),NULL)) != ePvErrSuccess)
	{
        printf("PvCaptureQueueFrame err: %u\n", errCode);
		GCamera.Abort = true;
		return false;
	}
	return true;
}
// setup and start streaming
// return value: true == success, false == fail
bool CameraStart()
{
    tPvErr errCode;

    // NOTE: This call sets camera PacketSize to largest sized test packet, up to 8228, that doesn't fail
	// on network card. Some MS VISTA network card drivers become unresponsive if test packet fails. 
	// Use PvUint32Set(handle, "PacketSize", MaxAllowablePacketSize) instead. See network card properties
	// for max allowable PacketSize/MTU/JumboFrameSize. 
	if((errCode = PvCaptureAdjustPacketSize(GCamera.Handle,8228)) != ePvErrSuccess)
	{
		printf("CameraStart: PvCaptureAdjustPacketSize err: %u\n", errCode);
		return false;
	}

    // start driver capture stream 
	if((errCode = PvCaptureStart(GCamera.Handle)) != ePvErrSuccess)
	{
		printf("CameraStart: PvCaptureStart err: %u\n", errCode);
		return false;
	}
	
    // queue frame
	if((errCode = PvCaptureQueueFrame(GCamera.Handle,&(GCamera.Frame),NULL)) != ePvErrSuccess)
	{
		printf("CameraStart: PvCaptureQueueFrame err: %u\n", errCode);
		// stop driver capture stream
		PvCaptureEnd(GCamera.Handle);
		return false;
	}
		
	// set the camera in hardware trigger, continuous mode, and start camera receiving triggers
	if((PvAttrEnumSet(GCamera.Handle,"FrameStartTriggerMode","SyncIn1") != ePvErrSuccess) ||
		(PvAttrEnumSet(GCamera.Handle,"AcquisitionMode","Continuous") != ePvErrSuccess) ||
		(PvCommandRun(GCamera.Handle,"AcquisitionStart") != ePvErrSuccess))
	{		
		printf("CameraStart: failed to set camera attributes\n");
		// clear queued frame
		PvCaptureQueueClear(GCamera.Handle);
		// stop driver capture stream
		PvCaptureEnd(GCamera.Handle);
		return false;
	}	

	return true;
}
bool CameraGigE::onStep() {
	LOG(LTRACE) << "CameraGigE::onStep";

	tPvErr Err = PvCaptureQueueFrame(cHandle, &frame, NULL);
	if (!Err) {
		Err = PvCaptureWaitForFrameDone(cHandle, &frame, PVINFINITE);
		if (!Err) {
			if (frame.Status == ePvErrSuccess) {
				img = cv::Mat(frame.Height, frame.Width, (frame.Format
						== ePvFmtMono8) ? CV_8UC1 : CV_8UC3, frame.ImageBuffer);

				out_img.write(img);
				newImage->raise();
			}
		}
	}

	return true;
}
Exemple #12
0
// snap and save a frame from the camera
tPvFrame *cameraSnap(tCamera* camera, int nbSnap) {
  unsigned long FrameSize = 0;
  PvAttrUint32Get(camera->Handle, "TotalBytesPerFrame", &FrameSize);

  tPvFrame *frames = new tPvFrame[nbSnap];
  for(int i=0; i<nbSnap; i++) {
    // allocate the buffer for the single frame we need
    frames[i].Context[0] = camera;
    frames[i].ImageBuffer = new char[FrameSize];
    if (frames[i].ImageBuffer)
      frames[i].ImageBufferSize = FrameSize;
    else
      throw "failed allocate Frame.ImageBuffer";
    
  }
  /*
  cerr<<"Warming up !\n";
  PvCaptureQueueFrame(camera->Handle, &(camera->Frame), NULL);
  while(camera->Frame.Status != ePvErrSuccess)
    PvCaptureQueueFrame(camera->Handle, &(camera->Frame), NULL);
  */

  struct timeval myTVstart, myTVend;
  gettimeofday (&myTVstart, NULL);
  for(int i=0; i<nbSnap; i++) {
    if (!PvCaptureQueueFrame(camera->Handle, &(frames[i]), NULL)) {
      int index = 0;
      while ((PvCaptureWaitForFrameDone(camera->Handle, &(frames[i]), 10) == ePvErrTimeout)
	     && (index < 100)){
	index++;
      }
      if (frames[i].Status != ePvErrSuccess)
	cout << "the frame failed to be captured : "<< cameraGetError(frames[i].Status) << endl;
    } else
      cout << "failed to enqueue the frame" << endl;
  }
  gettimeofday (&myTVend, NULL);
  double duration = my_difftime (&myTVstart, &myTVend)/1000000.;

  cout << "Acuisition tooks " << duration*1000 << " mseconds, (" << (double)nbSnap/duration << " Hz)" << endl;
  return frames;
}
Exemple #13
0
// snap and save a frame from the camera
void CameraSnap(tCamera* Camera)
{
    if(!PvCaptureQueueFrame(Camera->Handle,&(Camera->Frame),NULL))
    {
        printf("waiting for the frame to be done ...\n");
        while(PvCaptureWaitForFrameDone(Camera->Handle,&(Camera->Frame),100) == ePvErrTimeout)
            printf("still waiting ...\n");
        if(Camera->Frame.Status == ePvErrSuccess)
        {
            if(!ImageWriteTiff("./snap.tiff",&(Camera->Frame)))
                printf("Failed to save the grabbed frame!");
            else
                printf("frame saved\n");
        }
        else
            printf("the frame failed to be captured ...\n");
    }
    else
        printf("failed to enqueue the frame\n");
}
Exemple #14
0
void Camera::frameDone(tPvFrame* frame)
{
  // don't requeue if capture has stopped
  if (frame->Status == ePvErrUnplugged || frame->Status == ePvErrCancelled)
    return;

  Camera* camPtr = (Camera*) frame->Context[0];
  if (frame->Status == ePvErrSuccess && camPtr && !camPtr->userCallback_.empty()) {
    // TODO: thread safety OK here?
    boost::lock_guard<boost::mutex> guard(camPtr->frameMutex_);
    camPtr->userCallback_(frame);
  }
  else if (frame->Status == ePvErrDataMissing) {
    // Avoid warning spew; lots of dropped packets will show up in the diagnostics.
    ROS_DEBUG("Error in frame: %s\n", errorStrings[frame->Status]);
  }
  else {
    ROS_WARN("Error in frame: %s\n", errorStrings[frame->Status]);
  }
  
  PvCaptureQueueFrame(camPtr->handle_, frame, Camera::frameDone);
}
bool CvCaptureCAM_PvAPI::grabFrame()
{
	//if(Camera.Frame.Status != ePvErrUnplugged && Camera.Frame.Status != ePvErrCancelled)
	return PvCaptureQueueFrame(Camera.Handle, &(Camera.Frame), NULL) == ePvErrSuccess;
}
bool CvCaptureCAM_PvAPI::grabFrame()
{
    return PvCaptureQueueFrame(Camera.Handle, &(Camera.Frame), NULL) == ePvErrSuccess;
}
// Frame completed callback executes on seperate driver thread.
// One callback thread per camera. If a frame callback function has not 
// completed, and the next frame returns, the next frame's callback function is queued. 
// This situation is best avoided (camera running faster than host can process frames). 
// Spend as little time in this thread as possible and offload processing
// to other threads or save processing until later.
//
// Note: If a camera is unplugged, this callback will not get called until PvCaptureQueueClear.
// i.e. callback with pFrame->Status = ePvErrUnplugged doesn't happen -- so don't rely
// on this as a test for a missing camera. 
void _STDCALL FrameDoneCB(tPvFrame* pFrame)
{ 
	// if frame hasn't been cancelled, requeue frame
    if(pFrame->Status != ePvErrCancelled)
		PvCaptureQueueFrame(GCamera.Handle,pFrame,FrameDoneCB); 
}