Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QT 5.2 / OpenCV 2.4.8 - Can't open video files via VideoCapture
Forum Updated to NodeBB v4.3 + New Features

QT 5.2 / OpenCV 2.4.8 - Can't open video files via VideoCapture

Scheduled Pinned Locked Moved 3rd Party Software
2 Posts 2 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zamahra
    wrote on last edited by
    #1

    Hello Guys!

    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. Does anyone know how to solve this problem?

    Thank you very much!

    Nadine

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I would say that the path you give to OpenCV is invalid. Qt uses Unix style path internally on all platforms but not OpenCV.

      Use QDir::toNativeSeparators and it should work better.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved