0

I am using Opencv 2.4.10 in Android Studio and the method connectedComponents is only available in Opencv 3.0 and above. I want to know if there are similar methods I can use to replace connectedComponents() and what are the methods.

I am developing a real-time application that can track the people passing by using an android camera. Currently, I can extract the foreground (or segment the motion) from the background. But some of the detected foreground are divided into parts, so I need connectedComponents() method to connect the blobs that should be grouped together. But like I said earlier, it is not available in my Opencv version. Please help.

This is just a snippet of my code:

 Core.absdiff(frameGray, bgModelGray, differenceGray);

 differenceGray.convertTo(mGray, CvType.CV_8UC1) ;                                
 Imgproc.threshold(mGray, mGray, 0, 255, Imgproc.THRESH_OTSU); 

 Mat erodeElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5, 5), new Point(3, 3));
 Mat dilateElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3));
 Imgproc.erode(mGray, mGray, erodeElement);
 Imgproc.dilate(mGray, mGray, dilateElement);

 contours.clear();
 Imgproc.findContours(mGray, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
 Imgproc.drawContours(mRgba, contours, -1, new Scalar(0, 0, 255), 2);

This is a screenshot after the dilation, contours are not yet added here

Screenshot of detected persons enclosed in bounding boxes

  • Can you show sample output image ? – ZdaR May 18 '17 at 04:59
  • https://youtu.be/LJjqWMhZyhs This is a sample video of my app – dobyvatel75 May 18 '17 at 05:50
  • What do you need that `findContours` doesn't give you? I'm not sure I understand the bit about "connect the blobs that should be grouped together". – beaker May 18 '17 at 16:04
  • @beaker please see the image I added, "Screenshot of detected persons..." My problem is that, there are more than one bounding box drawn to a person because there are gaps in a blob. I need to enclose the person using only one bounding box. In order to do that, the binary foreground of the person should be connected together to be counted as one object/person. – dobyvatel75 May 18 '17 at 17:53
  • Okay, how do you propose to do that with connected components? – beaker May 18 '17 at 17:56
  • Based on my understanding, I need to use the connected components method after dilation in order to close/fill in the gaps to get the whole blob of the person. – dobyvatel75 May 18 '17 at 18:06

0 Answers0