当前位置: 首页>>代码示例>>Java>>正文


Java Calib3d.projectPoints方法代码示例

本文整理汇总了Java中org.opencv.calib3d.Calib3d.projectPoints方法的典型用法代码示例。如果您正苦于以下问题:Java Calib3d.projectPoints方法的具体用法?Java Calib3d.projectPoints怎么用?Java Calib3d.projectPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.calib3d.Calib3d的用法示例。


在下文中一共展示了Calib3d.projectPoints方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeReprojectionErrors

import org.opencv.calib3d.Calib3d; //导入方法依赖的package包/类
private double computeReprojectionErrors(List<Mat> objectPoints,
                                         List<Mat> rvecs, List<Mat> tvecs, Mat perViewErrors) {
    MatOfPoint2f cornersProjected = new MatOfPoint2f();
    double totalError = 0;
    double error;
    float viewErrors[] = new float[objectPoints.size()];

    MatOfDouble distortionCoefficients = new MatOfDouble(mDistortionCoefficients);
    int totalPoints = 0;
    for (int i = 0; i < objectPoints.size(); i++) {
        MatOfPoint3f points = new MatOfPoint3f(objectPoints.get(i));
        Calib3d.projectPoints(points, rvecs.get(i), tvecs.get(i),
                mCameraMatrix, distortionCoefficients, cornersProjected);
        error = Core.norm(mCornersBuffer.get(i), cornersProjected, Core.NORM_L2);

        int n = objectPoints.get(i).rows();
        viewErrors[i] = (float) Math.sqrt(error * error / n);
        totalError  += error * error;
        totalPoints += n;
    }
    perViewErrors.create(objectPoints.size(), 1, CvType.CV_32FC1);
    perViewErrors.put(0, 0, viewErrors);

    return Math.sqrt(totalError / totalPoints);
}
 
开发者ID:xunqun,项目名称:OpenCV-AndroidSamples-master,代码行数:26,代码来源:CameraCalibrator.java

示例2: draw3dCube

import org.opencv.calib3d.Calib3d; //导入方法依赖的package包/类
public void draw3dCube(Mat frame, CameraParameters cp, Scalar color){
	MatOfPoint3f objectPoints = new MatOfPoint3f();
	double halfSize = ssize/2.0;
	Vector<Point3> points = new Vector<Point3>();
	points.add(new Point3(-halfSize, -halfSize, 0));
	points.add(new Point3(-halfSize,  halfSize, 0));
	points.add(new Point3( halfSize,  halfSize, 0));
	points.add(new Point3( halfSize, -halfSize, 0));
	points.add(new Point3(-halfSize, -halfSize, ssize));
	points.add(new Point3(-halfSize,  halfSize, ssize));
	points.add(new Point3( halfSize,  halfSize, ssize));
	points.add(new Point3( halfSize, -halfSize, ssize));
	objectPoints.fromList(points);
	MatOfPoint2f imagePoints = new MatOfPoint2f();
	Calib3d.projectPoints(objectPoints, Rvec, Tvec, cp.getCameraMatrix(), cp.getDistCoeff(), imagePoints);

	List<Point> pts = new Vector<Point>();
	pts = imagePoints.toList();
	// draw
	for (int i=0;i<4;i++){
		Core.line(frame ,pts.get(i),pts.get((i+1)%4), color, 2);
		Core.line(frame,pts.get(i+4),pts.get(4+(i+1)%4), color, 2);
		Core.line(frame,pts.get(i),pts.get(i+4), color, 2);
	}
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:26,代码来源:Marker.java

示例3: draw3dAxis

import org.opencv.calib3d.Calib3d; //导入方法依赖的package包/类
public static void draw3dAxis(Mat frame, CameraParameters cp, Scalar color, double height, Mat Rvec, Mat Tvec){
//		Mat objectPoints = new Mat(4,3,CvType.CV_32FC1);
		MatOfPoint3f objectPoints = new MatOfPoint3f();
		Vector<Point3> points = new Vector<Point3>();
		points.add(new Point3(0,     0,     0));
		points.add(new Point3(height,0,     0));
		points.add(new Point3(0,     height,0));
		points.add(new Point3(0,     0,     height)); 
		objectPoints.fromList(points);
		
		MatOfPoint2f imagePoints = new MatOfPoint2f();
		Calib3d.projectPoints( objectPoints, Rvec, Tvec,
				cp.getCameraMatrix(), cp.getDistCoeff(), imagePoints);
		List<Point> pts = new Vector<Point>();
		Converters.Mat_to_vector_Point(imagePoints, pts);
		
		Core.line(frame ,pts.get(0),pts.get(1), color, 2);
		Core.line(frame ,pts.get(0),pts.get(2), color, 2);
		Core.line(frame ,pts.get(0),pts.get(3), color, 2);

		Core.putText(frame, "X", pts.get(1), Core.FONT_HERSHEY_SIMPLEX, 0.5,  color,2);
		Core.putText(frame, "Y", pts.get(2), Core.FONT_HERSHEY_SIMPLEX, 0.5,  color,2);
		Core.putText(frame, "Z", pts.get(3), Core.FONT_HERSHEY_SIMPLEX, 0.5,  color,2);
	}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:25,代码来源:Utils.java

示例4: draw3dCube

import org.opencv.calib3d.Calib3d; //导入方法依赖的package包/类
public void draw3dCube(Mat frame, CameraParameters cp, Scalar color){
	MatOfPoint3f objectPoints = new MatOfPoint3f();
	double halfSize = ssize/2.0;
	Vector<Point3> points = new Vector<Point3>();
	points.add(new Point3(-halfSize, -halfSize, 0));
	points.add(new Point3(-halfSize,  halfSize, 0));
	points.add(new Point3( halfSize,  halfSize, 0));
	points.add(new Point3( halfSize, -halfSize, 0));
	points.add(new Point3(-halfSize, -halfSize, ssize));
	points.add(new Point3(-halfSize,  halfSize, ssize));
	points.add(new Point3( halfSize,  halfSize, ssize));
	points.add(new Point3( halfSize, -halfSize, ssize));
	objectPoints.fromList(points);
	MatOfPoint2f imagePoints = new MatOfPoint2f();
	Calib3d.projectPoints(objectPoints, Rvec, Tvec, cp.getCameraMatrix(), cp.getDistCoeff(), imagePoints);
	
	List<Point> pts = new Vector<Point>();
	pts = imagePoints.toList();
	// draw
    for (int i=0;i<4;i++){
           Core.line(frame ,pts.get(i),pts.get((i+1)%4), color, 2);
		Core.line(frame,pts.get(i+4),pts.get(4+(i+1)%4), color, 2);
		Core.line(frame,pts.get(i),pts.get(i+4), color, 2);
    }	        
}
 
开发者ID:jsmith613,项目名称:Aruco-Marker-Tracking-Android,代码行数:26,代码来源:Marker.java

示例5: draw3dAxis

import org.opencv.calib3d.Calib3d; //导入方法依赖的package包/类
public static void draw3dAxis(Mat frame, CameraParameters cp, Scalar color, double height, Mat Rvec, Mat Tvec){
//		Mat objectPoints = new Mat(4,3,CvType.CV_32FC1);;
		MatOfPoint3f objectPoints = new MatOfPoint3f();
		Vector<Point3> points = new Vector<Point3>();
		points.add(new Point3(0,     0,     0));
		points.add(new Point3(height,0,     0));
		points.add(new Point3(0,     height,0));
		points.add(new Point3(0,     0,     height)); 
		objectPoints.fromList(points);

		MatOfPoint2f imagePoints = new MatOfPoint2f();
		Calib3d.projectPoints(objectPoints, Rvec, Tvec,
				cp.getCameraMatrix(), cp.getDistCoeff(), imagePoints);
		List<Point> pts = new Vector<Point>();
		Converters.Mat_to_vector_Point(imagePoints, pts);

		Core.line(frame ,pts.get(0),pts.get(1), color, 2);
		Core.line(frame ,pts.get(0),pts.get(2), color, 2);
		Core.line(frame ,pts.get(0),pts.get(3), color, 2);

		Core.putText(frame, "X", pts.get(1), Core.FONT_HERSHEY_SIMPLEX, 2.0,  color,2);
		Core.putText(frame, "Y", pts.get(2), Core.FONT_HERSHEY_SIMPLEX, 2.0,  color,2);
		Core.putText(frame, "Z", pts.get(3), Core.FONT_HERSHEY_SIMPLEX, 2.0,  color,2);
	}
 
开发者ID:jsmith613,项目名称:Aruco-Marker-Tracking-Android,代码行数:25,代码来源:Utils.java

示例6: onCameraFrame

import org.opencv.calib3d.Calib3d; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    //Convert input to rgba
    Mat rgba = inputFrame.rgba();

    //Setup required parameters for detect method
    MarkerDetector mDetector = new MarkerDetector();
    Vector<Marker> detectedMarkers = new Vector<>();
    CameraParameters camParams = new CameraParameters();
    camParams.readFromFile(Environment.getExternalStorageDirectory().toString() + DATA_FILEPATH);

    //Populate detectedMarkers
    mDetector.detect(rgba, detectedMarkers, camParams, MARKER_SIZE);

    //Draw Axis for each marker detected
    if (detectedMarkers.size() != 0) {
        for (int i = 0; i < detectedMarkers.size(); i++) {
            Marker marker = detectedMarkers.get(i);
            detectedMarkers.get(i).draw3dAxis(rgba, camParams, new Scalar(0,0,0));

            if (SHOW_MARKERID) {
                //Setup
                int idValue = detectedMarkers.get(i).getMarkerId();
                Vector<Point3> points = new Vector<>();
                points.add(new Point3(0, 0, 0));
                MatOfPoint3f pointMat = new MatOfPoint3f();
                pointMat.fromList(points);
                MatOfPoint2f outputPoints = new MatOfPoint2f();

                //Project point to marker origin
                Calib3d.projectPoints(pointMat, marker.getRvec(), marker.getTvec(), camParams.getCameraMatrix(), camParams.getDistCoeff(), outputPoints);
                List<Point> pts = new Vector<>();
                pts = outputPoints.toList();

                //Draw id number
                Core.putText(rgba, Integer.toString(idValue), pts.get(0), Core.FONT_HERSHEY_SIMPLEX, 2, new Scalar(0,0,1));
            }
        }
    }

    return rgba;
}
 
开发者ID:jsmith613,项目名称:Aruco-Marker-Tracking-Android,代码行数:42,代码来源:MarkerTracker.java


注:本文中的org.opencv.calib3d.Calib3d.projectPoints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。