QT+工业相机问题

captain_richard 2016-09-06 04:32:09
想用QT+工业相机采集视频在界面上显示,现在已经可以采集到视频,但是在QLabel上播放时视频很卡顿,我是通过信号槽来调动的,是不是相机视频一般用共享内存比较快,这个没试过,,,
下面是相机的主要代码

void Grab::run()
{


int width=659,height=494;
int bytePerLine=(width*24+31)/8;//图像每行字节对齐

unsigned char *graydata=new unsigned char[bytePerLine*height];//存储处理后的数据
const unsigned char *data;
unsigned char r,g,b;
QImage *grayImg;//处理后灰度图像

QSize colourImgSize = QSize(659,494);
QImage grayImg2(colourImgSize, QImage::Format_Indexed8);







// The exit code of the sample application.
// int exitCode = 0;

// Automagically call PylonInitialize and PylonTerminate to ensure the pylon runtime system
// is initialized during the lifetime of this object.
Pylon::PylonAutoInitTerm autoInitTerm;
printf("Unable to allocate libmodbus context\n");
try
{
// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());

// Print the model name of the camera.
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;

// The parameter MaxNumBuffer can be used to control the count of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5;

// Start the grabbing of c_countOfImagesToGrab images.
// The camera device is parameterized with a default configuration which
// sets up free-running continuous acquisition.
camera.StartGrabbing();

// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;
int count=0;
// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
while ( camera.IsGrabbing())
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
printf("Grabbing\n");
// Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded()) 、、判断是否成功抓取图像
{


int width = 659;
int height =494;
unsigned char *colourImgDataPtr = (uint8_t *) ptrGrabResult->GetBuffer();


int w_8=(659*8+31)/32*4; //
// QByteArray imageByteArray = QByteArray( (const char*)colourImgDataPtr,659*494 );
//uchar* transData = (unsigned char*)imageByteArray.data();
QSize colourImgSize2(660,494);
QVector<QRgb> grayTable;
for(int i = 0; i < 256; i++)
grayTable.push_back(qRgb(i,i,i));
QImage desImage = QImage(colourImgSize2, QImage::Format_Indexed8);
uchar* transData=desImage.bits();

printf("image %d\n",count);
count++;

for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
*transData=*colourImgDataPtr;
transData++;
colourImgDataPtr++;

}
transData++;
*transData=150;
}


desImage.setColorTable(grayTable);
emit log(sMessage,&desImage); 发射信号





#ifdef PYLON_WIN_BUILD
// Display the grabbed image.
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
else
{
sMessage="Error: "+QString::number(ptrGrabResult->GetErrorCode(),10);


}
}
}
catch (GenICam::GenericException &e)
{

//<< e.GetDescription() << endl;
sMessage+="An exception occurred.";//+e.GetDescription();


}






}
...全文
1761 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
frq007 2017-04-10
  • 打赏
  • 举报
回复
请问楼主你是在pc上做的还是开发板上做的
captain_richard 2017-01-19
  • 打赏
  • 举报
回复
引用 2 楼 qq_32343917 的回复:
你好,请问楼主是怎么配置pylon 和 qt 的呢,有什么相关资料吗?最近刚刚上手pylon,希望能得到指点,谢谢了~~
我是在官网下的SDK里面的,里面有readme有介绍安装,你是用pc还是arm,安装有点不一样,不过差不多的
Little柯南 2016-12-20
  • 打赏
  • 举报
回复
引用 1 楼 tyousi 的回复:
经过实际测试Qlabel显示image的效率很差,可以使用QWidget,然后在paintEvent里面drawPixmap。 这样的效率提升相当大,16路视频播放时CPU才20%; QPainter使用的是GPU,显卡不好的话图片与图片显示之间会有白画面,显卡不是很差的话非常流畅。
你说的确实不错,长做视频采集一般可以这么来
qq_32343917 2016-12-16
  • 打赏
  • 举报
回复
你好,请问楼主是怎么配置pylon 和 qt 的呢,有什么相关资料吗?最近刚刚上手pylon,希望能得到指点,谢谢了~~
tyousi 2016-09-14
  • 打赏
  • 举报
回复
经过实际测试Qlabel显示image的效率很差,可以使用QWidget,然后在paintEvent里面drawPixmap。 这样的效率提升相当大,16路视频播放时CPU才20%; QPainter使用的是GPU,显卡不好的话图片与图片显示之间会有白画面,显卡不是很差的话非常流畅。

16,211

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧