4

我在将 Image 对象(使用 Point Grej FlyCapture2 SDK 捕获)传递给 QImage 对象时遇到了问题。我通过函数获得与图像数据相关联的指针:

virtual unsigned char* FlyCapture2::GetData  (   ) 

然后通过以下方式加载数据:

QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

两个 Image 对象的数据格式均为 8 位单色。BytesPerLine 参数应该等于图像的宽度(我已经通过将 FlyCapture2::Image 保存到 .bmp 然后将其加载到 QImage 来检查它)。

您认为问题是从 unsigned char* 转换为 uchar* 吗?你还有其他建议吗?逐像素复制图像太慢了。

编辑:我正在将 FlyCapture 捕获的图像转换为FlyCapture2::PIXEL_FORMAT_RGB8,其中:R = G = B = 8 位,在PGR::SnapShot()函数内。SnapShot() 返回unsigned char* 常量。这是我的 Qt 显示功能的一部分:

unsigned char *const img = PGRSystem->SnapShot();
QImage Img(img, 1024, 768, QImage::Format_RGB888);
QGraphicsScene *Scene = new QGraphicsScene();
Scene->addPixmap(QPixmap::fromImage(Img));
ui.ImageView->setScene(Scene);
ui.ImageView->fitInView(ui.ImageView->itemAt(100,100));
delete [] Scene;

我也尝试将 Img 保存到文件中,但随后出现未处理的异常。我尝试了其他像素格式对(FlyCapture2::PIXEL_FORMAT_RGB- 24 bit RGB with QImage::RGB888 and FlyCapture2::PIXEL_FORMAT_RGBU32with QImage::RGB32

还值得一提的是,我正在使用的 QImage 构造函数没有设置 colorTable(检查 QImage 是否为灰度时出现异常)。我想我需要更多帮助。

4

2 回答 2

6

第一件事 - QImage 不支持本机灰度图像,这听起来就像你得到的输出一样 - 所以我很好奇你正在使用什么 Format 参数。可能最简单的解决方案虽然内存效率低,但通过将每个值复制三次(到新的 QByteArray)来将灰度图像扩展为 RGB。

An additional concern is that the particular QImage constructor you're using, does not copy the underlying data, so you need be sure the pointer returned from GetData() outlives the QImage - or force the QImage to make a copy internally, using, say, QImage::copy.

Seeing more code would help, as other respondents noted above.

于 2010-10-27T16:42:31.140 回答
1

Thanks a lot for your help, you were right about the Image formats. Unfortunatelly the main problem was associated with passing the pointer between functions. In PGR::SnapShot() I was creating FlyCapture2::Image and then I was getting the pointer to data. FlyCapture2::Image was detructed when exit the function so returned pointer was BadPtr.

于 2010-10-28T15:48:52.610 回答