Skip to content Skip to sidebar Skip to footer

Detecting Simple Geometric Shapes Using Opencv [java]

I'm programming a Java application that detects simple geometric shapes. The following Python code is used as a reference: How to detect simple geometric shapes using OpenCV This i

Solution 1:

This should do the trick. (Assuming you already have yourImagestored in a MatOfPoint2fobject).

MatOfPoint2fapprox=newMatOfPoint2f();
Imgproc.approxPolyDP(yourImage, approx, Imgproc.arcLength(yourImage, true) * 0.02, true);
longcount= approx.total();
if (count == 5) { 
    // this is a pentagon
}

Check this to see the use of total()

OpenCV on Java becomes a bit tricky compared with other languages like Python or C++.

Post a Comment for "Detecting Simple Geometric Shapes Using Opencv [java]"