// 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"); }
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); }
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; }
IplImage* CvCaptureCAM_PvAPI::retrieveFrame(int) { if (PvCaptureWaitForFrameDone(Camera.Handle, &(Camera.Frame), 1000) == ePvErrSuccess) { if (!monocrome) { cvMerge(grayframe,grayframe,grayframe,NULL,frame); return frame; } return grayframe; } else return NULL; }
// 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; }
// // idlPvCaptureWaitForFrameDone // // Block the calling thread until a frame is complete // // command line arguments // argv[0]: IN/FLAG debug // argv[1]: IN camera index // argv[2]: IN timeout in milliseconds int idlPvCaptureWaitForFrameDone (int argc, char *argv[]) { unsigned long err; unsigned long n; unsigned long timeout; debug = *(IDL_INT *) argv[0]; n = *(unsigned long *) argv[1]; timeout = *(unsigned long *) argv[2]; CHECKINDEX(n); err = PvCaptureWaitForFrameDone(camera[n], &frame, timeout); return err; }
// 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; }
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; }
// 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; }
// 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"); }
//-------------------------------------------------------------------- void ofxVideoGrabberPvAPI::grabFrame(){ int ret; if( bGrabberInited ){ if( !bWaitingForFrame ) { bIsFrameNew = false; queueFrame(); } else { // check if queued capture frame is ready ret = PvCaptureWaitForFrameDone(cameraHandle, &cameraFrame, 5); if( ret == ePvErrTimeout ) { bIsFrameNew = false; } else if( ret == ePvErrSuccess ){ bIsFrameNew = true; if (bUseTexture){ tex.loadData((unsigned char*)cameraFrame.ImageBuffer, width, height, GL_LUMINANCE ); //GL_LUMINANCE8 } memcpy(pixels, cameraFrame.ImageBuffer, width*height); queueFrame(); } } } }
IplImage* CvCaptureCAM_PvAPI::retrieveFrame(int) { return (PvCaptureWaitForFrameDone(Camera.Handle, &(Camera.Frame), 1000) == ePvErrSuccess) ? frame : NULL; }