使用 OpenCV 和 Qt 打开视频时出错
Posted
技术标签:
【中文标题】使用 OpenCV 和 Qt 打开视频时出错【英文标题】:Error while opening a video with OpenCV and Qt 【发布时间】:2013-12-17 09:05:26 【问题描述】:当我想要获取视频捕获以在图像中逐帧查看时,我有大约 15 个错误。
首先我从我的链接调用我的视频。
然后从中获取我的框架。
然后转换成图片。
最后在像素图中查看。
我的代码
#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
【问题讨论】:
你能用qt-creator编译和链接一个简单的hello world opencv程序吗?你使用 windows 和 minGW 吗?这些库真的在 /bin 文件夹中还是 /lib 文件夹中? 不,我不能:(我试图编译一个新项目,但我不能这样做我应该怎么做才能编译它??? 你用的是windows还是linux?您从哪里获得 OpenCV 库(您是自己构建的还是预先构建的)?D:/ubunto/OpenCV/opencv/build/x86/mingw/bin
中有哪些文件以及 ``D:/ubunto/OpenCV/opencv/build/x86/mingw` 中的所有文件夹是什么?
有人可以修正语法吗?它的英文读起来很糟糕,但我目前没有足够的时间。
'D:/ubunto/OpenCV/opencv/build/x86/mingw/bin'.dll中的文件类型和D:/ubunto/OpenCV/opencv/build/x86/mingw
mingw文件夹VC9文件夹VC10文件夹中的文件夹
【参考方案1】:
如果您查看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
【讨论】:
我的代码也使用了 QT5 并且打算在 Windows/Linux/Mac OS X 上编译。【参考方案2】:错误告诉您必须在 makefile 中链接包含 Mat 的特定库:
-lopencv_core
看看documentaion。
当出现如下错误时:
In function `ZN5Form1D2Ev'
可能是你安装了两个不同的 opencv 版本,不是吗?
【讨论】:
不不,只有一个版本以上是关于使用 OpenCV 和 Qt 打开视频时出错的主要内容,如果未能解决你的问题,请参考以下文章