gpt4 book ai didi

c++ - PvBuffer (Pleora SDK) 到 -> Opencv 缓冲区

转载 作者:行者123 更新时间:2023-11-28 02:15:16 25 4
gpt4 key购买 nike

我在将 (Pleora SDK)PvBuffer 转换为 Opencv 缓冲区并处理流时遇到问题。

这是我在(Pleora SDK C++示例代码)中找到的示例代码

while ( !PvKbHit() )
{
PvBuffer *lBuffer = NULL;
PvResult lOperationResult;
PvBufferWriter lBufferWriter;

// 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 = lBuffer->GetImage()->GetWidth();
lHeight = lBuffer->GetImage()->GetHeight();



unsigned char * data = lBuffer->GetImage()->GetDataPointer();

Mat OpencvImg = Mat(Size(lWidth, lHeight), CV_8UC1, data);

threshold(OpencvImg, OpencvImg, 100, 255, 0);

如果您检查最后 3 行,我正在尝试将缓冲区转换为 Mat 但没有成功。我也想显示流。

提前致谢。

最佳答案

我在以下方面取得了一些成功,但是这个结果确实效率低下,我希望找到一种不涉及中间写入磁盘的转换方法。

cv::Mat workImage;
lBuffer->GetImage()->Alloc(lWidth, lHeight, PvPixelBGR8);
lBufferWriter.Store(lBuffer, "ImageOriginal.bmp", PvBufferFormatBMP);
workImage = cv::imread("ImageOriginal.bmp", CV_LOAD_IMAGE_COLOR);

编辑(有效):

cv::Mat workImage;
PvImage* lImage = lBuffer->GetImage();
lImage->Alloc(lWidth, lHeight, PvPixelRGB8);
// 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_8UC3, img, cv::Mat::AUTO_STEP);
lframe.copyTo(workImage);

关于c++ - PvBuffer (Pleora SDK) 到 -> Opencv 缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34218482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com