qt linux image 显示不了,使用Qt在Linux Ubuntu平台上使用OpenCV 2.2显示图像(Showing an image using OpenCV 2.2 on a Linu...

使用Qt在Linux Ubuntu平台上使用OpenCV 2.2显示图像(Showing an image using OpenCV 2.2 on a Linux Ubuntu platform with Qt)

嘿伙计们,我使用Qt作为我的C ++ IDE平台而不是Ubuntu 10.10和OpenCV 2.2。 我只是编写代码片段并显示问题所在:

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main(int argc, char *argv[])

{

VideoCapture cap = VideoCapture(0);

Mat frame;

do

{

cap >> frame;

imshow("frame",frame);

} while (waitKey(10) != 27);

return 0;

}

我得到3个警告打印输出,看起来像这样:

VIDIOC_QUERYMENU: Invalid argument

一切似乎都很好(相机工作)。

我不得不添加Qt的用法并添加了3行代码,它看起来像这样:

#include

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main(int argc, char *argv[])

{

QApplication app(argc,argv);

VideoCapture cap = VideoCapture(0);

Mat frame;

do

{

cap >> frame;

imshow("frame",frame);

} while (waitKey(10) != 27);

return app.exec();

}

我仍然得到3条警告线,但现在,“框架”窗口是灰色的,没有显示任何内容。

这是我第一次使用Qt,所以我真的不知道它是如何工作的。 我只能猜测QApplication正在控制窗口管理,导致imshow命令无法打开新窗口。

THNX,谢谢你的帮助!

Hey guys, I'm using Qt as my C++ IDE platform over Ubuntu 10.10 with OpenCV 2.2. I'll just write pieces of code and show where the problem is:

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main(int argc, char *argv[])

{

VideoCapture cap = VideoCapture(0);

Mat frame;

do

{

cap >> frame;

imshow("frame",frame);

} while (waitKey(10) != 27);

return 0;

}

I get 3 warning printouts that seems something like this:

VIDIOC_QUERYMENU: Invalid argument

And everything seems to be fine (the camera works).

I had to add usage of the Qt and added 3 lines of code, and it looks like this:

#include

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main(int argc, char *argv[])

{

QApplication app(argc,argv);

VideoCapture cap = VideoCapture(0);

Mat frame;

do

{

cap >> frame;

imshow("frame",frame);

} while (waitKey(10) != 27);

return app.exec();

}

I still get the 3 warning lines but now, the "frame" window is grey, and nothing is shown.

This is my first time using Qt, so I don't really know how it works. I can only guess that QApplication is getting control over the window management, that causes the imshow command to not be able to open a new window.

I would appreciate your help, THNX!

原文:https://stackoverflow.com/questions/5170571

更新时间:2020-07-16 16:07

最满意答案

你的问题是Qt处理它自己的事件循环,因此OpenCV的事件循环很饿,永远不会运行。

让它们一起工作的方法非常简单:将OpenCV显示为QPixmap(通过将图像转换为QImage,然后使用QLabel显示它)。 然后将此QLabel添加到您的QWidget。 您的QWidget可以嵌入或成为QApplication的主要小部件。

要使用cv :: Mat图像的缓冲区作为QImage,请参阅此答案如何将opencv cv :: Mat转换为qimage

Your problem is with Qt handling its own event loop and thus the event loop of OpenCV is starved and never get run.

The way to get them to work together is quite simple: Display your OpenCV as a QPixmap (by convert your image to QImage then use QLabel to display it). Then add this QLabel to your QWidget. Your QWidget can either be embedded or become the main widget of your QApplication.

To use the buffer of your cv::Mat image as your QImage, see this answer how to convert an opencv cv::Mat to qimage

To display this QImage, see Display QImage with QtGui

2017-05-23

相关问答

你先sudo apt-get install qt4-dev-tools 然后dpkg -L qt4-dev-tools | grep "qmake.conf" 试试

我在网上查找安装方法时有两种方式,第一种方案在第三步测试的时候没有成功,不知道问题出在哪里,换用了第二种方式。如果直接用第二种方式安装不成功,可以试试进行第一种方式的第2步。   安装环境是Ubuntu 10.04,内核版本2.6.32.22。OpenCV版本为2.4.3。 第一种方式,参考org.cn/index.php/Debian%E4%B8%8B%E5%AE%89%E8%A3%85 1.更新下载更新软件包列表信息 $ apt-get update 2.查询OpenCV相关软件包   查询获

...

sudo apt-get install libv4l-dev

基于RH的系统编辑 : 在Fedora 16上安装pygame 1.9.1(在virtualenv中): sudo yum install libv4l-devel

sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h

sudo apt-get install libv4l-dev

Editing for RH based syst

...

您是否尝试过使用MSVC2013命令提示符: configure -platform win32-msvc2013 -mp -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg 然后输入: nmake 更新: 此外,在此之前,尝试使用bin文件夹将Qt源代码的路径添加到Windows的PATH变量中。 例如,如果您的PAT

...

您的GCC编译器似乎无法处理内联汇编代码。 您可以尝试更新GCC并进行检查吗? 我认为这是一个已知的问题 Okay its done! I was there was a problem in system.cpp in base folder. I copied the latest code from github and build it and it worked perfectly. Thank you everyone for your concern. Here is the com

...

您可能需要更改 -lopencv_core244 \

-lopencv_highgui244 \

-lopencv_imgproc244

至 -lopencv_core244d \

-lopencv_highgui244d \

-lopencv_imgproc244d

注意每个lib末尾的'd'(如果你要在debug中构建) You might need to change -lopencv_core244 \

-lopencv_highgui244 \

-lopencv_imgproc244

...

我得到了同样的错误 - 昨天晚上我们发现了问题。 我假设您使用BUILD_JPEG或OPENCV_BUILD_3RDPARTY_LIBS标志构建了OpenCV。 此外,OpenCV安装在/ usr / local / lib中。 在这种情况下,OpenCV使用自己的libjpeg构建,libjpeg静态链接到opencv_highgui库。 因此,当您创建QImage并将opencv_highgui链接到项目/应用程序时,链接器将搜索jpeg_CreateDecompress函数(该函数由Qt内部

...

尝试使用tortoise svn下载最新的svn版本的opencv。 opencv 2.2的发布也无法在我的机器的网络摄像头上运行,但是最新的svn确实如此。 您必须使用cmake自己构建此版本。 作为旁注,只要您正在构建它,您也可以从英特尔下载TBB并将其添加到您的构建中,以便在其他功能中实现4倍速的人脸检测。 Try downloading the latest svn version of opencv using tortoise svn. The release of opencv 2.

...

加 INCLUDEPATH += /usr/local/include/Opencvlibname

LIBS+ = -L/usr/local/lib -[module_name1] -[module_name2] ..

在.pro文件中然后尝试。 包括模块名称,例如,如果它的libopencvmodule1.a,将其添加为LIBS+ = -L/usr/local/lib -lopencvmodule1 Add INCLUDEPATH += /usr/local/include/Opencvl

...

你的问题是Qt处理它自己的事件循环,因此OpenCV的事件循环很饿,永远不会运行。 让它们一起工作的方法非常简单:将OpenCV显示为QPixmap(通过将图像转换为QImage,然后使用QLabel显示它)。 然后将此QLabel添加到您的QWidget。 您的QWidget可以嵌入或成为QApplication的主要小部件。 要使用cv :: Mat图像的缓冲区作为QImage,请参阅此答案如何将opencv cv :: Mat转换为qimage 要显示此QImage,请参阅使用QtGui显示

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值