org.opencv.core.MatOfPoint2f Java Examples

The following examples show how to use org.opencv.core.MatOfPoint2f. 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: Converters.java    From faceswap with Apache License 2.0 6 votes vote down vote up
public static void Mat_to_vector_vector_Point2f(Mat m, List<MatOfPoint2f> pts) {
    if (pts == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");

    if (m == null)
        throw new java.lang.IllegalArgumentException("Input Mat can't be null");

    List<Mat> mats = new ArrayList<Mat>(m.rows());
    Mat_to_vector_Mat(m, mats);
    for (Mat mi : mats) {
        MatOfPoint2f pt = new MatOfPoint2f(mi);
        pts.add(pt);
        mi.release();
    }
    mats.clear();
}
 
Example #2
Source File: CVProcessor.java    From CVScanner with GNU General Public License v3.0 6 votes vote down vote up
static public Quadrilateral getQuadrilateral(List<MatOfPoint> contours, Size srcSize){
    double ratio = getScaleRatio(srcSize);
    int height = Double.valueOf(srcSize.height / ratio).intValue();
    int width = Double.valueOf(srcSize.width / ratio).intValue();
    Size size = new Size(width,height);

    for ( MatOfPoint c: contours ) {
        MatOfPoint2f c2f = new MatOfPoint2f(c.toArray());
        double peri = Imgproc.arcLength(c2f, true);
        MatOfPoint2f approx = new MatOfPoint2f();
        Imgproc.approxPolyDP(c2f, approx, 0.02 * peri, true);

        Point[] points = approx.toArray();
        Log.d("SCANNER", "approx size: " + points.length);

        // select biggest 4 angles polygon
        if (points.length == 4) {
            Point[] foundPoints = sortPoints(points);

            if (isInside(foundPoints, size) && isLargeEnough(foundPoints, size, 0.25)) {
                return new Quadrilateral( c , foundPoints );
            }
            else{
                //showToast(context, "Try getting closer to the ID");
                Log.d("SCANNER", "Not inside defined area");
            }
        }
    }

    //showToast(context, "Make sure the ID is on a contrasting background");
    return null;
}
 
Example #3
Source File: Converters.java    From MOAAP with MIT License 6 votes vote down vote up
public static void Mat_to_vector_vector_Point2f(Mat m, List<MatOfPoint2f> pts) {
    if (pts == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");

    if (m == null)
        throw new java.lang.IllegalArgumentException("Input Mat can't be null");

    List<Mat> mats = new ArrayList<Mat>(m.rows());
    Mat_to_vector_Mat(m, mats);
    for (Mat mi : mats) {
        MatOfPoint2f pt = new MatOfPoint2f(mi);
        pts.add(pt);
        mi.release();
    }
    mats.clear();
}
 
Example #4
Source File: Converters.java    From LPR with Apache License 2.0 6 votes vote down vote up
public static void Mat_to_vector_vector_Point2f(Mat m, List<MatOfPoint2f> pts) {
    if (pts == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");

    if (m == null)
        throw new java.lang.IllegalArgumentException("Input Mat can't be null");

    List<Mat> mats = new ArrayList<Mat>(m.rows());
    Mat_to_vector_Mat(m, mats);
    for (Mat mi : mats) {
        MatOfPoint2f pt = new MatOfPoint2f(mi);
        pts.add(pt);
        mi.release();
    }
    mats.clear();
}
 
Example #5
Source File: Calib3d.java    From OpenCvFaceDetect with Apache License 2.0 5 votes vote down vote up
public static Mat findFundamentalMat(MatOfPoint2f points1, MatOfPoint2f points2, int method, double ransacReprojThreshold, double confidence)
{
    Mat points1_mat = points1;
    Mat points2_mat = points2;
    Mat retVal = new Mat(findFundamentalMat_1(points1_mat.nativeObj, points2_mat.nativeObj, method, ransacReprojThreshold, confidence));
    
    return retVal;
}
 
Example #6
Source File: Calib3d.java    From FtcSamples with MIT License 5 votes vote down vote up
public static boolean solvePnPRansac(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat cameraMatrix, MatOfDouble distCoeffs, Mat rvec, Mat tvec)
{
    Mat objectPoints_mat = objectPoints;
    Mat imagePoints_mat = imagePoints;
    Mat distCoeffs_mat = distCoeffs;
    boolean retVal = solvePnPRansac_1(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, cameraMatrix.nativeObj, distCoeffs_mat.nativeObj, rvec.nativeObj, tvec.nativeObj);
    
    return retVal;
}
 
Example #7
Source File: Subdiv2D.java    From MOAAP with MIT License 5 votes vote down vote up
public  void insert(MatOfPoint2f ptvec)
{
    Mat ptvec_mat = ptvec;
    insert_1(nativeObj, ptvec_mat.nativeObj);
    
    return;
}
 
Example #8
Source File: Imgproc.java    From SmartPaperScan with Apache License 2.0 5 votes vote down vote up
public static RotatedRect minAreaRect(MatOfPoint2f points)
{
    Mat points_mat = points;
    RotatedRect retVal = new RotatedRect(minAreaRect_0(points_mat.nativeObj));
    
    return retVal;
}
 
Example #9
Source File: Imgproc.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static RotatedRect fitEllipse(MatOfPoint2f points)
{
    Mat points_mat = points;
    RotatedRect retVal = new RotatedRect(fitEllipse_0(points_mat.nativeObj));
    
    return retVal;
}
 
Example #10
Source File: Imgproc.java    From MOAAP with MIT License 5 votes vote down vote up
public static Mat getAffineTransform(MatOfPoint2f src, MatOfPoint2f dst)
{
    Mat src_mat = src;
    Mat dst_mat = dst;
    Mat retVal = new Mat(getAffineTransform_0(src_mat.nativeObj, dst_mat.nativeObj));
    
    return retVal;
}
 
Example #11
Source File: Calib3d.java    From OpenCV-Android-Object-Detection with MIT License 5 votes vote down vote up
public static boolean solvePnPRansac(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat cameraMatrix, MatOfDouble distCoeffs, Mat rvec, Mat tvec)
{
    Mat objectPoints_mat = objectPoints;
    Mat imagePoints_mat = imagePoints;
    Mat distCoeffs_mat = distCoeffs;
    boolean retVal = solvePnPRansac_1(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, cameraMatrix.nativeObj, distCoeffs_mat.nativeObj, rvec.nativeObj, tvec.nativeObj);
    
    return retVal;
}
 
Example #12
Source File: Calib3d.java    From real_time_circle_detection_android with MIT License 5 votes vote down vote up
public static void projectPoints(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat rvec, Mat tvec, Mat K, Mat D)
{
    Mat objectPoints_mat = objectPoints;
    Mat imagePoints_mat = imagePoints;
    projectPoints_3(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, rvec.nativeObj, tvec.nativeObj, K.nativeObj, D.nativeObj);
    
    return;
}
 
Example #13
Source File: Video.java    From MOAAP with MIT License 5 votes vote down vote up
public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err)
{
    Mat prevPts_mat = prevPts;
    Mat nextPts_mat = nextPts;
    Mat status_mat = status;
    Mat err_mat = err;
    calcOpticalFlowPyrLK_2(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj);
    
    return;
}
 
Example #14
Source File: Calib3d.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
public static boolean solvePnP(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat cameraMatrix, MatOfDouble distCoeffs, Mat rvec, Mat tvec)
{
    Mat objectPoints_mat = objectPoints;
    Mat imagePoints_mat = imagePoints;
    Mat distCoeffs_mat = distCoeffs;
    boolean retVal = solvePnP_1(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, cameraMatrix.nativeObj, distCoeffs_mat.nativeObj, rvec.nativeObj, tvec.nativeObj);
    
    return retVal;
}
 
Example #15
Source File: Calib3d.java    From MOAAP with MIT License 5 votes vote down vote up
public static boolean solvePnPRansac(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat cameraMatrix, MatOfDouble distCoeffs, Mat rvec, Mat tvec, boolean useExtrinsicGuess, int iterationsCount, float reprojectionError, double confidence, Mat inliers, int flags)
{
    Mat objectPoints_mat = objectPoints;
    Mat imagePoints_mat = imagePoints;
    Mat distCoeffs_mat = distCoeffs;
    boolean retVal = solvePnPRansac_0(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, cameraMatrix.nativeObj, distCoeffs_mat.nativeObj, rvec.nativeObj, tvec.nativeObj, useExtrinsicGuess, iterationsCount, reprojectionError, confidence, inliers.nativeObj, flags);
    
    return retVal;
}
 
Example #16
Source File: Calib3d.java    From OpenCvFaceDetect with Apache License 2.0 5 votes vote down vote up
public static Mat findFundamentalMat(MatOfPoint2f points1, MatOfPoint2f points2, int method, double ransacReprojThreshold)
{
    Mat points1_mat = points1;
    Mat points2_mat = points2;
    Mat retVal = new Mat(findFundamentalMat_2(points1_mat.nativeObj, points2_mat.nativeObj, method, ransacReprojThreshold));
    
    return retVal;
}
 
Example #17
Source File: Calib3d.java    From MOAAP with MIT License 5 votes vote down vote up
public static Mat initCameraMatrix2D(List<MatOfPoint3f> objectPoints, List<MatOfPoint2f> imagePoints, Size imageSize, double aspectRatio)
{
    List<Mat> objectPoints_tmplm = new ArrayList<Mat>((objectPoints != null) ? objectPoints.size() : 0);
    Mat objectPoints_mat = Converters.vector_vector_Point3f_to_Mat(objectPoints, objectPoints_tmplm);
    List<Mat> imagePoints_tmplm = new ArrayList<Mat>((imagePoints != null) ? imagePoints.size() : 0);
    Mat imagePoints_mat = Converters.vector_vector_Point2f_to_Mat(imagePoints, imagePoints_tmplm);
    Mat retVal = new Mat(initCameraMatrix2D_0(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, imageSize.width, imageSize.height, aspectRatio));
    
    return retVal;
}
 
Example #18
Source File: Video.java    From SmartPaperScan with Apache License 2.0 5 votes vote down vote up
public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel, TermCriteria criteria, int flags, double minEigThreshold)
{
    Mat prevPts_mat = prevPts;
    Mat nextPts_mat = nextPts;
    Mat status_mat = status;
    Mat err_mat = err;
    calcOpticalFlowPyrLK_0(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj, winSize.width, winSize.height, maxLevel, criteria.type, criteria.maxCount, criteria.epsilon, flags, minEigThreshold);
    
    return;
}
 
Example #19
Source File: Calib3d.java    From OpenCV-AndroidSamples with MIT License 5 votes vote down vote up
public static Mat initCameraMatrix2D(List<MatOfPoint3f> objectPoints, List<MatOfPoint2f> imagePoints, Size imageSize)
{
    List<Mat> objectPoints_tmplm = new ArrayList<Mat>((objectPoints != null) ? objectPoints.size() : 0);
    Mat objectPoints_mat = Converters.vector_vector_Point3f_to_Mat(objectPoints, objectPoints_tmplm);
    List<Mat> imagePoints_tmplm = new ArrayList<Mat>((imagePoints != null) ? imagePoints.size() : 0);
    Mat imagePoints_mat = Converters.vector_vector_Point2f_to_Mat(imagePoints, imagePoints_tmplm);
    Mat retVal = new Mat(initCameraMatrix2D_1(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, imageSize.width, imageSize.height));
    
    return retVal;
}
 
Example #20
Source File: Imgproc.java    From FTCVision with MIT License 5 votes vote down vote up
public static double arcLength(MatOfPoint2f curve, boolean closed)
{
    Mat curve_mat = curve;
    double retVal = arcLength_0(curve_mat.nativeObj, closed);
    
    return retVal;
}
 
Example #21
Source File: ContoursUtils.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * 寻找轮廓,并按照递增排序
 *
 * @param cannyMat
 * @return
 */
public static List<MatOfPoint> findContours(Mat cannyMat) {
	List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
	Mat hierarchy = new Mat();

	// 寻找轮廓
	Imgproc.findContours(cannyMat, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));

	if (contours.size() <= 0) {
		// throw new RuntimeException("未找到图像轮廓");
	} else {
		// 对contours进行了排序,按递增顺序
		contours.sort(new Comparator<MatOfPoint>() {
			@Override
			public int compare(MatOfPoint o1, MatOfPoint o2) {
				MatOfPoint2f mat1 = new MatOfPoint2f(o1.toArray());
				RotatedRect rect1 = Imgproc.minAreaRect(mat1);
				Rect r1 = rect1.boundingRect();

				MatOfPoint2f mat2 = new MatOfPoint2f(o2.toArray());
				RotatedRect rect2 = Imgproc.minAreaRect(mat2);
				Rect r2 = rect2.boundingRect();

				return (int) (r1.area() - r2.area());
			}
		});

	}
	return contours;
}
 
Example #22
Source File: Calib3d.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static void drawChessboardCorners(Mat image, Size patternSize, MatOfPoint2f corners, boolean patternWasFound)
{
    Mat corners_mat = corners;
    drawChessboardCorners_0(image.nativeObj, patternSize.width, patternSize.height, corners_mat.nativeObj, patternWasFound);
    
    return;
}
 
Example #23
Source File: Imgproc.java    From LicensePlateDiscern with MIT License 5 votes vote down vote up
public static void approxPolyDP(MatOfPoint2f curve, MatOfPoint2f approxCurve, double epsilon, boolean closed)
{
    Mat curve_mat = curve;
    Mat approxCurve_mat = approxCurve;
    approxPolyDP_0(curve_mat.nativeObj, approxCurve_mat.nativeObj, epsilon, closed);
    
    return;
}
 
Example #24
Source File: Subdiv2D.java    From real_time_circle_detection_android with MIT License 5 votes vote down vote up
public  void getVoronoiFacetList(MatOfInt idx, List<MatOfPoint2f> facetList, MatOfPoint2f facetCenters)
{
    Mat idx_mat = idx;
    Mat facetList_mat = new Mat();
    Mat facetCenters_mat = facetCenters;
    getVoronoiFacetList_0(nativeObj, idx_mat.nativeObj, facetList_mat.nativeObj, facetCenters_mat.nativeObj);
    Converters.Mat_to_vector_vector_Point2f(facetList_mat, facetList);
    facetList_mat.release();
    return;
}
 
Example #25
Source File: Imgproc.java    From MOAAP with MIT License 5 votes vote down vote up
public static void approxPolyDP(MatOfPoint2f curve, MatOfPoint2f approxCurve, double epsilon, boolean closed)
{
    Mat curve_mat = curve;
    Mat approxCurve_mat = approxCurve;
    approxPolyDP_0(curve_mat.nativeObj, approxCurve_mat.nativeObj, epsilon, closed);
    
    return;
}
 
Example #26
Source File: Imgproc.java    From FTCVision with MIT License 5 votes vote down vote up
public static RotatedRect fitEllipse(MatOfPoint2f points)
{
    Mat points_mat = points;
    RotatedRect retVal = new RotatedRect(fitEllipse_0(points_mat.nativeObj));
    
    return retVal;
}
 
Example #27
Source File: Calib3d.java    From MOAAP with MIT License 5 votes vote down vote up
public static Mat initCameraMatrix2D(List<MatOfPoint3f> objectPoints, List<MatOfPoint2f> imagePoints, Size imageSize)
{
    List<Mat> objectPoints_tmplm = new ArrayList<Mat>((objectPoints != null) ? objectPoints.size() : 0);
    Mat objectPoints_mat = Converters.vector_vector_Point3f_to_Mat(objectPoints, objectPoints_tmplm);
    List<Mat> imagePoints_tmplm = new ArrayList<Mat>((imagePoints != null) ? imagePoints.size() : 0);
    Mat imagePoints_mat = Converters.vector_vector_Point2f_to_Mat(imagePoints, imagePoints_tmplm);
    Mat retVal = new Mat(initCameraMatrix2D_1(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, imageSize.width, imageSize.height));
    
    return retVal;
}
 
Example #28
Source File: Imgproc.java    From SmartPaperScan with Apache License 2.0 5 votes vote down vote up
public static double pointPolygonTest(MatOfPoint2f contour, Point pt, boolean measureDist)
{
    Mat contour_mat = contour;
    double retVal = pointPolygonTest_0(contour_mat.nativeObj, pt.x, pt.y, measureDist);
    
    return retVal;
}
 
Example #29
Source File: Imgproc.java    From Image-Detection-Samples with Apache License 2.0 5 votes vote down vote up
public static double pointPolygonTest(MatOfPoint2f contour, Point pt, boolean measureDist)
{
    Mat contour_mat = contour;
    double retVal = pointPolygonTest_0(contour_mat.nativeObj, pt.x, pt.y, measureDist);
    
    return retVal;
}
 
Example #30
Source File: Imgproc.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static void approxPolyDP(MatOfPoint2f curve, MatOfPoint2f approxCurve, double epsilon, boolean closed)
{
    Mat curve_mat = curve;
    Mat approxCurve_mat = approxCurve;
    approxPolyDP_0(curve_mat.nativeObj, approxCurve_mat.nativeObj, epsilon, closed);
    
    return;
}