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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations