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

时间:2013-12-17 09:05:27

标签: c++ qt opencv qt-creator qt5

当我想要获取视频捕捉以在图像中逐帧查看时,我有大约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'

我的LIBS

#-------------------------------------------------
#
# 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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

错误告诉您必须在makefile中链接包含Mat的特定库:

-lopencv_core

查看documentaion

如果出现以下错误:

In function `ZN5Form1D2Ev'

可能是你安装了两个不同的opencv版本,不是吗?