Ask Your Question
1

OpenCV4Android Camera Calibration sample error

asked 2016-03-07 06:05:45 -0600

andreivan gravatar image

I tried to run the Camera Calibration sample code from OpenCV4Android 3.0.0, Im using android studio. When I run the apps on my android devices the sample code can detect asymetric circle grid pattern and I take 10-20 captures from it. When I try to calibrate the captured pictures the application will exit and show Unfortunately "apps name" has stopped.

Logcat

> 03-07 20:54:55.420 17202-17713/org.opencv.samples.cameracalibration E/cv::error(): OpenCV Error: Assertion failed (_tvec.total() * _tvec.channels() == 3 && (_tvec.depth() == CV_32F || _tvec.depth() == CV_64F)) in void cv::fisheye::projectPoints(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray, double, cv::OutputArray), file /home/maksim/workspace/android-pack/opencv/modules/calib3d/src/fisheye.cpp, line 77
03-07 20:54:55.420 17202-17713/org.opencv.samples.cameracalibration E/org.opencv.calib3d: calib3d::projectPoints_11() caught cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/calib3d/src/fisheye.cpp:77: error: (-215) _tvec.total() * _tvec.channels() == 3 && (_tvec.depth() == CV_32F || _tvec.depth() == CV_64F) in function void cv::fisheye::projectPoints(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray, double, cv::OutputArray)
03-07 20:54:55.420 17202-17713/org.opencv.samples.cameracalibration W/dalvikvm: threadid=13: thread exiting with uncaught exception (group=0x4197ee48)
edit retag flag offensive close merge delete

Comments

Hi! Did you solve this problem? I got the same error in versions 3.0.0 and 3.10

athenais gravatar imageathenais ( 2016-11-11 15:24:12 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-12-25 22:35:38 -0600

Hi

I solved this problem. In fisheye.cpp, I saw that function

void cv::fisheye::projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray _rvec, InputArray _tvec, InputArray _K, InputArray _D, double alpha = 0, OutputArray jacobian = Mat())

But in interface Calib3d.java, the function is

public static void projectPoints(MatOfPoint3f objectPoints, Mat rvec, Mat tvec, Mat cameraMatrix, MatOfDouble distCoeffs, MatOfPoint2f imagePoints)

The params of implement and interface are not matched. You can solve it by changing position of param in interface as below. In function public static void projectPoints(MatOfPoint3f objectPoints, Mat rvec, Mat tvec, Mat cameraMatrix, MatOfDouble distCoeffs, MatOfPoint2f imagePoints) { Mat objectPoints_mat = objectPoints; Mat distCoeffs_mat = distCoeffs; Mat imagePoints_mat = imagePoints; projectPoints_1(objectPoints_mat.nativeObj, rvec.nativeObj, tvec.nativeObj, cameraMatrix.nativeObj, distCoeffs_mat.nativeObj, imagePoints_mat.nativeObj); return; }

We move position of imagePoints_mat.nativeObj to index 2 of projectPoints_1() call projectPoints_1(objectPoints_mat.nativeObj, imagePoints_mat.nativeObj, rvec.nativeObj, tvec.nativeObj, cameraMatrix.nativeObj, distCoeffs_mat.nativeObj)

And your problem is solved.

edit flag offensive delete link more
0

answered 2017-11-14 03:29:23 -0600

The answer above doesn't solve the problem. The problem is, the wrong functions is called. It should be cv::projectPoints, but it is cv::fisheye::projectPoints instead (they have the same name but different interfaces). The error occurs in the first place, because arguments pass the interface, but fail checking their size inside the function. If you change their positions according to the answer above, you'll just make it correct for the wrong function. And there still will be an error, this time because fisheye projectPoints require four distortion coefficients and from the standard camera calibration you got five.

The solution that works for me is, because projectPoints_1 should call cv::projectPoints, but calls cv::fisheye::projectPoints instead, what about projectPoints_3, which should call the latter? And indeed, they seem to be switched, and projectPoints_3 calls cv::projectPoints. If you change projectPoints_1 in your code to projectPoints_3 it works as it should.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-03-07 06:05:45 -0600

Seen: 711 times

Last updated: Mar 07 '16