0

I have about 15 errors, when I want to get a video capture to view it frame by frame in an image.

First I call my video from my link.

Then get from it my frame.

Then convert it into image.

Finally view it in pixmap.

MY CODE

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

}

'

The errors like this:

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'

My 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
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • are you able to compile and link a simple hello world opencv program with qt-creator? You work with windows and minGW? Are the libs really inside the /bin folder or is there a /lib folder? – Micka Dec 17 '13 at 10:30
  • No i can't :( i tried to compile a new project but i can't do it what should i do to compile it??? – Islam Hamdy Dec 17 '13 at 10:43
  • Are you using windows or linux? Where did you get the OpenCV libraries from (did you build them yourself or are they pre-built)? What kind of files are in `D:/ubunto/OpenCV/opencv/build/x86/mingw/bin` and what are all folders in ``D:/ubunto/OpenCV/opencv/build/x86/mingw` ? – Micka Dec 17 '13 at 10:46
  • Can someone please fix the grammar? It reads bad as English, but I do not have enough time currently. – László Papp Dec 17 '13 at 10:48
  • the kind of files in 'D:/ubunto/OpenCV/opencv/build/x86/mingw/bin' .dll and the folders in `D:/ubunto/OpenCV/opencv/build/x86/mingw` mingw folder VC9 folder VC10 Folder – Islam Hamdy Dec 17 '13 at 11:00
  • @Islan Hamdy I meant what kind of folders are there inside the /mingw folder. There is a /bin folder and what else? I guess there is a /lib folder where you should link to instead of the /bin folder. In addition the library names might have to be adjusted to the version number: -lopencv_core420 for example if you use openCV 4.2.0 . You have to look at the filenames of the .lib files. Have a look at this link too: http://stackoverflow.com/questions/15881913/how-to-link-opencv-in-qtcreator-and-use-qt-library – Micka Dec 17 '13 at 11:13

2 Answers2

1

If you take a look at the source code of cvVideo (an application that shows how to create a Qt window to display videos loaded with OpenCV) you can see how to achieve what you are looking for.

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
karlphillip
  • 92,053
  • 36
  • 243
  • 426
0

Error tells you that you have to link, in you makefile, the specific library that include Mat:

-lopencv_core

Take a look at the documentaion.

When there are errors like:

In function `ZN5Form1D2Ev'

It could be that you have two different opencv version installed, isn't it?

Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146