I have problem to convert the (Pleora SDK)PvBuffer into an Opencv buffer and display the stream.
This is the sample code from (Pleora SDK C++) with the added modification.
while ( !PvKbHit() )
{
PvBuffer *lBuffer = NULL;
PvResult lOperationResult;
// Retrieve next buffer
PvResult lResult = aStream->RetrieveBuffer( &lBuffer, &lOperationResult, 1000 );
if ( lResult.IsOK() )
{
if ( lOperationResult.IsOK() )
{
PvPayloadType lType;
//
// We now have a valid buffer. This is where you would typically process the buffer.
// -----------------------------------------------------------------------------------------
// ...
lFrameRate->GetValue( lFrameRateVal );
lBandwidth->GetValue( lBandwidthVal );
// If the buffer contains an image, display width and height.
uint32_t lWidth = 0, lHeight = 0;
lType = lBuffer->GetPayloadType();
cout << fixed << setprecision( 1 );
cout << lDoodle[ lDoodleIndex ];
cout << " BlockID: " << uppercase << hex << setfill( '0' ) << setw( 16 ) << lBuffer->GetBlockID();
if ( lType == PvPayloadTypeImage )
{
// Get image specific buffer interface.
PvImage *lImage = lBuffer->GetImage();
// Read width, height.
lWidth = lImage->GetWidth();
lHeight = lImage->GetHeight();
cout << " W: " << dec << lWidth << " H: " << lHeight;
//********* added modifications ******
namedWindow("cam", CV_WINDOW_AUTOSIZE);
cv::Mat workImage;
lImage->Alloc(lWidth, lHeight, lBuffer->GetImage()->GetPixelType());
// Get image data pointer so we can pass it to CV::MAT container
unsigned char *img = lImage->GetDataPointer();
// Copy/convert Pleora Vision image pointer to cv::Mat container
cv::Mat lframe(lHeight, lWidth, CV_8U, img, cv::Mat::AUTO_STEP);
lframe.copyTo(workImage);
cv::imshow("cam",workImage);
}
With the added lines I am trying to convert the buffer into a Mat and also to display the stream as well but without success . .
Exactly same problem my imshow never appeared and also when I change by imwrite just save a nonesense picture.
RépondreSupprimer