Java Code Examples for org.opencv.core.MatOfPoint2f#put()
The following examples show how to use
org.opencv.core.MatOfPoint2f#put() .
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: AutoCalibrationManager.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
private MatOfPoint2f rotateRect(Mat rotMat, MatOfPoint2f boardRect) { final MatOfPoint2f result = new MatOfPoint2f(); result.alloc(4); for (int i = 0; i < 4; i++) { final Point rPoint = rotPoint(rotMat, new Point(boardRect.get(i, 0)[0], boardRect.get(i, 0)[1])); final double[] rPointD = new double[2]; rPointD[0] = rPoint.x; rPointD[1] = rPoint.y; result.put(i, 0, rPointD); } return result; }
Example 2
Source File: AutoCalibrationManager.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
public java.awt.Point undistortCoords(int x, int y) { if (!warpInitialized) return new java.awt.Point(x, y); final MatOfPoint2f point = new MatOfPoint2f(); point.alloc(1); point.put(0, 0, new double[] { x, y }); Core.perspectiveTransform(point, point, perspMat); return new java.awt.Point((int) point.get(0, 0)[0], (int) point.get(0, 0)[1]); }
Example 3
Source File: AutoCalibrationManager.java From ShootOFF with GNU General Public License v3.0 | 4 votes |
private MatOfPoint2f estimateFullPatternSize(MatOfPoint2f rect) { // Result Mat final MatOfPoint2f result = new MatOfPoint2f(); result.alloc(4); // Get the sources as points final Point topLeft = new Point(rect.get(0, 0)[0], rect.get(0, 0)[1]); final Point topRight = new Point(rect.get(1, 0)[0], rect.get(1, 0)[1]); final Point bottomRight = new Point(rect.get(2, 0)[0], rect.get(2, 0)[1]); final Point bottomLeft = new Point(rect.get(3, 0)[0], rect.get(3, 0)[1]); // We need the heights and widths to estimate the square sizes final double topWidth = Math.sqrt(Math.pow(topRight.x - topLeft.x, 2) + Math.pow(topRight.y - topLeft.y, 2)); final double leftHeight = Math .sqrt(Math.pow(bottomLeft.x - topLeft.x, 2) + Math.pow(bottomLeft.y - topLeft.y, 2)); final double bottomWidth = Math .sqrt(Math.pow(bottomRight.x - bottomLeft.x, 2) + Math.pow(bottomRight.y - bottomLeft.y, 2)); final double rightHeight = Math .sqrt(Math.pow(bottomRight.x - topRight.x, 2) + Math.pow(bottomRight.y - topRight.y, 2)); if (logger.isTraceEnabled()) { logger.trace("points {} {} {} {}", topLeft, topRight, bottomRight, bottomLeft); final double angle = Math.atan((topRight.y - topLeft.y) / (topRight.x - topLeft.x)) * 180 / Math.PI; final double angle2 = Math.atan((bottomRight.y - bottomLeft.y) / (bottomRight.x - bottomLeft.x)) * 180 / Math.PI; logger.trace("square size {} {} - angle {}", topWidth / (PATTERN_WIDTH - 1), leftHeight / (PATTERN_HEIGHT - 1), angle); logger.trace("square size {} {} - angle {}", bottomWidth / (PATTERN_WIDTH - 1), rightHeight / (PATTERN_HEIGHT - 1), angle2); } // Estimate the square widths, that is what we base the estimate of the // real corners on final double squareTopWidth = (1 + BORDER_FACTOR) * (topWidth / (PATTERN_WIDTH - 1)); final double squareLeftHeight = (1 + BORDER_FACTOR) * (leftHeight / (PATTERN_HEIGHT - 1)); final double squareBottomWidth = (1 + BORDER_FACTOR) * (bottomWidth / (PATTERN_WIDTH - 1)); final double squareRightHeight = (1 + BORDER_FACTOR) * (rightHeight / (PATTERN_HEIGHT - 1)); // The estimations final double[] newTopLeft = { topLeft.x - squareTopWidth, topLeft.y - squareLeftHeight }; final double[] newBottomLeft = { bottomLeft.x - squareBottomWidth, bottomLeft.y + squareLeftHeight }; final double[] newTopRight = { topRight.x + squareTopWidth, topRight.y - squareRightHeight }; final double[] newBottomRight = { bottomRight.x + squareBottomWidth, bottomRight.y + squareRightHeight }; // Populate the result result.put(0, 0, newTopLeft); result.put(1, 0, newTopRight); result.put(2, 0, newBottomRight); result.put(3, 0, newBottomLeft); return result; }