gpt4 book ai didi

image - OpenCV、Qt、imread、namedWindow、imshow 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 21:04:09 24 4
gpt4 key购买 nike

.pro 文件中:

QT       += core

QT -= gui

TARGET = latihan_2
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

INCLUDEPATH += E:\OpenCV\OpenCV\opencv\build\include

LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_core246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_highgui246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_imgproc246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_features2d246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_calib3d246.dll.a

main.cpp中:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(){
//read image
Mat image = imread("img.jpg", 1);
//create image window named "My image"
namedWindow("My Image", CV_WINDOW_AUTOSIZE);
//show the image on window
imshow("My image", image);
//wait key for 5000ms
waitKey(5000);
return 1;
}

当我点击运行时,没有错误,但它只显示一个名为 qtcreator_process_stub.exe 的黑色窗口。

为什么“我的图像”窗口没有出现并显示 img.jpg?我使用基于 Qt 5.1.1 和 openCV-2.4.6.0 的 Qt creator 2.8.1。

最佳答案

您还可以在 Qt 窗口上显示 cv::Mat我在 cvImage 上演示了如何做到这一点。 .下面的代码改编自cvImage::_open():

std::string filename = ...
cv::Mat mat = cv::imread(filename);

// Since OpenCV uses BGR order, we need to convert it to RGB
// NOTE: OpenCV 2.x uses CV_BGR2RGB, OpenCV 3.x uses cv::COLOR_BGR2RGB
cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB)

// image is created according to Mat dimensions
QImage image(mat.size().width, mat.size().height, QImage::Format_RGB888);

// Copy cv::Mat to QImage
memcpy(image.scanLine(0), mat.data, static_cast<size_t>(image.width() * image.height() * mat.channels()));

// Display the QImage in a QLabel
QLabel label;
label.setPixmap(QPixmap::fromImage(image));
label.show();

关于image - OpenCV、Qt、imread、namedWindow、imshow 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20013903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com