Closed mattycorbett closed 9 months ago
It is unlikely that the OpenCV solvePnP function is broken. First, create a minimal test that processes the exact same values (object_points, image_points...) and compare the results between python and Unity. Also, the Asset "DlibFaceLandmarkDetector" that we sell comes with a sample scene that uses the solvePnP function to estimate head angles from facial landmarks. The code is publicly available and may be helpful in solving the problem. https://github.com/EnoxSoftware/DlibFaceLandmarkDetector/blob/master/Assets/DlibFaceLandmark DetectorWithOpenCVExample/ARHeadExample/ARHeadWebCamTextureExample.cs
Extremely helpful. Thank you!
Using the code below, I am trying to use the output Face Landmarks from Google's MediaPipe to estimate head pose. I am using OpenCV's solvePnP. The code compiles and runs, but the output rotation Quaternions are 90% zeros, with the odd rotation values that are never the same and always inaccurate. There is jitter in the landmarks, but they are normally about a pixel, so I do not believe the error is with the MediaPipe results. I believe the error is with the solvePnP implementation. I am truly at a loss, as even with the jitter, I wouldn't expect Quaternions of zero or so much deviation in the results.
Also, I have tested the example code here in python and it works like a charm. Im using the same landmarks, functions, and conversions. Any ideas?
`Mat rvec = new Mat(1, 3, CvType.CV_64FC1); Mat tvec = new Mat(1, 3, CvType.CV_64FC1); Mat rmat = new Mat(3, 3, CvType.CV_64FC1); //camera_matrix.put(0, 0, 800, 0, 400, 0, 600, 300, 0, 0, 1); camera_matrix.put(0, 0, new double[] { 800, 0, 400, 0, 600, 300, 0, 0, 1.0f });
An example of the output angles are below