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


Java Calib3d类代码示例

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


Calib3d类属于org.opencv.calib3d包,在下文中一共展示了Calib3d类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: findCheckereboardPatterns

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
private void findCheckereboardPatterns() {
    cornersFromAllImages = new ArrayList<>();
    for (int i = 0; i < images.size(); i++) {
        corners = new MatOfPoint2f();
        boolean patternFound = Calib3d.findCheckerboardCorners(images.get(i),
                new Size(width, height), corners, Calib3d.CALIB_CB_FAST_CHECK);
        if (patternFound) {
            TermCriteria termCriteria = new TermCriteria(TermCriteria.COUNT + TermCriteria.EPS,
                    30, 0.1);
            Imgproc.cornerSubPix(images.get(i), corners, new Size(width, height),
                    new Size(-1, -1), termCriteria);
            cornersFromAllImages.add(corners);
            Log.d(TAG, "IMG_" + String.valueOf(i + 1) + " -> PATTERN FOUND");
        } else {
            rejectedImage++;
            Log.d(TAG, "IMG_" + String.valueOf(i + 1) + " -> PATTERN NOT FOUND");
        }
    }
}
 
开发者ID:PawelTypiak,项目名称:Checkerboard-IMU-Comparator,代码行数:20,代码来源:CheckerboardPatternComputingInitializer.java

示例3: calibrate

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
public void calibrate() {
    ArrayList<Mat> rvecs = new ArrayList<Mat>();
    ArrayList<Mat> tvecs = new ArrayList<Mat>();
    Mat reprojectionErrors = new Mat();
    ArrayList<Mat> objectPoints = new ArrayList<Mat>();
    objectPoints.add(Mat.zeros(mCornersSize, 1, CvType.CV_32FC3));
    calcBoardCornerPositions(objectPoints.get(0));
    for (int i = 1; i < mCornersBuffer.size(); i++) {
        objectPoints.add(objectPoints.get(0));
    }

    Calib3d.calibrateCamera(objectPoints, mCornersBuffer, mImageSize,
            mCameraMatrix, mDistortionCoefficients, rvecs, tvecs, mFlags);

    mIsCalibrated = Core.checkRange(mCameraMatrix)
            && Core.checkRange(mDistortionCoefficients);

    mRms = computeReprojectionErrors(objectPoints, rvecs, tvecs, reprojectionErrors);
    Log.i(TAG, String.format("Average re-projection error: %f", mRms));
    Log.i(TAG, "Camera matrix: " + mCameraMatrix.dump());
    Log.i(TAG, "Distortion coefficients: " + mDistortionCoefficients.dump());
}
 
开发者ID:xunqun,项目名称:OpenCV-AndroidSamples-master,代码行数:23,代码来源:CameraCalibrator.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:davrempe,项目名称:cardboardAR-lib,代码行数: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, 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

示例6: 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

示例7: calculateExtrinsics

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
/**
 * Calculate 3D position of the marker based on its translation and rotation matrix.
 * This method fills in these matrix properly.
 * @param camMatrix
 * @param distCoeffs
 * @param sizeMeters
 */
protected void calculateExtrinsics(Mat camMatrix, MatOfDouble distCoeffs, float sizeMeters){
	// TODO check params
	
	// set the obj 3D points
	double halfSize = sizeMeters/2.0;
	List<Point3> objPoints = new ArrayList<Point3>();
	objPoints.add(new Point3(-halfSize, -halfSize,0));
	objPoints.add(new Point3(-halfSize,  halfSize,0));
	objPoints.add(new Point3( halfSize,  halfSize,0));
	objPoints.add(new Point3( halfSize, -halfSize,0));

	MatOfPoint3f objPointsMat = new MatOfPoint3f();
	objPointsMat.fromList(objPoints);
	Calib3d.solvePnP(objPointsMat, this, camMatrix, distCoeffs, Rvec, Tvec);

	//Added to library
       Utils.alignToId(Rvec, this.getRotations());
}
 
开发者ID:jsmith613,项目名称:Aruco-Marker-Tracking-Android,代码行数:26,代码来源:Marker.java

示例8: 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

示例9: calibrationStep

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
public boolean calibrationStep() {
	Mat frame = getFrame();
	MatOfPoint2f pointBuf = new MatOfPoint2f();
	boolean found = Calib3d.findChessboardCorners(frame, _patternSize, pointBuf,
			Calib3d.CALIB_CB_ADAPTIVE_THRESH | Calib3d.CALIB_CB_NORMALIZE_IMAGE);
	
	if (found) {
		Mat viewGray = new Mat();
		Imgproc.cvtColor(frame, viewGray, Imgproc.COLOR_BGR2GRAY);
		Imgproc.cornerSubPix(viewGray, pointBuf, new Size(11, 11), new Size(-1, -1),
				new TermCriteria(TermCriteria.EPS | TermCriteria.MAX_ITER, 30, 0.1));
		
		_calibrationPoints.add(pointBuf);
	}
	frame.release();
	
	return found;
}
 
开发者ID:lumannnn,项目名称:AudioRacer,代码行数:19,代码来源:OpenCVCamera.java

示例10: runCalibration

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
private boolean runCalibration() {
	Mat frame = getFrame();
	
	Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64F);
	List<Mat> objectPoints = calcBoardCornerPositions();
	Mat distCoeffs = Mat.zeros(8, 1, CvType.CV_64F);
	List<Mat> rvecs = new LinkedList<>();
	List<Mat> tvecs = new LinkedList<>();
	
	Calib3d.calibrateCamera(objectPoints, _calibrationPoints, frame.size(), cameraMatrix,
			distCoeffs, rvecs, tvecs, Calib3d.CALIB_FIX_K4 | Calib3d.CALIB_FIX_K5);
	
	boolean ok = Core.checkRange(frame) && Core.checkRange(distCoeffs);
	
	if (ok) {
		_cameraMatrix = cameraMatrix;
		_distCoeefs = distCoeffs;
	}
	
	frame.release();
	
	return ok;
}
 
开发者ID:lumannnn,项目名称:AudioRacer,代码行数:24,代码来源:OpenCVCamera.java

示例11: getCameraImage

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
public BufferedImage getCameraImage() {
	Mat frame = _camera.getFrame();
	if (frame == null) {
		return null;
	} else {
		if (_drawCheesboard) {
			MatOfPoint2f corners = new MatOfPoint2f();
			if (Calib3d.findChessboardCorners(frame, _camera.getPatternSize(), corners,
					Calib3d.CALIB_CB_FAST_CHECK)) {
				Calib3d.drawChessboardCorners(frame, _camera.getPatternSize(), corners, true);
			}
		}
		
		BufferedImage img = matToBufferedImage(frame);
		frame.release();
		if (!_cameraImagePosCalculated) {
			refreshCameraImagePos(img.getWidth(), img.getHeight());
		}
		if (_selecting) {
			drawGameArea(img);
		}
		return img;
	}
}
 
开发者ID:lumannnn,项目名称:AudioRacer,代码行数:25,代码来源:CameraMapComponent.java

示例12: makeCalibrationOfPatterns

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
private void makeCalibrationOfPatterns() {
    cameraMatrix = new Mat();
    distCoeff = new Mat();
    rvecs = new ArrayList<>();
    tvecs = new ArrayList<>();
    Calib3d.calibrateCamera(cornersModelFromAllImages, cornersFromAllImages,
            images.get(0).size(), cameraMatrix, distCoeff, rvecs, tvecs);
}
 
开发者ID:PawelTypiak,项目名称:Checkerboard-IMU-Comparator,代码行数:9,代码来源:CheckerboardPatternComputingInitializer.java

示例13: findPattern

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
private boolean findPattern() {
    boolean isPatternFound = Calib3d.findCheckerboardCorners(IMAGE, new Size(width, height),
            cornerOfOneImage, Calib3d.CALIB_CB_FAST_CHECK);
    if (isPatternFound) {
        TermCriteria termCriteria = new TermCriteria(TermCriteria.COUNT + TermCriteria.EPS,
                30, 0.1);
        Imgproc.cornerSubPix(IMAGE, cornerOfOneImage, new Size(width, height),
                new Size(-1, -1), termCriteria);
        Log.d(TAG, "findPattern(picture, externalCorners) -> done - found checkerboard");
        return true;
    } else {
        Log.d(TAG, "findPattern(picture, externalCorners) -> done - no checkerboard detected");
        return false;
    }
}
 
开发者ID:PawelTypiak,项目名称:Checkerboard-IMU-Comparator,代码行数:16,代码来源:CheckerboardPatternComputingInitializer.java

示例14: CameraCalibrator

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
public CameraCalibrator(int width, int height) {
    mImageSize = new Size(width, height);
    mFlags = Calib3d.CALIB_FIX_PRINCIPAL_POINT +
            Calib3d.CALIB_ZERO_TANGENT_DIST +
            Calib3d.CALIB_FIX_ASPECT_RATIO +
            Calib3d.CALIB_FIX_K4 +
            Calib3d.CALIB_FIX_K5;
    Mat.eye(3, 3, CvType.CV_64FC1).copyTo(mCameraMatrix);
    mCameraMatrix.put(0, 0, 1.0);
    Mat.zeros(5, 1, CvType.CV_64FC1).copyTo(mDistortionCoefficients);
    Log.i(TAG, "Instantiated new " + this.getClass());
}
 
开发者ID:xunqun,项目名称:OpenCV-AndroidSamples-master,代码行数:13,代码来源:CameraCalibrator.java

示例15: calculateExtrinsics

import org.opencv.calib3d.Calib3d; //导入依赖的package包/类
/**
	 * Calculate 3D position of the marker based on its translation and rotation matrix.
	 * This method fills in these matrix properly.
	 * @param camMatrix
	 * @param distCoeff
	 */
	protected void calculateExtrinsics(Mat camMatrix, MatOfDouble distCoeffs, float sizeMeters){
		// TODO check params

		// set the obj 3D points
		double halfSize = sizeMeters/2.0;
		List<Point3> objPoints = new ArrayList<Point3>();
//		 old
		objPoints.add(new Point3(-halfSize, halfSize,0));
		objPoints.add(new Point3(-halfSize, -halfSize,0));
		objPoints.add(new Point3( halfSize,  -halfSize,0));
		objPoints.add(new Point3( halfSize, halfSize,0));

		// new
//		objPoints.add(new Point3(-halfSize, -halfSize,0));
//		objPoints.add(new Point3(-halfSize,  halfSize,0));
//		objPoints.add(new Point3( halfSize,  halfSize,0));
//		objPoints.add(new Point3( halfSize, -halfSize,0));

		MatOfPoint3f objPointsMat = new MatOfPoint3f();
		objPointsMat.fromList(objPoints);
		Calib3d.solvePnP(objPointsMat, this, camMatrix, distCoeffs, Rvec, Tvec);

		double [] t0 = Tvec.get(0, 0);
		double [] t1 = Tvec.get(1, 0);
		double [] t2 = Tvec.get(2, 0);
		double [] r0 = Rvec.get(0, 0);
		double [] r1 = Rvec.get(1, 0);
		double [] r2 = Rvec.get(2, 0);
//		Utils.rotateXAxis(Rvec);

		Utils.alignToId(Rvec, this.getRotations());
	}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:39,代码来源:Marker.java


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