StevenBanama / C3AE

C3AE implement
BSD 2-Clause "Simplified" License
86 stars 16 forks source link

About function get_rotation_angle #25

Closed YanzuoLu closed 3 years ago

YanzuoLu commented 3 years ago

Hello, @StevenBanama . When I'm trying to preprocess some new dataset, I met some problems about function get_rotation_angle where giving out assertion error on cv2.solvePnP. I check cv2 document about cv2.solvePnP and find something as follows.

If you are using Python:

I think that adding landmarks = np.ascontiguousarray(landmarks.reshape((landmarks.shape[0], 1, landmarks.shape[1]))) after landmarks would be helpful.

YanzuoLu commented 3 years ago

Hello, @StevenBanama . When I'm trying to preprocess some new dataset, I met some problems about function get_rotation_angle where giving out assertion error on cv2.solvePnP. I check cv2 document about cv2.solvePnP and find something as follows.

If you are using Python:

  • Numpy array slices won't work as input because solvePnP requires contiguous arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of modules/calib3d/src/solvepnp.cpp version 2.4.9)
  • The P3P algorithm requires image points to be in an array of shape (N,1,2) due to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) which requires 2-channel information.
  • Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = np.ascontiguousarray(D[:,:2]).reshape((N,1,2))

I think that adding landmarks = np.ascontiguousarray(landmarks.reshape((landmarks.shape[0], 1, landmarks.shape[1]))) after landmarks would be helpful.

BTW, I have tried this method and successfully run the code. Thank you for your implementation!

StevenBanama commented 3 years ago

sorry, lately reply. "np.ascontiguousarray() or np.copy()" may meet your demands. Meanwhile you can proccess you dataset with landmarks when you garante it without side-face.