Search in sources :

Example 6 with Point

use of org.bytedeco.opencv.opencv_core.Point in project qupath by qupath.

the class OpenCVTools method labelImage.

/**
 * Create a labelled image from a binary image using findContours and drawContours.
 * @param matBinary
 * @param matLabels
 * @param contourRetrievalMode defined within OpenCV findContours
 * @deprecated Use {@link #label(Mat, Mat, int)} instead.
 */
@Deprecated
public static void labelImage(Mat matBinary, Mat matLabels, int contourRetrievalMode) {
    MatVector contours = new MatVector();
    Mat hierarchy = new Mat();
    opencv_imgproc.findContours(matBinary, contours, hierarchy, contourRetrievalMode, opencv_imgproc.CHAIN_APPROX_SIMPLE);
    Point offset = new Point(0, 0);
    for (int c = 0; c < contours.size(); c++) {
        opencv_imgproc.drawContours(matLabels, contours, c, Scalar.all(c + 1), -1, 8, hierarchy, 2, offset);
    }
    hierarchy.close();
    contours.close();
}
Also used : Mat(org.bytedeco.opencv.opencv_core.Mat) MatVector(org.bytedeco.opencv.opencv_core.MatVector) Point(org.bytedeco.opencv.opencv_core.Point) Point(org.bytedeco.opencv.opencv_core.Point)

Example 7 with Point

use of org.bytedeco.opencv.opencv_core.Point in project qupath by qupath.

the class OpenCVTools method fillSmallHoles.

/**
 * Fill holes in a binary image (1-channel, 8-bit unsigned) with an area &lt;= maxArea.
 *
 * @param matBinary
 * @param maxArea
 */
public static void fillSmallHoles(Mat matBinary, double maxArea) {
    Mat matHoles = new Mat();
    invertBinary(matBinary, matHoles);
    MatVector contours = new MatVector();
    Mat hierarchy = new Mat();
    opencv_imgproc.findContours(matHoles, contours, hierarchy, opencv_imgproc.RETR_CCOMP, opencv_imgproc.CHAIN_APPROX_SIMPLE);
    Scalar color = Scalar.WHITE;
    int ind = 0;
    Point offset = new Point(0, 0);
    Indexer indexerHierarchy = hierarchy.createIndexer();
    for (int c = 0; c < contours.size(); c++) {
        Mat contour = contours.get(c);
        // TODO: Check hierarchy indexing after switch to JavaCPP!!
        if (indexerHierarchy.getDouble(0, ind, 3) >= 0 || opencv_imgproc.contourArea(contour) > maxArea) {
            ind++;
            continue;
        }
        opencv_imgproc.drawContours(matBinary, contours, c, color, -1, opencv_imgproc.LINE_8, null, Integer.MAX_VALUE, offset);
        ind++;
    }
}
Also used : Mat(org.bytedeco.opencv.opencv_core.Mat) ByteIndexer(org.bytedeco.javacpp.indexer.ByteIndexer) IntIndexer(org.bytedeco.javacpp.indexer.IntIndexer) ShortIndexer(org.bytedeco.javacpp.indexer.ShortIndexer) DoubleIndexer(org.bytedeco.javacpp.indexer.DoubleIndexer) UByteIndexer(org.bytedeco.javacpp.indexer.UByteIndexer) UShortIndexer(org.bytedeco.javacpp.indexer.UShortIndexer) FloatIndexer(org.bytedeco.javacpp.indexer.FloatIndexer) Indexer(org.bytedeco.javacpp.indexer.Indexer) MatVector(org.bytedeco.opencv.opencv_core.MatVector) Point(org.bytedeco.opencv.opencv_core.Point) Point(org.bytedeco.opencv.opencv_core.Point) Scalar(org.bytedeco.opencv.opencv_core.Scalar)

Aggregations

Mat (org.bytedeco.opencv.opencv_core.Mat)7 Point (org.bytedeco.opencv.opencv_core.Point)7 DoublePointer (org.bytedeco.javacpp.DoublePointer)2 MatVector (org.bytedeco.opencv.opencv_core.MatVector)2 Scalar (org.bytedeco.opencv.opencv_core.Scalar)2 ArrayList (java.util.ArrayList)1 Pointer (org.bytedeco.javacpp.Pointer)1 ByteIndexer (org.bytedeco.javacpp.indexer.ByteIndexer)1 DoubleIndexer (org.bytedeco.javacpp.indexer.DoubleIndexer)1 FloatIndexer (org.bytedeco.javacpp.indexer.FloatIndexer)1 Indexer (org.bytedeco.javacpp.indexer.Indexer)1 IntIndexer (org.bytedeco.javacpp.indexer.IntIndexer)1 ShortIndexer (org.bytedeco.javacpp.indexer.ShortIndexer)1 UByteIndexer (org.bytedeco.javacpp.indexer.UByteIndexer)1 UShortIndexer (org.bytedeco.javacpp.indexer.UShortIndexer)1 AbstractScalar (org.bytedeco.opencv.opencv_core.AbstractScalar)1 Point2f (org.bytedeco.opencv.opencv_core.Point2f)1