Search in sources :

Example 26 with Point

use of org.opencv.core.Point in project kifu-recorder by leonardost.

the class ImageUtils method generateOrthogonalBoardImage.

public static Mat generateOrthogonalBoardImage(Mat image, Corner[] corners) {
    Mat orthogonalBoardImage = new Mat(ORTHOGONAL_BOARD_IMAGE_SIZE, ORTHOGONAL_BOARD_IMAGE_SIZE, image.type());
    Mat orthogonalImageCorners = new Mat(4, 1, CvType.CV_32FC2);
    orthogonalImageCorners.put(0, 0, 0, 0, ORTHOGONAL_BOARD_IMAGE_SIZE, 0, ORTHOGONAL_BOARD_IMAGE_SIZE, ORTHOGONAL_BOARD_IMAGE_SIZE, 0, ORTHOGONAL_BOARD_IMAGE_SIZE);
    Point[] realCornerPositions = new Point[4];
    for (int i = 0; i < 4; i++) {
        Ponto realCornerPosition = corners[i].getRealCornerPosition();
        realCornerPositions[i] = new Point(realCornerPosition.x, realCornerPosition.y);
    }
    Mat boardPositionInImage = new Mat(4, 1, CvType.CV_32FC2);
    boardPositionInImage.put(0, 0, realCornerPositions[0].x, realCornerPositions[0].y, realCornerPositions[1].x, realCornerPositions[1].y, realCornerPositions[2].x, realCornerPositions[2].y, realCornerPositions[3].x, realCornerPositions[3].y);
    Mat transformationMatrix = Imgproc.getPerspectiveTransform(boardPositionInImage, orthogonalImageCorners);
    Imgproc.warpPerspective(image, orthogonalBoardImage, transformationMatrix, orthogonalBoardImage.size());
    return orthogonalBoardImage;
}
Also used : Mat(org.opencv.core.Mat) Ponto(br.edu.ifspsaocarlos.sdm.kifurecorder.processing.cornerDetector.Ponto) Point(org.opencv.core.Point) Point(org.opencv.core.Point)

Example 27 with Point

use of org.opencv.core.Point in project kifu-recorder by leonardost.

the class ImageUtils method rotateImage.

// direction = -1 counter-clockwise, 1 clockwise
public static Mat rotateImage(Mat image, int direction) {
    Point center = new Point(image.cols() / 2, image.rows() / 2);
    // Positive values mean counter-clockwise rotation
    direction *= -1;
    Mat transformationMatrix = Imgproc.getRotationMatrix2D(center, 90 * direction, 1);
    Mat rotatedImage = new Mat();
    Imgproc.warpAffine(image, rotatedImage, transformationMatrix, new Size(image.cols(), image.rows()));
    return rotatedImage;
}
Also used : Mat(org.opencv.core.Mat) Size(org.opencv.core.Size) Point(org.opencv.core.Point)

Example 28 with Point

use of org.opencv.core.Point in project kifu-recorder by leonardost.

the class BoardDetectorByQuadrilateralCounting method addBlackBorderAround.

private Mat addBlackBorderAround(Mat image) {
    Mat imageWithBlackBorder = image.clone();
    Imgproc.rectangle(imageWithBlackBorder, new Point(0, 0), new Point(499, 499), new Scalar(0, 0, 0), 1);
    return imageWithBlackBorder;
}
Also used : Mat(org.opencv.core.Mat) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint) Scalar(org.opencv.core.Scalar)

Example 29 with Point

use of org.opencv.core.Point in project kifu-recorder by leonardost.

the class BoardDetectorByQuadrilateralCounting method detectContoursIn.

private List<MatOfPoint> detectContoursIn(Mat imageWithBordersDetected) {
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    Imgproc.findContours(imageWithBordersDetected, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
    removeSmallContours(contours);
    return contours;
}
Also used : Mat(org.opencv.core.Mat) ArrayList(java.util.ArrayList) MatOfPoint(org.opencv.core.MatOfPoint) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Example 30 with Point

use of org.opencv.core.Point in project kifu-recorder by leonardost.

the class FirstEllipseDetector method detectContoursIn.

private List<MatOfPoint> detectContoursIn(Mat imageWithBordersDetected) {
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    // Imgproc.findContours(imageWithBordersDetected, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
    Imgproc.findContours(imageWithBordersDetected, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
    removeSmallContours(contours);
    System.out.println("Number of contours found in scene: " + contours.size());
    return contours;
}
Also used : Mat(org.opencv.core.Mat) ArrayList(java.util.ArrayList) MatOfPoint(org.opencv.core.MatOfPoint) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Aggregations

Point (org.opencv.core.Point)56 MatOfPoint (org.opencv.core.MatOfPoint)30 Mat (org.opencv.core.Mat)23 ArrayList (java.util.ArrayList)11 Scalar (org.opencv.core.Scalar)9 Line (com.disnodeteam.dogecv.math.Line)7 Rect (org.opencv.core.Rect)7 Size (org.opencv.core.Size)7 MatOfPoint2f (org.opencv.core.MatOfPoint2f)4 TimingLogger (android.util.TimingLogger)2 Ponto (br.edu.ifspsaocarlos.sdm.kifurecorder.processing.cornerDetector.Ponto)2 KeyPoint (org.opencv.core.KeyPoint)2 MatOfKeyPoint (org.opencv.core.MatOfKeyPoint)2 Pair (android.util.Pair)1 Corner (br.edu.ifspsaocarlos.sdm.kifurecorder.processing.cornerDetector.Corner)1 Rectangle (java.awt.Rectangle)1 List (java.util.List)1 ImageNotFoundException (org.getopentest.exceptions.ImageNotFoundException)1 Core (org.opencv.core.Core)1 MinMaxLocResult (org.opencv.core.Core.MinMaxLocResult)1