Error : java.lang.UnsatisfiedLinkError with Charuco Camera Calibration (DetectorParameters)

huangapple go评论88阅读模式
英文:

Error : java.lang.UnsatisfiedLinkError with Charuco Camera Calibration (DetectorParameters)

问题

抱歉,我无法识别代码中的特定错误。如果你需要帮助解决代码错误,请提供更多上下文信息,以便我可以尝试提供更准确的建议。

英文:

Good morning everyone. I am currently working on a project in which I have to detect object coordinates within an image with high precision. I have tried using a normal chessboard for camera calibration but the reprojection error was too high so I decided to use the Charuco calibration pattern. I am working with OpenCv 3.4 and Java (project constraint). Since the Aruco function are not included in OpenCv for Java I created a new package in my project which includes the necessary classes. The Aruco code is the one that you can find in the following link :
Aruco Code Github

The code that I'm executing is the following:

protected void captureImagesCharuco() {
	int squaresX = 5;
	int squaresY = 7;
	float squareLength = (float) 37.0;
	float markerLength = (float) 22.0;
	int calibrationFlags = 0;
	float aspectRatio = 1;
	DetectorParameters detectParams = DetectorParameters.create();
	detectParams.set_adaptiveThreshWinSizeMin(3);
	detectParams.set_adaptiveThreshWinSizeMax(23);
	detectParams.set_adaptiveThreshWinSizeStep(10);
	detectParams.set_adaptiveThreshConstant(7);
	detectParams.set_minMarkerPerimeterRate(0.03);
	detectParams.set_maxMarkerPerimeterRate(4.0);
	detectParams.set_polygonalApproxAccuracyRate(0.05);
	detectParams.set_minCornerDistanceRate(10);
	detectParams.set_minDistanceToBorder(3);
	detectParams.set_minMarkerDistanceRate(0.05);
	detectParams.set_cornerRefinementWinSize(5);
	detectParams.set_cornerRefinementMaxIterations(30);
	detectParams.set_cornerRefinementMinAccuracy(0.1);
	detectParams.set_markerBorderBits(1);
	detectParams.set_perspectiveRemovePixelPerCell(8);
	detectParams.set_perspectiveRemoveIgnoredMarginPerCell(0.13);
	detectParams.set_maxErroneousBitsInBorderRate(0.04);
	detectParams.set_minOtsuStdDev(5.0);
	detectParams.set_errorCorrectionRate(0.6);
	Dictionary dictionary = Aruco.getPredefinedDictionary(0);
	CharucoBoard charucoBoard = CharucoBoard.create(squaresX, squaresY, squareLength, markerLength, dictionary);
	List<List<Mat>> charucoCorners = new ArrayList<>();
	List<Mat> charucoIds = new ArrayList<>();
	List<Mat> validImgs = new ArrayList<>();
	Size imgSize = new Size();
	int nFrame = 0;
	
	File[] listImages = imageDirectory.listFiles();
	for(File file : listImages) {
		String src = file.getAbsolutePath();
		Mat imgRead = Imgcodecs.imread(src,Imgcodecs.IMREAD_COLOR);
		imgSize = imgRead.size();
		Mat imgCopy = new Mat();
		Mat ids = new Mat();
		List<Mat> rejectedCorners = new ArrayList<>();
		List<Mat> corners = new ArrayList<>();
		if (!imgRead.empty()){ 
			Aruco.detectMarkers(imgRead, dictionary, corners, ids);
			Aruco.refineDetectedMarkers(imgRead, (Board)charucoBoard, corners, ids, rejectedCorners);
			Mat currentCharucoCorners = new Mat();
			Mat currentCharucoIds = new Mat();
			int idsSize = ids.rows()*ids.cols();
			if(idsSize>0) {
				Aruco.interpolateCornersCharuco(corners, ids, imgRead, charucoBoard, currentCharucoCorners, currentCharucoIds);
			}
			imgRead.copyTo(imgCopy);
			if(idsSize<0) {
				Aruco.drawDetectedCornersCharuco(imgCopy, currentCharucoCorners);
			}
			if(currentCharucoCorners.total()>0) {
				Aruco.drawDetectedCornersCharuco(imgCopy, currentCharucoCorners, currentCharucoIds, new Scalar(255,0,0));
			}
			charucoCorners.add(corners);
			charucoIds.add(currentCharucoIds);
			validImgs.add(imgRead);
			nFrame++;
		}
		
	}
	
	intrinsic.put(0, 0, 1);
	intrinsic.put(1, 1, 1);
	List<Mat> allCharucoCorners = new ArrayList<>();
	List<Mat> allCharucoIds = new ArrayList<>();
	for(int i =0;i<nFrame;i++) {
		Mat currentCharucoCorners = new Mat();
		Mat currentCharucoIds = new Mat();
		Aruco.interpolateCornersCharuco(charucoCorners.get(i), charucoIds.get(i), validImgs.get(i), charucoBoard, currentCharucoCorners, currentCharucoIds,intrinsic,distCoeffs,4);
		allCharucoCorners.add(currentCharucoCorners);
		allCharucoIds.add(currentCharucoIds);
	}
	double repError = Aruco.calibrateCameraCharuco(allCharucoCorners, charucoIds, charucoBoard, imgSize, intrinsic, distCoeffsCharuco, rvecs, tvecs, calibrationFlags);
	System.out.println("reprojection error : " + repError);
}

I then simply execute the captureImagesCharuco() in the main program. However when I do so I get the following error :

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.UnsatisfiedLinkError: application.DetectorParameters.create_0()J
at application.DetectorParameters.create_0(Native Method)
at application.DetectorParameters.create(DetectorParameters.java:24)
at application.CameraCalibrate.captureImagesCharuco(CameraCalibrate.java:115)
at application.Main.main(Main.java:64)
... 11 more
Exception running application application.Main

I have tried searching for how to solve this error (UnsatisfiedLinkError) and I found that it is usually caused when you're using a library that isn't included in the Build Path or the project (Even though I ma not sure). I guess the library in question here is the Aruco package but I don't know how I can include a package in the build path of the project.

Any kind of help will be more than welcome ! Thank you ! Error : java.lang.UnsatisfiedLinkError with Charuco Camera Calibration (DetectorParameters)

答案1

得分: 1

错误表明您已安装了OpenCV包,但没有使用的特殊模块;

为了解决这个问题,您需要找到一个带有您所需模块的预构建OpenCV(在您的情况下,它位于contrib库中,所以这里可能会有帮助。

如果您想从源代码构建它 - 您应该在CMake属性中启用您需要的模块。对于contrib - 您需要首先使用CMake构建contrib项目,然后在主OpenCV makefile中启用contrib。有关构建OpenCV和contrib的详细信息 - 请参考官方文档。

英文:

The error indicates that you have opencv package without special module you're using;

In order to fix that you'd need to either find a prebuilt opencv with module you need (in your exactly case it's lcoated in contrib library, so this probably helps.

In case you want to build it from sources - you should enable the module you want in cmake properties. For contrib - you'd need to cmake contrib project first & then enable contrib in main opencv makefile. For building opencv & contirb - please follow official documentation.

huangapple
  • 本文由 发表于 2020年7月22日 18:03:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/63031705.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定