Ask Your Question

Revision history [back]

OpenCV parallelization with OpenMP

enter code here

OpenCV parallelization with OpenMP

I am getting Fatal error in this code. I want to display the frames parallely. Need help.

include <cv.h>

include <cvaux.h>

include <iostream>

include <cxcore.h>

include <highgui.h>

include <omp.h>

using namespace cv; using namespace std;

int main(int argc, char *argv) { int no_of_frames = 0,i,j; int fps = 0; int mid_frame = 0; CvCapture capture = cvCaptureFromFile("/home/nagaraj/ImageVideo/tunnel.avi"); CvCapture* captureNew = cvCaptureFromFile("/home/nagaraj/ImageVideo/tunnel.avi"); if (capture == NULL) { printf("Error: Can't open video.\n"); return -1; } if (captureNew == NULL) { printf("Error: Can't open video.\n"); return -1; } fps = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FPS); no_of_frames = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT); mid_frame = no_of_frames/2; omp_set_num_threads(2);

pragma omp parallel sections

enter code here
{

pragma omp section

{
    //cvSetCaptureProperty(capture,CV_CAP_PROP_POS_FRAMES,0);
    IplImage* img = cvQueryFrame(capture);
    cvNamedWindow("Window1",CV_WINDOW_AUTOSIZE);
    cvShowImage("Window1",img);
    cvWaitKey(10000);
    cvReleaseImage(&img);
    cvDestroyWindow("Window1");
    cvReleaseCapture(&capture);
}

pragma omp section

{
    cvSetCaptureProperty(captureNew,CV_CAP_PROP_POS_FRAMES,(double)mid_frame-1);
    IplImage* img = cvQueryFrame(captureNew);
    cvNamedWindow("Window2",CV_WINDOW_AUTOSIZE);
    cvShowImage("Window2",img);
    cvWaitKey(10000);
    cvReleaseImage(&img);
    cvDestroyWindow("Window2");
    cvReleaseCapture(&captureNew);
}

} }

click to hide/show revision 3
OpenCV OpenMP query

OpenCV parallelization with OpenMP

I am getting Fatal error in this code. I want to display the frames parallely. Need help.help.I am newbee to OpenCV and OpenMP. Ur suggestions will be helpful for me. please :)

include <cv.h>

include <cvaux.h>

include <iostream>

include <cxcore.h>

include <highgui.h>

include <omp.h>

 #include <cv.h>
    #include <cvaux.h>
    #include <iostream>
    #include <cxcore.h>
    #include <highgui.h>
    #include <omp.h>

    using namespace cv;
 using namespace std;

std; int main(int argc, char *argv) **argv) { int no_of_frames = 0,i,j; int fps = 0; int mid_frame = 0; CvCapture CvCapture* capture = cvCaptureFromFile("/home/nagaraj/ImageVideo/tunnel.avi"); CvCapture* captureNew = cvCaptureFromFile("/home/nagaraj/ImageVideo/tunnel.avi"); if (capture == NULL) { printf("Error: Can't open video.\n"); return -1; } if (captureNew == NULL) { printf("Error: Can't open video.\n"); return -1; } fps = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FPS); no_of_frames = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT); mid_frame = no_of_frames/2; omp_set_num_threads(2);

pragma omp_set_num_threads(2); #pragma omp parallel sections

sections
{

pragma #pragma omp section

section
{
 //cvSetCaptureProperty(capture,CV_CAP_PROP_POS_FRAMES,0);
  IplImage* img = cvQueryFrame(capture);
 cvNamedWindow("Window1",CV_WINDOW_AUTOSIZE);
 cvShowImage("Window1",img);
 cvWaitKey(10000);
 cvReleaseImage(&img);
 cvDestroyWindow("Window1");
 cvReleaseCapture(&capture);
 }
#pragma omp section
{
cvSetCaptureProperty(captureNew,CV_CAP_PROP_POS_FRAMES,(double)mid_frame-1);
IplImage* img = cvQueryFrame(captureNew);
cvNamedWindow("Window2",CV_WINDOW_AUTOSIZE);
cvShowImage("Window2",img);
cvWaitKey(10000);
cvReleaseImage(&img);
cvDestroyWindow("Window2");
cvReleaseCapture(&captureNew);
}
}
}

pragma omp section

{
    cvSetCaptureProperty(captureNew,CV_CAP_PROP_POS_FRAMES,(double)mid_frame-1);
    IplImage* img = cvQueryFrame(captureNew);
    cvNamedWindow("Window2",CV_WINDOW_AUTOSIZE);
    cvShowImage("Window2",img);
    cvWaitKey(10000);
    cvReleaseImage(&img);
    cvDestroyWindow("Window2");
    cvReleaseCapture(&captureNew);
}

} }