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; }
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; }
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 AcquireImages() { PvResult lResult; PvDeviceInfo *lDeviceInfo = NULL; PvSystem lSystem; PvStream lStream; lSystem.SetDetectionTimeout( 20000 ); lResult = lSystem.Find(); if( !lResult.IsOK() ) { cout << "PvSystem::Find Error: " << lResult.GetCodeString().GetAscii(); return -1; } PvUInt32 lInterfaceCount = lSystem.GetInterfaceCount(); for( PvUInt32 x = 0; x < lInterfaceCount; x++ ) { PvInterface * lInterface = lSystem.GetInterface( x ); cout << "Ethernet Interface " << endl; cout << "IP Address: " << lInterface->GetIPAddress().GetAscii() << endl; cout << "Subnet Mask: " << lInterface->GetSubnetMask().GetAscii() << endl << endl; PvUInt32 lDeviceCount = lInterface->GetDeviceCount(); for( PvUInt32 y = 0; y < lDeviceCount ; y++ ) { lDeviceInfo = lInterface->GetDeviceInfo( y ); cout << "ThermoCam " << endl; cout << "IP Address: " << lDeviceInfo->GetIPAddress().GetAscii() << endl; } } if( lDeviceInfo != NULL ) { cout << "Connecting to " << lDeviceInfo->GetIPAddress().GetAscii() << endl; PvDevice lDevice; lResult = lDevice.Connect( lDeviceInfo ); if ( !lResult.IsOK() ) { cout << "Unable to connect to " << lDeviceInfo->GetIPAddress().GetAscii() << endl; } else { cout << "Successfully connected to " << lDeviceInfo->GetIPAddress().GetAscii() << endl; lResult = lDevice.NegotiatePacketSize( ); if ( !lResult.IsOK() ) { cout << endl; cout << " Failed to negotiate a packet size setting GevSCPSPacketSize to original value"; PvSleepMs( 2500 ); } cout << endl; cout << "3. Open stream......"; lResult = lStream.Open( lDeviceInfo->GetIPAddress() ); if ( !lResult.IsOK() ) { cout << endl; cout << " Failed to open stream"; return 0; } lDevice.SetStreamDestination( lStream.GetLocalIPAddress(), lStream.GetLocalPort() ); PvInt64 lPayloadSize; lDevice.GetGenParameters()->GetIntegerValue( "PayloadSize", lPayloadSize ); PvBuffer * lBuffer = new PvBuffer(); lBuffer->Alloc( static_cast<PvUInt32>( lPayloadSize ) ); PvBuffer *lPtr = NULL; PvImage *lImage = NULL; cout << endl; cout << "5. Grab one image" << endl; lStream.QueueBuffer( lBuffer ); lDevice.GetGenParameters()->SetIntegerValue( "TLParamsLocked", 1 ); lDevice.GetGenParameters()->ExecuteCommand( "AcquisitionStart" ); PvResult lStreamResult; lResult = lStream.RetrieveBuffer( &lPtr, &lStreamResult, 10000 ); lDevice.GetGenParameters()->ExecuteCommand( "AcquisitionStop" ); lDevice.GetGenParameters()->SetIntegerValue( "TLParamsLocked", 0 ); PvInt64 lWidth = 0, lHeight = 0; PvGenParameterArray *lDeviceParams = lDevice.GetGenParameters(); lDeviceParams->GetIntegerValue( "Width", lWidth); lDeviceParams->GetIntegerValue( "Height", lHeight); cvNamedWindow("OpenCV: ThermoCam",CV_WINDOW_NORMAL); cv::Mat raw_lImage(cv::Size(lWidth,lHeight),CV_8U); if ( lResult.IsOK() ) { if ( lStreamResult.IsOK() ) { cout << endl; cout << "6. Using RGB Filter"; lImage=lPtr->GetImage(); lPtr->GetImage()->Alloc(lImage->GetWidth(),lImage->GetHeight(),PvPixelMono8); cout << " a. Save the original image into ImageOriginal.bmp"; PvBufferWriter lBufferWriter; lBufferWriter.Store(lPtr,"ThermoCam.bmp",PvBufferFormatBMP); } lImage->Attach(raw_lImage.data,lImage->GetWidth(),lImage->GetHeight(),PvPixelMono8); //cv::imshow("OpenCV: ThermoCam",raw_lImage); cv::FileStorage fs("ThermoCam.xml",cv::FileStorage::WRITE); fs << "raw_lImage" << raw_lImage; fs.release(); //if(cv::waitKey(1000) >= 0) break; lPtr->Free(); } lBuffer->Free(); lDevice.ResetStreamDestination(); lStream.Close(); lDevice.Disconnect(); return true; } } else { cout << "No device found" << endl; } return 0; }