title: On visual C++ how can I works on an array of images with threads (parallelism)
body: <p>I want to ask how can use multiple threads to works on array of OpenCV Mat images...</p>
  
  <p>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:</p>
  
  <pre><code>struct Args
  {
       Mat in[6];
       Mat out[6];
  };
  </code></pre>
  
  <p>In main code I populate the input "in" array with six images, with this code, and assing it to struct in array:</p>
  
  <pre><code>    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;
  </code></pre>
  
  <p>Now I want to use multiple threads to process this images...all six images, and store them in output array to visualize them.</p>
  
  <p>the functions are:</p>
  
  <pre><code> //greyscale funct
   void grey (void *param){
  while (TRUE)
  {
  WaitForSingleObject(mutex,INFINITE);
  Args* arg = (Args*)param;
  cvtColor(*arg-&gt;in,*arg-&gt;out,CV_BGR2GRAY);
  ReleaseMutex(mutex);
  }
  _endthread();
   }
    //threshold funct
   void soglia(void *param){
  while (TRUE)
  {
  WaitForSingleObject(mutex,INFINITE);
  Args* arg = (Args*)param;
  threshold(*arg-&gt;out,*arg-&gt;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-&gt;out);
  waitKey(10);
  ReleaseMutex(mutex);
  }
  //_endthread();
    }
  </code></pre>
  
  <p>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?</p>
  
  <p>I mean: while second thread soglia works on first image of array, the first thread grey start works on secondo images..and so on....</p>
  
  <p>How can I do this?</p>
  
  <p>Thanks in advance for your attention and time.</p>