I want to ask how can use multiple threads to works on array of OpenCV Mat images...
In simple words: using suggestion give me from user of this site, I have packed two array of six images in a struct to pass it at thread:
struct Args
{
Mat in[6];
Mat out[6];
};
In main code I populate the input "in" array with six images, with this code, and assing it to struct in array:
Mat inn[6],ou[6];
inn[0]=imread("C:/OPENCV/Test/imgtest/bird1.jpg",1);
inn[1]=imread("C:/OPENCV/Test/imgtest/bird2.jpg",1);
inn[2]=imread("C:/OPENCV/Test/imgtest/bird3.jpg",1);
inn[3]=imread("C:/OPENCV/Test/imgtest/pig1.jpg",1);
inn[4]=imread("C:/OPENCV/Test/imgtest/pig2.jpg",1);
inn[5]=imread("C:/OPENCV/Test/imgtest/pig3.jpg",1);
Args dati;
*dati.in = *inn;
*dati.out = *ou;
Now I want to use multiple threads to process this images...all six images, and store them in output array to visualize them.
the functions are:
//greyscale funct
void grey (void *param){
while (TRUE)
{
WaitForSingleObject(mutex,INFINITE);
Args* arg = (Args*)param;
cvtColor(*arg->in,*arg->out,CV_BGR2GRAY);
ReleaseMutex(mutex);
}
_endthread();
}
//threshold funct
void soglia(void *param){
while (TRUE)
{
WaitForSingleObject(mutex,INFINITE);
Args* arg = (Args*)param;
threshold(*arg->out,*arg->out,128,255,THRESH_BINARY);
ReleaseMutex(mutex);
}
_endthread();
}
//output
void visualizza(void *param){
while (TRUE)
{
WaitForSingleObject(mutex,INFINITE);
Args* arg = (Args*)param;
imshow("Immagine",*arg->out);
waitKey(10);
ReleaseMutex(mutex);
}
//_endthread();
}
using a mutex object to make them thread safe. These functions using cast to make conversion from void to Args...but, if I want to process all 6 images of input array, and I think to use for cicle, how can I modify these functions to accept and use array with "i" position? Because I use for cicle without use threads and works...but with threads and for have a parallelism, how can I modify these functions for elaborate every images of input array?
I mean: while second thread soglia works on first image of array, the first thread grey start works on secondo images..and so on....
How can I do this?
Thanks in advance for your attention and time.