當前位置: 首頁>>代碼示例>>Java>>正文


Java MatOfPoint2f.fromList方法代碼示例

本文整理匯總了Java中org.opencv.core.MatOfPoint2f.fromList方法的典型用法代碼示例。如果您正苦於以下問題:Java MatOfPoint2f.fromList方法的具體用法?Java MatOfPoint2f.fromList怎麽用?Java MatOfPoint2f.fromList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.core.MatOfPoint2f的用法示例。


在下文中一共展示了MatOfPoint2f.fromList方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: detectContoursByShape

import org.opencv.core.MatOfPoint2f; //導入方法依賴的package包/類
/**
 * Filters contours by shape. Iterates through the list of contours and approximates their shape. 
 * Compares the vertices of the shape to the desired vertices and removes the contour if they do not match.
 * 
 * @param contours list of contours
 * @param vertices vertices of the desired shape
 * @param accuracy the accuracy of approximation
 * @see Imgproc#approxPolyDP(MatOfPoint2f, MatOfPoint2f, double, boolean)
 */
public static void detectContoursByShape(List<MatOfPoint> contours, int vertices, double accuracy){
	MatOfPoint2f matOfPoint2f = new MatOfPoint2f();
	MatOfPoint2f approxCurve = new MatOfPoint2f();
	
	for(int idx = contours.size() - 1; idx >= 0; idx--){
		MatOfPoint contour = contours.get(idx);
	   
	    matOfPoint2f.fromList(contour.toList());
	    Imgproc.approxPolyDP(matOfPoint2f, approxCurve, Imgproc.arcLength(matOfPoint2f, true) * accuracy, true);
	    long total = approxCurve.total();
	    
	    if (total != vertices)
	    	contours.remove(idx);
	}
}
 
開發者ID:Flash3388,項目名稱:FlashLib,代碼行數:25,代碼來源:CvProcessing.java

示例2: drawObjectLocation

import org.opencv.core.MatOfPoint2f; //導入方法依賴的package包/類
/**
 * Draw the object's location
 *
 * @param output         Image to draw on
 * @param objectAnalysis Object analysis information
 * @param sceneAnalysis  Scene analysis information
 */
public static void drawObjectLocation(Mat output, ObjectAnalysis objectAnalysis, SceneAnalysis sceneAnalysis) {
    List<Point> ptsObject = new ArrayList<>();
    List<Point> ptsScene = new ArrayList<>();

    KeyPoint[] keypointsObject = objectAnalysis.keypoints.toArray();
    KeyPoint[] keypointsScene = sceneAnalysis.keypoints.toArray();

    DMatch[] matches = sceneAnalysis.matches.toArray();

    for (DMatch matche : matches) {
        //Get the keypoints from these matches
        ptsObject.add(keypointsObject[matche.queryIdx].pt);
        ptsScene.add(keypointsScene[matche.trainIdx].pt);
    }

    MatOfPoint2f matObject = new MatOfPoint2f();
    matObject.fromList(ptsObject);

    MatOfPoint2f matScene = new MatOfPoint2f();
    matScene.fromList(ptsScene);

    //Calculate homography of object in scene
    Mat homography = Calib3d.findHomography(matObject, matScene, Calib3d.RANSAC, 5.0f);

    //Create the unscaled array of corners, representing the object size
    Point cornersObject[] = new Point[4];
    cornersObject[0] = new Point(0, 0);
    cornersObject[1] = new Point(objectAnalysis.object.cols(), 0);
    cornersObject[2] = new Point(objectAnalysis.object.cols(), objectAnalysis.object.rows());
    cornersObject[3] = new Point(0, objectAnalysis.object.rows());

    Point[] cornersSceneTemp = new Point[0];

    MatOfPoint2f cornersSceneMatrix = new MatOfPoint2f(cornersSceneTemp);
    MatOfPoint2f cornersObjectMatrix = new MatOfPoint2f(cornersObject);

    //Transform the object coordinates to the scene coordinates by the homography matrix
    Core.perspectiveTransform(cornersObjectMatrix, cornersSceneMatrix, homography);

    //Mat transform = Imgproc.getAffineTransform(cornersObjectMatrix, cornersSceneMatrix);

    //Draw the lines of the object on the scene
    Point[] cornersScene = cornersSceneMatrix.toArray();
    final ColorRGBA lineColor = new ColorRGBA("#00ff00");
    Drawing.drawLine(output, new Point(cornersScene[0].x + objectAnalysis.object.cols(), cornersScene[0].y),
            new Point(cornersScene[1].x + objectAnalysis.object.cols(), cornersScene[1].y), lineColor, 5);
    Drawing.drawLine(output, new Point(cornersScene[1].x + objectAnalysis.object.cols(), cornersScene[1].y),
            new Point(cornersScene[2].x + objectAnalysis.object.cols(), cornersScene[2].y), lineColor, 5);
    Drawing.drawLine(output, new Point(cornersScene[2].x + objectAnalysis.object.cols(), cornersScene[2].y),
            new Point(cornersScene[3].x + objectAnalysis.object.cols(), cornersScene[3].y), lineColor, 5);
    Drawing.drawLine(output, new Point(cornersScene[3].x + objectAnalysis.object.cols(), cornersScene[3].y),
            new Point(cornersScene[0].x + objectAnalysis.object.cols(), cornersScene[0].y), lineColor, 5);
}
 
開發者ID:ykarim,項目名稱:FTC2016,代碼行數:61,代碼來源:ObjectDetection.java


注:本文中的org.opencv.core.MatOfPoint2f.fromList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。