- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am currently using openmp in the computer vision. What I want to do is grab images from to cameras. By using the parallel structure, I firstly generate two threads using the omp sections. The each stream from these cameras is proposed to grabbed and displayed in a corresponding thread. I am using the opencv to grab and display images. Once I use the series structure, i.e. images from two cameras are grabbed one by one, there is no problem. However, if I use the parallel structure, I can see that two threads do work, but I can only display one image. I am not quite sure about the problem. I need your help in this issue or any other suggestion.
I am using Xeon 2Cpu workstation with winxp system and intel cpp compiler 9.0 installed. The opencv is v4beta. The c file is shown as follows:
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include
#include
#include
void main()
{
IplImage *image1, *image2;
CvCapture *capture1, *capture2;
clock_t t1, t2;
int nframe1, nframe2, tid, nthreads;
capture1=cvCaptureFromCAM(-1);
capture2=cvCaptureFromCAM(-1);
cvNamedWindow("camera1", 1);
cvNamedWindow("camera2", 1);
cvResizeWindow("camera1", 320, 240);
cvResizeWindow("camera2", 320, 240);
omp_set_num_threads(2);
nframe1=0;
nframe2=0;
for (;;)
{
t1=clock();
#pragma omp parallel private(tid)
{
tid=omp_get_thread_num();
if (tid==0)
{
nthreads=omp_get_num_threads();
printf("Number of threads = %d ", nthreads);
}
printf("Thread %d starting.... ", tid);
#pragma omp sections
{
#pragma omp section
{
printf("Thread %d grabbing from camera 1 ", tid);
image1=cvQueryFrame(capture1);
cvShowImage("camera1", image1);
printf("This is the No %d frame from camera1 ", nframe1);
nframe1++;
}
#pragma omp section
{
printf("Thread %d grabbing from camera 2 ", tid);
image2=cvQueryFrame(capture2);
cvShowImage("camera2", image2);
printf("This is the No %d frame from camera2 ", nframe2);
nframe2++;
}
}
}
t2=clock();
printf("Time is %f ", (double)(t2-t1)/CLOCKS_PER_SEC);
if (cvWaitKey(10)>=0)
break;
}
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
cvDestroyAllWindows();
}
I am currently using openmp in the computer vision. What I want to do is grab images from to cameras. By using the parallel structure, I firstly generate two threads using the omp sections. The each stream from these cameras is proposed to grabbed and displayed in a corresponding thread. I am using the opencv to grab and display images. Once I use the series structure, i.e. images from two cameras are grabbed one by one, there is no problem. However, if I use the parallel structure, I can see that two threads do work, but I can only display one image. I am not quite sure about the problem. I need your help in this issue or any other suggestion.
I am using Xeon 2Cpu workstation with winxp system and intel cpp compiler 9.0 installed. The opencv is v4beta. The c file is shown as follows:
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include
#include
#include
void main()
{
IplImage *image1, *image2;
CvCapture *capture1, *capture2;
clock_t t1, t2;
int nframe1, nframe2, tid, nthreads;
capture1=cvCaptureFromCAM(-1);
capture2=cvCaptureFromCAM(-1);
cvNamedWindow("camera1", 1);
cvNamedWindow("camera2", 1);
cvResizeWindow("camera1", 320, 240);
cvResizeWindow("camera2", 320, 240);
omp_set_num_threads(2);
nframe1=0;
nframe2=0;
for (;;)
{
t1=clock();
#pragma omp parallel private(tid)
{
tid=omp_get_thread_num();
if (tid==0)
{
nthreads=omp_get_num_threads();
printf("Number of threads = %d ", nthreads);
}
printf("Thread %d starting.... ", tid);
#pragma omp sections
{
#pragma omp section
{
printf("Thread %d grabbing from camera 1 ", tid);
image1=cvQueryFrame(capture1);
cvShowImage("camera1", image1);
printf("This is the No %d frame from camera1 ", nframe1);
nframe1++;
}
#pragma omp section
{
printf("Thread %d grabbing from camera 2 ", tid);
image2=cvQueryFrame(capture2);
cvShowImage("camera2", image2);
printf("This is the No %d frame from camera2 ", nframe2);
nframe2++;
}
}
}
t2=clock();
printf("Time is %f ", (double)(t2-t1)/CLOCKS_PER_SEC);
if (cvWaitKey(10)>=0)
break;
}
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
cvDestroyAllWindows();
}
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I don't see any OpenMP errors in your program, provided the cvQueryFrame and cvShowImage functions are threadsafe. I'm not an OpenCV expert so I don't know if these functions can be called simultaneously by multiple threads. Does the OpenCV documentation say anything about threadsafety?
Best regards,
Henry
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page