gpt4 book ai didi

c++ - 使用 OpenCV 和 Qt 打开视频时出错

转载 作者:行者123 更新时间:2023-11-28 07:13:19 25 4
gpt4 key购买 nike

当我想要捕获视频以在图像中逐帧查看时,我遇到了大约 15 个错误。

首先,我从我的链接调用我的视频。

然后从中获取我的框架。

然后将其转换为图像。

最后在pixmap中查看。

我的代码

#include "form1.h"
#include "ui_form1.h"
#include <QtCore>
#include <QtGui>
#include <QGraphicsAnchorLayout>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include "qimage.h"
#include <QFileDialog>
#include <QPixmap>
#include "qpixmap.h"

Form1::Form1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
video->open("D:/Downloads/DirectX/Zlatan Ibrahimovic ● Taekwondo Goals.mp4");
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updatePicture()));
timer->start(20);
}

QString fileName;

QImage Form1::getQImageFromFrame(cv::Mat frame) {
//converts the color model of the image from RGB to BGR because OpenCV uses BGR
cv::cvtColor(frame, frame, CV_RGB2BGR);
return QImage((uchar*) (frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
}

Form1::~Form1()
{
delete ui;
}

void Form1::updatePicture()
{
cv::Mat frame1;
video->operator >>( frame1);
img = getQImageFromFrame(frame1);
ui->label->setPixmap(QPixmap::fromImage(img));

}

void Form1::on_pushButton_clicked()
{
//fileName = QFileDialog::getOpenFileName(this,
//tr("Open Image"), "/elhandasya/Desktop", tr("Image Files (*.png *.jpg *.bmp)"));
//QPixmap pix(fileName);

}

'

像这样的错误:

undefined reference to `cv::Mat::Mat()
D:\ubunto\QT5\Tools\QtCreator\bin\Video_Player-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug\debug\form1.o:-1: In function `ZN5Form1D2Ev'

我的库

#-------------------------------------------------
#
# Project created by QtCreator 2013-12-16T09:23:28
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Video_Player
TEMPLATE = app


SOURCES += main.cpp\
form1.cpp

HEADERS += form1.h

FORMS += form1.ui

INCLUDEPATH += -I"D:/ubunto/OpenCV/opencv/build/include/opencv2/imgproc"
INCLUDEPATH += -I"D:/ubunto/OpenCV/opencv/build/include/"
#INCLUDEPATH += "D:/ubunto/OpenCV/opencv/build/include/"


LIBS += -LD:/ubunto/OpenCV/opencv/build/x86/mingw/bin
-lopencv_core
-lopencv_imgproc
-lopencv_highgui
-lopencv_legacy
-lopencv_gpu
-lopencv_video
-lopencv_ml
-lopencv_contrib


#LIBS += D:\ubunto\emgu\emgucv-windows-x86 2.4.0.1717\lib


#-opencv_calib3d240
#-opencv_videostab240
#-opencv_calib3d240
#-opencv_contrib240
#-opencv_core240
#-opencv_features2d240
#-opencv_flann240
#-opencv_gpu240
#-opencv_highgui240
#-opencv_imgproc240
#-opencv_legacy240
#-opencv_ml240
#-opencv_nonfree240
#-opencv_objdetect240
#-opencv_photo240
#-opencv_stitching240
#-opencv_video240

最佳答案

如果你看看cvVideo的源代码(一个显示如何创建 Qt 窗口以显示用 OpenCV 加载的视频的应用程序)您可以看到如何实现您正在寻找的内容。

cvVideo.pro:

TEMPLATE = app

QT += core gui

contains(QT_VERSION, ^5\\.[0-8]\\..*) {
message("* Using Qt $${QT_VERSION}.")
QT += widgets

# On my system I have to specify g++ as compiler else it will use clang++ by default
#QMAKE_CXX=g++
#QMAKE_CC=gcc
}

HEADERS += \
cvWindow.h

SOURCES += \
main.cpp \
cvWindow.cpp

## OpenCV settings for Unix/Linux
unix:!mac {
message("* Using settings for Unix/Linux.")
INCLUDEPATH += /usr/local/include/opencv

LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}

## OpenCV settings for Mac OS X
macx {
message("* Using settings for Mac OS X.")
INCLUDEPATH += /usr/local/include/opencv

LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}

## OpenCV settings for Windows and OpenCV 2.4.2
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"

LIBS += -L"C:\\opencv\\build\\x86\\vc10\\lib" \
-lopencv_core242 \
-lopencv_highgui242 \
-lopencv_imgproc242
}

# Runs this app automatically after the building has succeeded
#QMAKE_POST_LINK=./$$TARGET

关于c++ - 使用 OpenCV 和 Qt 打开视频时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20629919/

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