void ImperxStream::Stream(unsigned char *frame, Semaphore &frame_semaphore, Flag &stream_flag) { // The pipeline is already "armed", we just have to tell the device // to start sending us images printf( "Sending StartAcquisition command to device\n" ); lDeviceParams->ExecuteCommand( "AcquisitionStart" ); char lDoodle[] = "|\\-|-/"; int lDoodleIndex = 0; PvInt64 lImageCountVal = 0; double lFrameRateVal = 0.0; double lBandwidthVal = 0.0; // Acquire images until the user instructs us to stop printf( "\n<press a key to stop streaming>\n" ); while ( stream_flag.check() ) { std::cout << "here\n"; // Retrieve next buffer PvBuffer *lBuffer = NULL; PvResult lOperationResult; PvResult lResult = lPipeline.RetrieveNextBuffer( &lBuffer, 1000, &lOperationResult ); if ( lResult.IsOK() ) { if ( lOperationResult.IsOK() ) { // Process Buffer lStreamParams->GetIntegerValue( "ImagesCount", lImageCountVal ); lStreamParams->GetFloatValue( "AcquisitionRateAverage", lFrameRateVal ); lStreamParams->GetFloatValue( "BandwidthAverage", lBandwidthVal ); // If the buffer contains an image, display width and height PvUInt32 lWidth = 0, lHeight = 0; if ( lBuffer->GetPayloadType() == PvPayloadTypeImage ) { // Get image specific buffer interface PvImage *lImage = lBuffer->GetImage(); // Read width, height lWidth = lBuffer->GetImage()->GetWidth(); lHeight = lBuffer->GetImage()->GetHeight(); stream_flag.raise(); } std::cout << lWidth << " " << lHeight << "\n"; } // We have an image - do some processing (...) and VERY IMPORTANT, // release the buffer back to the pipeline //semaphore thing //get all in there. //a semaphore thing lPipeline.ReleaseBuffer( lBuffer ); } else { // Timeout printf( "%c Timeout\r", lDoodle[ lDoodleIndex ] ); } ++lDoodleIndex %= 6; } }
void *ImageProcessThread(void *threadargs) { long tid = (long)((struct Thread_data *)threadargs)->thread_id; printf("ImageProcess thread #%ld!\n", tid); CoordList localLimbs, localPixelFiducials, localScreenFiducials; IndexList localIds; uint8_t localMin, localMax; std::vector<float> localMapping; cv::Point2f localPixelCenter, localScreenCenter, localError; timespec waittime; waittime.tv_sec = frameRate.tv_sec/10; waittime.tv_nsec = frameRate.tv_nsec/10; while(1) { if (stop_message[tid] == 1) { printf("ImageProcess thread #%ld exiting\n", tid); started[tid] = false; pthread_exit( NULL ); } if (cameraReady) { while(1) { if(procReady.check()) { procReady.lower(); break; } else { nanosleep(&waittime, NULL); } } //printf("ImageProcessThread: trying to lock\n"); if (pthread_mutex_trylock(&mutexImage) == 0) { //printf("ImageProcessThread: got lock\n"); if(!frame.empty()) { aspect.LoadFrame(frame); pthread_mutex_unlock(&mutexImage); runResult = aspect.Run(); switch(GeneralizeError(runResult)) { case NO_ERROR: aspect.GetScreenFiducials(localScreenFiducials); aspect.GetScreenCenter(localScreenCenter); aspect.GetMapping(localMapping); case MAPPING_ERROR: aspect.GetFiducialIDs(localIds); case ID_ERROR: aspect.GetPixelFiducials(localPixelFiducials); case FIDUCIAL_ERROR: aspect.GetPixelCenter(localPixelCenter); aspect.GetPixelError(localError); case CENTER_ERROR: aspect.GetPixelCrossings(localLimbs); if (REPORT_FOCUS) aspect.ReportFocus(); case LIMB_ERROR: case RANGE_ERROR: aspect.GetPixelMinMax(localMin, localMax); break; default: std::cout << "Nothing worked\n"; } pthread_mutex_lock(&mutexProcess); switch(GeneralizeError(runResult)) { case NO_ERROR: screenFiducials = localScreenFiducials; screenCenter = localScreenCenter; mapping = localMapping; case MAPPING_ERROR: ids = localIds; case ID_ERROR: pixelFiducials = localPixelFiducials; case FIDUCIAL_ERROR: pixelCenter = localPixelCenter; error = localError; case CENTER_ERROR: limbs = localLimbs; case LIMB_ERROR: case RANGE_ERROR: frameMin = localMin; frameMax = localMax; break; default: break; } pthread_mutex_unlock(&mutexProcess); } else { //std::cout << "Frame empty!" << std::endl; } /* std::cout << ids.size() << " fiducials found:"; for(uint8_t i = 0; i < ids.size() && i < 20; i++) std::cout << pixelFiducials[i]; std::cout << std::endl; for(uint8_t i = 0; i < ids.size() && i < 20; i++) std::cout << ids[i]; std::cout << std::endl; for(uint8_t i = 0; i < ids.size() && i < 20; i++) std::cout << screenFiducials[i]; std::cout << std::endl; std::cout << "Sun center (pixels): " << pixelCenter << ", Sun center (screen): " << screenCenter << std::endl; */ } } } }