我在重写的qpushbutton中显示opencv调用来的视频图像,图像就奔溃了,然后我加了一个qlabel标签来显示相同的输出图像,程序没用奔溃,说明我生成的qimage是没有问题的,代码如下:
connect(timer,SIGNAL(timeout()),this,SLOT(released()));
void MainWindow::released()
{
Mat frame;
cap>>frame;
if(frame.empty()){
return;
}
cvtColor(frame,frame,CV_BGR2RGB);
QImage image(frame.data,frame.cols,frame.rows,QImage::Format_RGB888);
label->setPixmap(QPixmap::fromImage(image));
qDebug()<<image.byteCount();
QPalette p;
p.setBrush(QPalette::Button,QBrush(image));
bgp->button(0)->setPalette(p);
update();
}
希望能得到帮助,谢谢
http://blog.163.com/qimo601@126/blog/static/15822093201432494134937/
希望能得到大神的解释,谢谢了
我对代码进行了修改,先保存了qimage,然后用qpalette加载了保存的图片,程序就没有报错了,所以我觉得是数据流解析的问题,修改后的代码。
connect(timer,SIGNAL(timeout()),this,SLOT(released()));
void MainWindow::released()
{
Mat frame;
cap>>frame;
if(frame.empty()){
return;
}
cvtColor(frame,frame,CV_BGR2RGB);
QImage image(frame.data,frame.cols,frame.rows,QImage::Format_RGB888);
image.save("1.jpg","jpg");
label->setPixmap(QPixmap::fromImage(image));
qDebug()<<image.byteCount();
QPalette p;
p.setBrush(QPalette::Button,QBrush(QImage("1.jpg")));
bgp->button(0)->setPalette(p);
update();
}