bool PleoraVideo::GrabNewest( unsigned char* image, bool wait ) { PvBuffer *lBuffer0 = NULL; PvBuffer *lBuffer = NULL; PvResult lOperationResult; const uint32_t timeout = wait ? 0xFFFFFFFF : 0; PvResult lResult = lStream->RetrieveBuffer( &lBuffer, &lOperationResult, timeout ); if ( !lResult.IsOK() ) { pango_print_warn("Pleora error: %s\n", lResult.GetCodeString().GetAscii() ); return false; }else if( !lOperationResult.IsOK() ) { pango_print_warn("Pleora error: %s\n", lOperationResult.GetCodeString().GetAscii() ); lStream->QueueBuffer( lBuffer ); return false; } // We have at least one frame. Capture more until we fail, 0 timeout while(true) { PvResult lResult = lStream->RetrieveBuffer( &lBuffer0, &lOperationResult, 0 ); if ( !lResult.IsOK() ) { break; }else if( !lOperationResult.IsOK() ) { lStream->QueueBuffer( lBuffer0 ); break; }else{ lStream->QueueBuffer( lBuffer ); lBuffer = lBuffer0; } } bool good = false; PvPayloadType lType = lBuffer->GetPayloadType(); if ( lType == PvPayloadTypeImage ) { PvImage *lImage = lBuffer->GetImage(); std::memcpy(image, lImage->GetDataPointer(), size_bytes); good = true; } lStream->QueueBuffer( lBuffer ); return good; }
bool PleoraVideo::GrabNext( unsigned char* image, bool /*wait*/ ) { PvBuffer *lBuffer = NULL; PvResult lOperationResult; // Retrieve next buffer PvResult lResult = lStream->RetrieveBuffer( &lBuffer, &lOperationResult, 1000 ); if ( !lResult.IsOK() ) { pango_print_warn("Pleora error: %s\n", lResult.GetCodeString().GetAscii() ); return false; } bool good = false; if ( lOperationResult.IsOK() ) { PvPayloadType lType = lBuffer->GetPayloadType(); if ( lType == PvPayloadTypeImage ) { PvImage *lImage = lBuffer->GetImage(); std::memcpy(image, lImage->GetDataPointer(), size_bytes); good = true; } } else { pango_print_warn("Pleora error: %s\n", lOperationResult.GetCodeString().GetAscii() ); } lStream->QueueBuffer( lBuffer ); return good; }
int ImperxStream::Snap(cv::Mat &frame, int timeout) { // std::cout << "ImperxStream::Snap starting" << std::endl; // The pipeline is already "armed", we just have to tell the device // to start sending us images lDeviceParams->ExecuteCommand( "AcquisitionStart" ); int lWidth, lHeight, result = 0; // Retrieve next buffer PvBuffer *lBuffer = NULL; PvResult lOperationResult; PvResult lResult = lPipeline.RetrieveNextBuffer( &lBuffer, timeout, &lOperationResult ); if ( lResult.IsOK() ) { if ( lOperationResult.IsOK() ) { // Process Buffer if ( lBuffer->GetPayloadType() == PvPayloadTypeImage ) { // std::cout << "ImperxStream::Snap Copying frame" << std::endl; // Get image specific buffer interface PvImage *lImage = lBuffer->GetImage(); // Read width, height lWidth = (int) lImage->GetWidth(); lHeight = (int) lImage->GetHeight(); unsigned char *img = lImage->GetDataPointer(); cv::Mat lframe(lHeight,lWidth,CV_8UC1,img, cv::Mat::AUTO_STEP); lframe.copyTo(frame); result = 0; } else { std::cout << "ImperxStream::Snap No image in buffer" << std::endl; result = 1; } } else { std::cout << "ImperxStream::Snap Operation result: " << lOperationResult << std::endl; result = 1;; } // We have an image - do some processing (...) and VERY IMPORTANT, // release the buffer back to the pipeline } else { std::cout << "ImperxStream::Snap Timeout: " << lResult << std::endl; result = 1; } lPipeline.ReleaseBuffer( lBuffer ); // std::cout << "ImperxStream::Snap Exiting" << std::endl; return result; }
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 ImperxStream::Snap(cv::Mat &frame) { // 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; 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 int lWidth = 0, lHeight = 0; if ( lBuffer->GetPayloadType() == PvPayloadTypeImage ) { // Get image specific buffer interface PvImage *lImage = lBuffer->GetImage(); // Read width, height lWidth = (int) lImage->GetWidth(); lHeight = (int) lImage->GetHeight(); unsigned char *img = lImage->GetDataPointer(); // cv::Mat lframe(lHeight,lWidth,CV_8UC1,img, cv::Mat::AUTO_STEP); // lframe.copyTo(frame); for (int m = 0; m < lHeight; m++) { for (int n = 0; n < lWidth; n++) { frame.at<unsigned char>(m,n) = img[m*lWidth + n]; // std::cout << (short int) img[n*lHeight +m] << " "; } } } else { std::cout << "No image\n"; } std::cout << lWidth << " " << lHeight << "\n"; } else { std::cout << "Damaged Result\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 { std::cout << "Timeout\n"; } ++lDoodleIndex %= 6; }
bool StartSlave() { // Let the user select the device to receive from PvString lDeviceIP; if ( !SelectDevice( lDeviceIP ) ) { return false; } // Create the PvStream object PvStream lStream; // Create the PvPipeline object PvPipeline lPipeline( &lStream ); // Create a PvPipeline event sink (used to trap buffer too small events) PipelineEventSink lPipelineEventSink; lPipeline.RegisterEventSink( &lPipelineEventSink ); // Open stream printf( "Opening stream\n" ); lStream.Open( lDeviceIP, "239.192.1.1", 1042 ); // IMPORTANT: the pipeline needs to be "armed", or started before // we instruct the device to send us images printf( "Starting pipeline\n" ); lPipeline.SetBufferCount( 16 ); lPipeline.Start(); // Get stream parameters/stats PvGenParameterArray *lStreamParams = lStream.GetParameters(); PvGenInteger *lCount = dynamic_cast<PvGenInteger *>( lStreamParams->Get( "ImagesCount" ) ); PvGenFloat *lFrameRate = dynamic_cast<PvGenFloat *>( lStreamParams->Get( "AcquisitionRateAverage" ) ); PvGenFloat *lBandwidth = dynamic_cast<PvGenFloat *>( lStreamParams->Get( "BandwidthAverage" ) ); PvGenBoolean *lIgnoreMissingPackets = dynamic_cast<PvGenBoolean *>( lStreamParams->Get( "IgnoreMissingPackets" ) ); // Disabling resend packets lIgnoreMissingPackets->SetValue( true ); 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 receiving>\n" ); while ( !PvKbHit() ) { // Retrieve next buffer PvBuffer *lBuffer = NULL; PvResult lOperationResult; PvResult lResult = lPipeline.RetrieveNextBuffer( &lBuffer, 1000, &lOperationResult ); if ( lResult.IsOK() ) { if (lOperationResult.IsOK()) { // // We now have a valid buffer. This is where you would typically process the buffer. // ----------------------------------------------------------------------------------------- // ... lCount->GetValue( lImageCountVal ); lFrameRate->GetValue( lFrameRateVal ); lBandwidth->GetValue( 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(); } printf( "%c BlockID: %016llX W: %i H: %i %.01f FPS %.01f Mb/s\r", lDoodle[ lDoodleIndex ], lBuffer->GetBlockID(), lWidth, lHeight, lFrameRateVal, lBandwidthVal / 1000000.0 ); } // We have an image - do some processing (...) and VERY IMPORTANT, // release the buffer back to the pipeline lPipeline.ReleaseBuffer( lBuffer ); } else { // Timeout printf( "%c Timeout\r", lDoodle[ lDoodleIndex ] ); } ++lDoodleIndex %= 6; } PvGetChar(); // Flush key buffer for next stop printf( "\n\n" ); // We stop the pipeline - letting the object lapse out of // scope would have had the destructor do the same, but we do it anyway printf( "Stop pipeline\n" ); lPipeline.Stop(); // Now close the stream. Also optionnal but nice to have printf( "Closing stream\n" ); lStream.Close(); // Unregister pipeline event sink. Optional but nice to have. lPipeline.UnregisterEventSink( &lPipelineEventSink ); return true; }