App crash when using solvePnP on Android

asked 2019-11-20 06:47:19 -0500

ARYL518 gravatar image

updated 2019-11-20 06:54:37 -0500

supra56 gravatar image

Hi, I use OpenCV on Andoid. I can use it for face detection. But when I use it for solvePnp, the app crash. The code looks as follows:

  Mat mCameraMatrix = new Mat(3, 3, CvType.CV_64FC1);
  //assign values to mCameraMatrix, not real calibration results

  mImagePoints = new MatOfPoint2f();

  List<Point> imgPoints = new ArrayList<Point>();
  imgPoints.add(new Point(mSpecificInferencePointArray[0], mSpecificInferencePointArray[1]));
  imgPoints.add(new Point(mSpecificInferencePointArray[2], mSpecificInferencePointArray[3]));
  imgPoints.add(new Point(mSpecificInferencePointArray[4], mSpecificInferencePointArray[5]));
  imgPoints.add(new Point(mSpecificInferencePointArray[6], mSpecificInferencePointArray[7]));
  imgPoints.add(new Point(mSpecificInferencePointArray[8], mSpecificInferencePointArray[9]));
  mImagePoints.fromList(imgPoints);

   mObjectPoints = new MatOfPoint3f();

   List<Point3> objPoints = new ArrayList<Point3>();
   objPoints.add(new Point3(-22.20, -66.559, -28.726));
   objPoints.add(new Point3(15.55, -68.66, -28.174));
   objPoints.add(new Point3(-5.97, -84.487, -64.864));
   objPoints.add(new Point3(-26.322, -50.606, -97.192));
   objPoints.add(new Point3(23.032, -48.908, -96.501));
   mObjectPoints.fromList(objPoints);

    Mat rvec = new Mat(3,1, CvType.CV_64FC1);
    Mat tvec = new Mat(3, 1, CvType.CV_64FC1);

    Calib3d.solvePnP(mObjectPoints, mImagePoints, mCameraMatrix, null, rvec, tvec);

When I call Calib3d.solvePnP, the App crash.

The 3D and 2D points do not have correspondence and the camera intrinsic parameters are not real. I set the value to fx, fy, cx and cy. But I think the App should not crash even given simulated inputs.

Any help is very appreciated.

Best,

YL

edit retag flag offensive close merge delete

Comments

It is hopeless to help you if don't - for starters - tell where exactly the code crashes. And when you run the code in debugger to find that out, you just may see in debegger's console a message from OpenCv that tells what is wrong

mvuori gravatar imagemvuori ( 2019-11-20 07:34:47 -0500 )edit

Thanks. I need at leas 6 points rather than 4.

ARYL518 gravatar imageARYL518 ( 2019-11-21 19:49:55 -0500 )edit