openMP imshow

asked 2015-08-16 02:41:34 -0500

Nbb gravatar image

updated 2015-08-16 03:23:36 -0500

Hi forum,

I am having a problem trying to show multiple videos using openmp. Below is the code

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "omp.h"
#include <iostream>

using namespace cv;
using namespace std;

string Camera[2] = { "camA.avi", "camB.avi" };

int main(int argc, const char * argv[])
{
    omp_set_num_threads(2);
    Mat frame;

    #pragma omp parallel private (frame)
    {
        VideoCapture capture;

        int Thread = omp_get_thread_num();

        capture.open(Camera[Thread]);

        while (1){
            capture.read(frame);

            namedWindow(Camera[Thread], CV_WINDOW_NORMAL);
            imshow(Camera[Thread], frame);
            waitKey(1);
        }

    }

}

I just wanna be able to display both videos at the same time. Hope I can get some help. Thanks

EDIT: So I added in a few lines of code which has no relation to the parallel threads and I got it running... Now im even more confused.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "omp.h"
#include <iostream>

using namespace cv;
using namespace std;

string Camera[2] = { "filmrole3.avi", "filmrole4.avi" };


int main(int argc, const char * argv[])
{
    omp_set_num_threads(2);

    FileStorage fs("Cam3_Homography.yml", FileStorage::READ);
    vector<Mat> Homography_Matrix(2);
    fs["Cam3_Homography"] >> Homography_Matrix[0];
    fs.release();


    #pragma omp parallel
    {
        VideoCapture capture;
        Mat frame;

        int Thread = omp_get_thread_num();

        capture.open(Camera[Thread]);

        while (1){
            capture.read(frame);

            namedWindow(Camera[Thread], CV_WINDOW_NORMAL);
            imshow(Camera[Thread], frame);
            waitKey(1);
        }

    }

}
edit retag flag offensive close merge delete

Comments

What's sort of problem have you got?

I'm not sure that's allowed to share graphical user (with imshow) interface using threads. I will test it

In my own program for multiple videocapture I use one thread for each videocapture and send data to main thread

LBerger gravatar imageLBerger ( 2015-08-16 03:10:41 -0500 )edit

Hello, this is the error that I am receiving

OpenCV Error: Assertion failed (u != 0) in cv::Mat::create, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 412

I went to continue my work and it worked after I added a few lines of unrelated code. I have edited my post above. Im not sure what is going on.

Nbb gravatar imageNbb ( 2015-08-16 03:26:25 -0500 )edit

Finally I have test it's possible to have a thread for each webcam using parallel thread. Do you want to use native OpenMP or use parallel thread (opencv thread may)?

LBerger gravatar imageLBerger ( 2015-08-16 11:16:20 -0500 )edit

Hello, the program is actually working now. I am not sure why the 1st program I posted had problems.

Nbb gravatar imageNbb ( 2015-08-17 10:28:27 -0500 )edit