3

I am trying to stitch images and the code on which I am working on, it uses SeamFinder and ExposureCompensator along with other functions. But while running the code, these two are taking so much of time. Is there any other alternative or is there a way to improve the performance.

Ptr<ExposureCompensator> compensator = ExposureCompensator::createDefault(expos_comp_type);
compensator->feed(corners, images_warped, masks_warped);

seam_finder = makePtr<GraphCutSeamFinder>(GraphCutSeamFinderBase::COST_COLOR);
seam_finder->find(images_warped_f, corners, masks_warped);

The above are the two functions which are taking time. Please help me in solving the problem. Thanks in advance.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Anirudh
  • 558
  • 1
  • 6
  • 22

1 Answers1

0

The ImageStitching via OpenCV is known to be slow in many cases. Maybe you can give Open MP Parallel a shot here and counter the delay you are facing by using parallelization.

OpenMP consists of a set of compiler #pragmas that control how the program works. The pragmas are designed so that even if the compiler does not support them, the program will still yield correct behavior, but without any parallelism.

In cases where different iterations of loops have nothing to do with each other, therefore making these loops a prime target for parallelization. OpenMP effectively exploits these common program characteristics, so it is extremely easy to allow an OpenMP program to use multiple processors simply by adding a few lines of compiler directives into your source code.

In case you are running a loop in which a set of images are being stitched, you can make sure that the stiching for each set of images run parallely.

#pragma omp parallel for
for( ... )
{
  // Image-stitching algorithms go here.
}

This compiler directive #pragma opm parallel for tells the compiler to auto-parallelize the for loop with OpenMP.

For non-loops, or just sections of code you can do something of this sort :

#pragma omp parallel sections
{
  #pragma omp section
  { 
    DoSomething();
  }

  #pragma omp section
  { 
    DoSomethingElseParallely();
  }
}

I know that the answer might not directly help you out, but might give you some avenues to dig.

You can go through more about the usage of OpenMP loop Parallelism and OpenMP: Sections before using it.

Vishaal Shankar
  • 1,648
  • 14
  • 26
  • I tried OpenMP also. Same problem I am facing even there. The program takes some time when it encounter these two functions during execution. Are there any implementations for these functions available. – Anirudh Feb 08 '18 at 09:31
  • Oh, that's a pity ! I believe this is the implementation that you are looking for : 1. [exposure_compensate.cpp](https://github.com/opencv/opencv/blob/master/modules/stitching/src/exposure_compensate.cpp) 2. [seam_finder.cpp](https://github.com/opencv/opencv/blob/master/modules/stitching/src/seam_finders.cpp) Hope this helps ! – Vishaal Shankar Feb 08 '18 at 09:43
  • I even went through those two .cpp files. Are there any other implementations other than these two. I used #pragma omp parallel for in my code same as u mentioned above. – Anirudh Feb 08 '18 at 09:51