Java Code Examples for org.opencv.core.Point

The following examples show how to use org.opencv.core.Point. These examples are extracted from open source projects. 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 Project: pasm-yolov3-Android   Source File: Imgproc.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
{
    double[] rect_out = new double[4];
    int retVal = floodFill_0(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3], rect_out, loDiff.val[0], loDiff.val[1], loDiff.val[2], loDiff.val[3], upDiff.val[0], upDiff.val[1], upDiff.val[2], upDiff.val[3], flags);
    if(rect!=null){ rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3]; } 
    return retVal;
}
 
Example 2
Source Project: LPR   Source File: Subdiv2D.java    License: Apache License 2.0 5 votes vote down vote up
public  Point getVertex(int vertex, int[] firstEdge)
{
    double[] firstEdge_out = new double[1];
    Point retVal = new Point(getVertex_0(nativeObj, vertex, firstEdge_out));
    if(firstEdge!=null) firstEdge[0] = (int)firstEdge_out[0];
    return retVal;
}
 
Example 3
Source Project: VIA-AI   Source File: Subdiv2D.java    License: MIT License 5 votes vote down vote up
public  int edgeOrg(int edge, Point orgpt)
{
    double[] orgpt_out = new double[2];
    int retVal = edgeOrg_0(nativeObj, edge, orgpt_out);
    if(orgpt!=null){ orgpt.x = orgpt_out[0]; orgpt.y = orgpt_out[1]; } 
    return retVal;
}
 
Example 4
Source Project: VIA-AI   Source File: Converters.java    License: MIT License 5 votes vote down vote up
public static void Mat_to_vector_RotatedRect(Mat m, List<RotatedRect> rs) {
    if (rs == null)
        throw new java.lang.IllegalArgumentException("rs == null");
    int count = m.rows();
    if (CvType.CV_32FC(5) != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC5 != m.type() ||  m.rows()!=1\n" + m);

    rs.clear();
    float[] buff = new float[5 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        rs.add(new RotatedRect(new Point(buff[5 * i], buff[5 * i + 1]), new Size(buff[5 * i + 2], buff[5 * i + 3]), buff[5 * i + 4]));
    }
}
 
Example 5
Source Project: AndroidDocumentScanner   Source File: PerspectiveTransformation.java    License: MIT License 5 votes vote down vote up
private Point getMassCenter(MatOfPoint2f points) {
    double xSum = 0;
    double ySum = 0;
    List<Point> pointList = points.toList();
    int len = pointList.size();
    for (Point point : pointList) {
        xSum += point.x;
        ySum += point.y;
    }
    return new Point(xSum / len, ySum / len);
}
 
Example 6
Source Project: AndroidDocumentScanner   Source File: NativeClass.java    License: 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 7
Source Project: AndroidDocumentScanner   Source File: PerspectiveTransformation.java    License: MIT License 5 votes vote down vote up
private Size getRectangleSize(MatOfPoint2f rectangle) {
    Point[] corners = rectangle.toArray();

    double top = getDistance(corners[0], corners[1]);
    double right = getDistance(corners[1], corners[2]);
    double bottom = getDistance(corners[2], corners[3]);
    double left = getDistance(corners[3], corners[0]);

    double averageWidth = (top + bottom) / 2f;
    double averageHeight = (right + left) / 2f;

    return new Size(new Point(averageWidth, averageHeight));
}
 
Example 8
Source Project: VIA-AI   Source File: KeyPoint.java    License: MIT License 5 votes vote down vote up
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
{
    pt = new Point(x, y);
    size = _size;
    angle = _angle;
    response = _response;
    octave = _octave;
    class_id = _class_id;
}
 
Example 9
Source Project: LicensePlateDiscern   Source File: Imgproc.java    License: MIT License 5 votes vote down vote up
public static void minEnclosingCircle(MatOfPoint2f points, Point center, float[] radius)
{
    Mat points_mat = points;
    double[] center_out = new double[2];
    double[] radius_out = new double[1];
    minEnclosingCircle_0(points_mat.nativeObj, center_out, radius_out);
    if(center!=null){ center.x = center_out[0]; center.y = center_out[1]; } 
    if(radius!=null) radius[0] = (float)radius_out[0];
    return;
}
 
Example 10
Source Project: LPR   Source File: Converters.java    License: Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_RotatedRect(Mat m, List<RotatedRect> rs) {
    if (rs == null)
        throw new java.lang.IllegalArgumentException("rs == null");
    int count = m.rows();
    if (CvType.CV_32FC(5) != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC5 != m.type() ||  m.rows()!=1\n" + m);

    rs.clear();
    float[] buff = new float[5 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        rs.add(new RotatedRect(new Point(buff[5 * i], buff[5 * i + 1]), new Size(buff[5 * i + 2], buff[5 * i + 3]), buff[5 * i + 4]));
    }
}
 
Example 11
Source Project: LPR   Source File: Subdiv2D.java    License: Apache License 2.0 5 votes vote down vote up
public  int locate(Point pt, int[] edge, int[] vertex)
{
    double[] edge_out = new double[1];
    double[] vertex_out = new double[1];
    int retVal = locate_0(nativeObj, pt.x, pt.y, edge_out, vertex_out);
    if(edge!=null) edge[0] = (int)edge_out[0];
    if(vertex!=null) vertex[0] = (int)vertex_out[0];
    return retVal;
}
 
Example 12
Source Project: AndroidObjectDetection-OpenCV   Source File: CameraActivity.java    License: MIT License 4 votes vote down vote up
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2RGB);
    Size frame_size = new Size(416, 416);
    Scalar mean = new Scalar(127.5);

    Mat blob = Dnn.blobFromImage(frame, 1.0 / 255.0, frame_size, mean, true, false);
    //save_mat(blob);
    net.setInput(blob);

    List<Mat> result = new ArrayList<>();
    List<String> outBlobNames = net.getUnconnectedOutLayersNames();

    net.forward(result, outBlobNames);
    float confThreshold = 0.5f;

    for (int i = 0; i < result.size(); ++i) {
        // each row is a candidate detection, the 1st 4 numbers are
        // [center_x, center_y, width, height], followed by (N-4) class probabilities
        Mat level = result.get(i);
        for (int j = 0; j < level.rows(); ++j) {
            Mat row = level.row(j);
            Mat scores = row.colRange(5, level.cols());
            Core.MinMaxLocResult mm = Core.minMaxLoc(scores);
            float confidence = (float) mm.maxVal;
            Point classIdPoint = mm.maxLoc;
            if (confidence > confThreshold) {

                int centerX = (int) (row.get(0, 0)[0] * frame.cols());
                int centerY = (int) (row.get(0, 1)[0] * frame.rows());
                int width = (int) (row.get(0, 2)[0] * frame.cols());
                int height = (int) (row.get(0, 3)[0] * frame.rows());

                int left = (int) (centerX - width * 0.5);
                int top =(int)(centerY - height * 0.5);
                int right =(int)(centerX + width * 0.5);
                int bottom =(int)(centerY + height * 0.5);

                Point left_top = new Point(left, top);
                Point right_bottom=new Point(right, bottom);
                Point label_left_top = new Point(left, top-5);
                DecimalFormat df = new DecimalFormat("#.##");

                int class_id = (int) classIdPoint.x;
                String label= classNames.get(class_id) + ": " + df.format(confidence);
                Scalar color= colors.get(class_id);

                Imgproc.rectangle(frame, left_top,right_bottom , color, 3, 2);
                Imgproc.putText(frame, label, label_left_top, Imgproc.FONT_HERSHEY_SIMPLEX, 1, new Scalar(0, 0, 0), 4);
                Imgproc.putText(frame, label, label_left_top, Imgproc.FONT_HERSHEY_SIMPLEX, 1, new Scalar(255, 255, 255), 2);
            }
        }
    }
    return frame;
}
 
Example 13
Source Project: VIA-AI   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static void Mat_to_vector_Point2f(Mat m, List<Point> pts) {
    Mat_to_vector_Point(m, pts);
}
 
Example 14
Source Project: LicensePlateDiscern   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static Mat vector_Point_to_Mat(List<Point> pts) {
    return vector_Point_to_Mat(pts, CvType.CV_32S);
}
 
Example 15
Source Project: SoftwarePilot   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static Mat vector_Point2f_to_Mat(List<Point> pts) {
    return vector_Point_to_Mat(pts, CvType.CV_32F);
}
 
Example 16
Source Project: SoftwarePilot   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static Mat vector_Point2d_to_Mat(List<Point> pts) {
    return vector_Point_to_Mat(pts, CvType.CV_64F);
}
 
Example 17
public static void Mat_to_vector_Point2f(Mat m, List<Point> pts) {
    Mat_to_vector_Point(m, pts);
}
 
Example 18
Source Project: LicensePlateDiscern   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static void Mat_to_vector_Point2d(Mat m, List<Point> pts) {
    Mat_to_vector_Point(m, pts);
}
 
Example 19
Source Project: AndroidDocumentScanner   Source File: PerspectiveTransformation.java    License: MIT License 4 votes vote down vote up
private double getDistance(Point p1, Point p2) {
    double dx = p2.x - p1.x;
    double dy = p2.y - p1.y;
    return Math.sqrt(dx * dx + dy * dy);
}
 
Example 20
Source Project: LicensePlateDiscern   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static Mat vector_Point2f_to_Mat(List<Point> pts) {
    return vector_Point_to_Mat(pts, CvType.CV_32F);
}
 
Example 21
Source Project: pasm-yolov3-Android   Source File: Imgproc.java    License: GNU General Public License v3.0 3 votes vote down vote up
public static void erode(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType, Scalar borderValue)
{
    
    erode_0(src.nativeObj, dst.nativeObj, kernel.nativeObj, anchor.x, anchor.y, iterations, borderType, borderValue.val[0], borderValue.val[1], borderValue.val[2], borderValue.val[3]);
    
    return;
}
 
Example 22
Source Project: LicensePlateDiscern   Source File: Imgproc.java    License: MIT License 3 votes vote down vote up
public static void dilate(Mat src, Mat dst, Mat kernel, Point anchor)
{
    
    dilate_3(src.nativeObj, dst.nativeObj, kernel.nativeObj, anchor.x, anchor.y);
    
    return;
}
 
Example 23
Source Project: LicensePlateDiscern   Source File: Imgproc.java    License: MIT License 3 votes vote down vote up
public static void erode(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType)
{
    
    erode_1(src.nativeObj, dst.nativeObj, kernel.nativeObj, anchor.x, anchor.y, iterations, borderType);
    
    return;
}
 
Example 24
Source Project: LPR   Source File: Imgproc.java    License: Apache License 2.0 3 votes vote down vote up
public static void erode(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType)
{
    
    erode_1(src.nativeObj, dst.nativeObj, kernel.nativeObj, anchor.x, anchor.y, iterations, borderType);
    
    return;
}
 
Example 25
Source Project: LicensePlateDiscern   Source File: Imgproc.java    License: MIT License 3 votes vote down vote up
public static void arrowedLine(Mat img, Point pt1, Point pt2, Scalar color, int thickness, int line_type)
{
    
    arrowedLine_2(img.nativeObj, pt1.x, pt1.y, pt2.x, pt2.y, color.val[0], color.val[1], color.val[2], color.val[3], thickness, line_type);
    
    return;
}
 
Example 26
Source Project: pasm-yolov3-Android   Source File: Imgproc.java    License: GNU General Public License v3.0 3 votes vote down vote up
public static void circle(Mat img, Point center, int radius, Scalar color, int thickness, int lineType, int shift)
{
    
    circle_0(img.nativeObj, center.x, center.y, radius, color.val[0], color.val[1], color.val[2], color.val[3], thickness, lineType, shift);
    
    return;
}
 
Example 27
Source Project: LicensePlateDiscern   Source File: Imgproc.java    License: MIT License 3 votes vote down vote up
public static void erode(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType, Scalar borderValue)
{
    
    erode_0(src.nativeObj, dst.nativeObj, kernel.nativeObj, anchor.x, anchor.y, iterations, borderType, borderValue.val[0], borderValue.val[1], borderValue.val[2], borderValue.val[3]);
    
    return;
}
 
Example 28
Source Project: LicensePlateDiscern   Source File: Imgproc.java    License: MIT License 3 votes vote down vote up
public static void line(Mat img, Point pt1, Point pt2, Scalar color, int thickness)
{
    
    line_2(img.nativeObj, pt1.x, pt1.y, pt2.x, pt2.y, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}
 
Example 29
Source Project: LPR   Source File: Imgproc.java    License: Apache License 2.0 3 votes vote down vote up
public static void sepFilter2D(Mat src, Mat dst, int ddepth, Mat kernelX, Mat kernelY, Point anchor, double delta, int borderType)
{
    
    sepFilter2D_0(src.nativeObj, dst.nativeObj, ddepth, kernelX.nativeObj, kernelY.nativeObj, anchor.x, anchor.y, delta, borderType);
    
    return;
}
 
Example 30
Source Project: VIA-AI   Source File: Calib3d.java    License: MIT License 3 votes vote down vote up
public static Mat findEssentialMat(Mat points1, Mat points2, double focal, Point pp, int method, double prob, double threshold, Mat mask)
{
    
    Mat retVal = new Mat(findEssentialMat_5(points1.nativeObj, points2.nativeObj, focal, pp.x, pp.y, method, prob, threshold, mask.nativeObj));
    
    return retVal;
}