mardi 27 juillet 2021

What is the best structure for calculating images from multiple thread?

when I tried do average to multiple panorama for blurring moving object, I got panoramas each loop in each threads, and brought by ThreadSafe_Queue. (I try to use this for making threadsafe queue : https://codetrips.com/2020/07/26/modern-c-writing-a-thread-safe-queue/)

void makePanorama_th(int thread_num, ThreadSafe_Queue* frame_q, ThreadSafe_Queue* result_q);

... and run this function asynchronously like this.

v_th_panorama.emplace_back(std::async(std::launch::async, &Pano_Worker::makePanorama_th, pano_worker, i, &this->th_frame_q, &this->th_result_q));

all thread get unique frame from shared queue. and get results from threads by threadsafe queue and do average each pixel value.

make panorama average like

     frame number for make panorama each thread
   thread 1.   2   5   8
   thread 2.    3   6   9
   thread 3.     4   7   10
  1. The average is calculated based on the length of the panorama using the frame with the smallest frame number(2~5). and other thread's remaining sections(2. 5~6/ 3. 5~7), simply sum the pixel values.

          first panorama average
    thread 1.   2   5
    thread 2.    3     
    thread 3.     4
    average     2 ~ 5
    sum             5 ~ 7 
    
  2. if shortest panorama's(2 ~ 5) length reach to longest panorama's length(2 ~ 5 -> 2 ~ 8), sum and do average about the longest section before(2 ~ 7)

second panorama average

   thread 1.   2   5   8
   thread 2.    3   6   
   thread 3.     4   7
   average     2  ~  7
   sum               7 ~ 8

But, When I tried this method, seriously slow. because return image each loop, and calculate average sequentially.

How can I create in real-time average image of multiple panoramas created in multiple threads?

Aucun commentaire:

Enregistrer un commentaire