Question

I have a big problem that i can’t solve by myself. OpenCV itself works fine, but i’m not able to load videos. Here’s my code:

PRO- File

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = videoredux
TEMPLATE = app

INCLUDEPATH += C:/OpenCV/opencv_bin/install/include
LIBS += -LC:\\OpenCV\\opencv_bin\\bin \
    libopencv_core248d \
    libopencv_highgui248d \
    libopencv_imgproc248d \
    libopencv_features2d248d \
    libopencv_calib3d248d \
    libopencv_video248d \


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

and the MainWindow Class:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <iostream>
#include <qdebug.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->videoStatusLabel->setText("Kein Video geladen.");

    // SIGNALS & SLOTS

    QObject::connect(ui->chooseVideoButton,SIGNAL(clicked()),
                 this,SLOT(chooseVideo()));
    QObject::connect(ui->startButton,SIGNAL(clicked()),
                 this,SLOT(startProcess()));

}

void MainWindow::chooseVideo(){

    QString fileName = QFileDialog::getOpenFileName(this,
         tr("Open Video"), "/home", tr("Video Files (*.avi *.mp4 *.mpeg *.mpg)"));
    qDebug() << "Path:" << fileName;
    ui->videoStatusLabel->setText(fileName);
}

void MainWindow::startProcess(){
    QString videoPath = ui->videoStatusLabel->text();
    QFileInfo video(videoPath);
    if(video.exists()){
        const std::string path = videoPath.toUtf8().constData();
        cv::VideoCapture capture(path);
        cv::Mat frame;

        if(!capture.isOpened()){
            qDebug() << "Error, video not loaded";
        }

        cv::namedWindow("window",1);
        while(true)
        {
            bool success = capture.read(frame);
            if(success == false){
                break;
            }
            cv::imshow("window",frame);
            cv::waitKey(20);
        }
        cv::waitKey(0);
    }
    else{
        qDebug() << "Error, File doesn't exist";
    }
}

The paths are correct, I tried many different video formats but he never loads the videos. I’m running Qt on a Windows 8 machine and i have “K-Lite Codec Pack 10.2.0 Basic” and ffmpeg installed. The videos are playing properly with my video players. I also tried to copy the .dll to the working directory, searched for opencv dll's in the system32 directory and rebuild OpenCV with mingw on this computer. I know that many people have the same problems, but none of their suggestions solved it. Does anyone know how to solve this problem?

Thank you very much!

Nadine

----UPDATE---- I still can't open video files, so I programmed the application on a Windows7 64-Bit system. It worked fine, but when I try to open the application on a Windows8 computer it still can't open the file. It doesn't matter which codecs are installed, because it generally runs on every Windows7 computer and fails on every Windows8 computer.. The same for older OpenCV-Versions. Is there a general problem with OpenCV and Windows8?

Was it helpful?

Solution 2

I do not know if somebody is still needing an answer, but here is how I solved this problem.

I simply copied the opencv_ffmpegXXX.dll into the directory with the .exe-file. It took me days to find that out. Thanks for all your answers and help!

OTHER TIPS

I had the same problem. Now it is solved. We need to install correct Codecs following the suggestion from OpenCV at http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html. Check the VideoWriter::VideoWriter section. We need Video Codecs by FOURCC at http://www.fourcc.org/codecs.php. Be careful. The installation may install garbage as well as codecs. Not all codecs are recognized. At least now I have mpeg4 and DivX and can open Megamind.avi, used by OpenCV's own demo program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top