Closed mattycorbett closed 9 months ago
The error that occurs in the Converters.Mat_to_vector_double function can be resolved by modifying the code as follows
OpenCVForUnity.UtilsModule.Converters.Mat_to_vector_double(Rvec.reshape(1, 3), rvecList);
OpenCVForUnity.UtilsModule.Converters.Mat_to_vector_double(Tvec.reshape(1, 3), tvecList);
The simple code to convert rvec and tvec obtained by the Calib3d.solvePnP function to poseData is as follows.
// Convert to unity pose data.
double[] rvecArr = new double[3];
rvec.get(0, 0, rvecArr);
double[] tvecArr = new double[3];
tvec.get(0, 0, tvecArr);
PoseData poseData = ARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
var outQuat = poseData.rot;
This worked. Thank you
Unity 2022.2.19f1 OpenCVForUnity 2.5.4
I am trying to create a head post estimation from a MediaPipe face landmark list from the device's camera. After getting the landmarks, I use the code below to estimate the pose of the face
` var camera_matrix = new Mat(3, 3, CvType.CV_32F); var dist_coeffs = new MatOfDouble(1, 4, CvType.CV_32F); Mat Rvec = new Mat(); Mat Tvec = new Mat(); Mat rvec = new Mat(1, 3, CvType.CV_64FC1); Mat tvec = new Mat(1, 3, CvType.CV_64FC1);
However, when I run this code, I get the error "CvException: CvType.CV_64FC1 != m.type() || m.cols()!=1 Mat [ 13CV_64FC1, isCont=True, isSubmat=False, nativeObj=0x2131137118096, dataAddr=0x2131137119232 ] OpenCVForUnity.UtilsModule.Converters.Mat_to_vector_double (OpenCVForUnity.CoreModule.Mat m, System.Collections.Generic.List`1[T] ds) (at Assets/OpenCVForUnity/org/opencv/utils/Converters.cs:824) Mediapipe.Unity.CameraCapture.Update () (at Assets/Scripts/CameraCapture.cs:236)"
This happens at the var poseData = OpenCVForUnity.UnityUtils.ARUtils.ConvertRvecTvecToPoseData(rvecList, tvecList) line. When I try to use the Rvec and Tvec without conversion, and am told that it cant convert a Mat to a List<> and wont run. When I DO convert it, the List has 3 columns, and requires one. Has anyone done this? Where am I going wrong?