1

Is it possible to perform blog-detection where there are multiple Regions-of-Interest in a frame, using OpenCV ?

I have been reading the 'Learning OpenCV' book, which is based on 1.x 'C' API, and I realized that the ROI information in IplImage accommodates as single ROI, thus all operations would assume a single ROI. Does it mean that I cannot work with multiple ROI's ?

My requirement of multiple ROI stems from a desire to reduce processing while I know for sure that the blobs of interest for me, happen to be in about only 30-40% of the total image area, split into 3-4 regions. Operating on entire image means an overhead of 60-70% in terms of processing power / time. Or, am I missing something very basic here ?

Edited:

Found this question on SA, and looks like this could be one approach. If I understood it correctly, I could use a mask over the entire frame, unmasking the multiple ROI's, but not use a ROI per-se, in IplImage. Is that right ? Also, does this serve my purpose of reducing processing requirement, which was my main objective behind using ROI ?

Community
  • 1
  • 1
bdutta74
  • 2,798
  • 3
  • 31
  • 54
  • I think using mask can solve your problem. However, most of the algorithm iterate through the mask to check if certain pixel is masked out, whether it reduces processing time depends on what kind of operation you are performing. One question, why not just perform single ROI at a time, and do multiply times? – cxyzs7 Apr 05 '12 at 17:14
  • Thanks for taking time to answer, @cxyzs7. Do you mean something like first partition the frame into multiple (say ROI sized) sub-frames, and then process each one separately ? Or, in every frame, perform 4 operations setting different ROI's each time ? If it's the latter, seems doable and fairly elegant, but somehow I got the impression that you set ROI once... which could be mis-interpretation on my part. – bdutta74 Apr 06 '12 at 18:19
  • 1
    I meant the later one, which is easy. You can set ROI multiply times. – cxyzs7 Apr 06 '12 at 20:45
  • Thanks @cxyzs7, seems like an acceptable answer. Why not answer it and I can accept + close it. I might keep it open for another day or so to see if there's anything more efficient (I doubt). – bdutta74 Apr 07 '12 at 02:55

1 Answers1

1

In your case, I think you can set one ROI at a time, and perform your blob detection for each ROI. Remember the resulting coordinates are in sub-image space, you may want to convert them back to original image space. One thing I personally found helpful: usually a ROI is not memory-continuous, if the size of the ROI is quite small comparing to the original image, copying the ROI as another image and running your algorithm on that single image may be faster, for example:

for (int i = 0;i < numRects; ++i) {
    cv::Mat subImg = img(rects[i]).clone();
    blobDetection(subImg);
}

Hope this helps.

cxyzs7
  • 1,227
  • 8
  • 15
  • Excellent. I am certainly going to try this out and try to figure out the kind of speed up I am getting. – bdutta74 Apr 07 '12 at 09:16