QT上面搭建opencv環境,本來用了一堆復雜的QT語言由于看不太懂(而且顯示的圖片變得特別小,1平飛厘米那么大,不會改),就找了個極其簡單的的例程,我覺得環境沒問題。
結果不報錯,但是啥都不顯示,printf都不顯示...好奇怪。cmake編譯的.去掉namewindow和imshow的話printf就正常了.
這是main檔案
#include <QCoreApplication>
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat image=imread("C:/Users/Administrator/Desktop/1.jpg");
if(image.empty())
{
fprintf(stderr,"Error: load image failed.");
return-1;
}
namedWindow("test",CV_WINDOW_AUTOSIZE);
imshow("test",image);
printf("****");
return a.exec();
}
這是pro檔案
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH+=E:/opencv-3.2.0/newbuild/install/include \
E:/opencv-3.2.0/newbuild/install/include/opencv \
E:/opencv-3.2.0/newbuild/install/include/opencv2
LIBS+= E:/opencv-3.2.0/newbuild/install/x86/mingw/lib/libopencv_core320.dll.a \
E:/opencv-3.2.0/newbuild/install/x86/mingw/lib/libopencv_highgui320.dll.a \
E:/opencv-3.2.0/newbuild/install/x86/mingw/lib/libopencv_imgproc320.dll.a \
E:/opencv-3.2.0/newbuild/install/x86/mingw/lib/libopencv_imgcodecs320.dll.a \
E:/opencv-3.2.0/newbuild/install/x86/mingw/lib/libopencv_highgui320.dll.a \
E:/opencv-3.2.0/newbuild/install/x86/mingw/lib/libopencv_videoio320.dll.a
SOURCES += main.cpp
我參考的是以下這個博客https://blog.csdn.net/Betterc5/article/details/88374258
也就換個平臺,
uj5u.com熱心網友回復:
qt控制臺輸出用qDebug()<<uj5u.com熱心網友回復:
僅呼叫opencv的 imshow("test",image);是不會顯示圖片的,需要加一行代碼:imshow("test",image);
waitKey(1);
uj5u.com熱心網友回復:
你這個和Qt沒啥關系,你opencv用的不對。你可以用opencv官方的例子uj5u.com熱心網友回復:
你確定,我VS里面都這樣寫的,這段顯示圖片我真的是背都背的出來了。
uj5u.com熱心網友回復:

代碼就是你的,修正了一下WINDOW_AUTOSIZE和圖片檔案名:
#include <QCoreApplication>
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat image=imread("e:/mm.jpg");
if(image.empty())
{
fprintf(stderr,"Error: load image failed.");
return-1;
}
namedWindow("test",WINDOW_AUTOSIZE);
imshow("test",image);
printf("****");
return a.exec();
}
pro也類似:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp
INCLUDEPATH += C:/opencv/build/include
CONFIG(debug, debug|release){
LIBS += -LC:/opencv/build/x64/vc15/lib -lopencv_world420d
} else {
LIBS += -LC:/opencv/build/x64/vc15/lib -lopencv_world420
}
DESTDIR = $${PWD}/bin/amd64
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
uj5u.com熱心網友回復:
哈哈我搞出來了qt工程的目錄出了點問題

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/48855.html
標籤:Qt
