1

I'm trying to find the centroids of the connected components using the java version of OpenCV (Java 8 and OpenCV 3.2.0.1). However I can't find a detailed documentation on how to exploit the returned variables. I found this post which explains how the data is structured, but it is for python.

How to use openCV's connected components with stats in python?

I would enjoy having such an explanation for the java one. For exemple, doing centroids.get(0, 0); in Java returns an array with NaN inside even if centroids.rows(); returns 2.

Romain
  • 799
  • 1
  • 9
  • 29
  • You could use contours in java and get the centroids using moments. Have you tried that? If not, which opencv version are you using? – Rick M. Jul 14 '17 at 15:02
  • Please attach you current version of relevant Java code, and mention the exact version of OpenCV you're using. – Dan Mašek Jul 14 '17 at 17:05
  • I'm using Java 8 and OpenCV 3.2.0.1. I didn't tried contours yet because openCv 3.x added connected components functionnality and I wanted to use this. – Romain Jul 14 '17 at 22:55

1 Answers1

0

You need to specify the row from which you're extracting centroid info as well.

Eg:

Imgproc.connectedComponentsWithStats(binarized, labeled, rectComponents, centComponents);     
centComponents.row(i).get(0, 0, centroidInfo);
Point centroid = new Point(centroidInfo[0], centroidInfo[1]);

The object centroid would contain the centroid you want. Hope it helps!

Caife
  • 415
  • 1
  • 5
  • 16