Java Code Examples for org.opencv.imgproc.Imgproc#isContourConvex()

The following examples show how to use org.opencv.imgproc.Imgproc#isContourConvex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeClass.java    From AndroidDocumentScanner with MIT License 5 votes vote down vote up
private boolean isRectangle(MatOfPoint2f polygon, int srcArea) {
    MatOfPoint polygonInt = MathUtils.toMatOfPointInt(polygon);

    if (polygon.rows() != 4) {
        return false;
    }

    double area = Math.abs(Imgproc.contourArea(polygon));
    if (area < srcArea * AREA_LOWER_THRESHOLD || area > srcArea * AREA_UPPER_THRESHOLD) {
        return false;
    }

    if (!Imgproc.isContourConvex(polygonInt)) {
        return false;
    }

    // Check if the all angles are more than 72.54 degrees (cos 0.3).
    double maxCosine = 0;
    Point[] approxPoints = polygon.toArray();

    for (int i = 2; i < 5; i++) {
        double cosine = Math.abs(MathUtils.angle(approxPoints[i % 4], approxPoints[i - 2], approxPoints[i - 1]));
        maxCosine = Math.max(cosine, maxCosine);
    }

    return !(maxCosine >= 0.3);
}
 
Example 2
Source File: Contour.java    From FTCVision with MIT License 2 votes vote down vote up
/**
 * Tests if the contour is closed (convex)
 *
 * @return True if closed (convex), false otherwise
 */
public boolean isClosed() {
    return Imgproc.isContourConvex(mat);
}