Ask Your Question

Revision history [back]

SolvePNP_P3P doesn't work for 4 points. Please help.

Hello, I'm using the solvePnP() function to get the extrinsics for a camera. I'm calibrating wrt the ground. I have taken 4 points on the ground. I tried to use the solvePnP_P3P flag because I was using exactly 4 points but I get an error when I run the function.

System details: Windows 10. OpenCV 4.1

Code snippet: import numpy as np from numpy.linalg import inv import cv2 import sys

with open('./calib/calibration.yaml') as f:

loadeddict = yaml.load(f)

camera_matrix = loadeddict.get('camera_matrix')

dist_coeffs = loadeddict.get('dist_coeff')

camera_matrix = [[1029.61564, 0.00000000, 916.314412], [0.00000000 ,1026.37518 ,526.909999], [0.00000000, 0.00000000, 1.00000000]]

dist_coeffs = [[-0.3725, 0.21018, -0.001127, 0.00013219, -0.09244]]

tnsPoints = [(0.0, 1.0, 0.0), (3.0, 1.0, 0.0), (2.0, 6.0, 0.0), (0.0, 6.0, 0.0)]

tnsPoints = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)]

imPoints = [(809, 915), (1181, 893), (1020, 362), (811, 372)]

retval, rvec, tvec = cv2.solvePnP(np.array(tnsPoints),np.array(imPoints),np.asarray(camera_matrix),np.asarray(dist_coeffs), flags=cv2.SOLVEPNP_P3P)

Error that I get:

Traceback (most recent call last): File "C:\Users\pavithra\Pictures\Camera Roll\project_3D_to_2D.py", line 2016, in <module> retval, rvec, tvec = cv2.solvePnP(np.array(tnsPoints),np.array(imPoints),np.asarray(camera_matrix),np.asarray(dist_coeffs), flags=cv2.SOLVEPNP_P3P) cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\calib3d\src\solvepnp.cpp:92: error: (-215:Assertion failed) ( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) in function 'cv::solvePnP'


Please let me know if anybody has any idea of what is going on.

Thank you.

SolvePNP_P3P doesn't work for 4 points. Please help.

Hello, I'm using the solvePnP() function to get the extrinsics for a camera. I'm calibrating wrt the ground. I have taken 4 points on the ground. I tried to use the solvePnP_P3P flag because I was using exactly 4 points but I get an error when I run the function.

System details: Windows 10. OpenCV 4.1

Code snippet: snippet:

import numpy as np
from numpy.linalg import inv
import cv2
import sys

sys # with open('./calib/calibration.yaml') as f:

f: # loadeddict = yaml.load(f)

yaml.load(f) # camera_matrix = loadeddict.get('camera_matrix')

loadeddict.get('camera_matrix') # dist_coeffs = loadeddict.get('dist_coeff')

loadeddict.get('dist_coeff') camera_matrix = [[1029.61564, 0.00000000, 916.314412], [0.00000000 ,1026.37518 ,526.909999], [0.00000000, 0.00000000, 1.00000000]]

1.00000000]] dist_coeffs = [[-0.3725, 0.21018, -0.001127, 0.00013219, -0.09244]]

tnsPoints #tnsPoints = [(0.0, 1.0, 0.0), (3.0, 1.0, 0.0), (2.0, 6.0, 0.0), (0.0, 6.0, 0.0)]

0.0)] tnsPoints = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)]

1.0)] imPoints = [(809, 915), (1181, 893), (1020, 362), (811, 372)]

372)] retval, rvec, tvec = cv2.solvePnP(np.array(tnsPoints),np.array(imPoints),np.asarray(camera_matrix),np.asarray(dist_coeffs), flags=cv2.SOLVEPNP_P3P)

flags=cv2.SOLVEPNP_P3P)

Error that I get:

Traceback (most recent call last): File "C:\Users\pavithra\Pictures\Camera Roll\project_3D_to_2D.py", line 2016, in <module> retval, rvec, tvec = cv2.solvePnP(np.array(tnsPoints),np.array(imPoints),np.asarray(camera_matrix),np.asarray(dist_coeffs), flags=cv2.SOLVEPNP_P3P) cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\calib3d\src\solvepnp.cpp:92: error: (-215:Assertion failed) ( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) in function 'cv::solvePnP'


Please let me know if anybody has any idea of what is going on.

Thank you.

SolvePNP_P3P doesn't work for 4 points. Please help.

Hello, I'm using the solvePnP() function to get the extrinsics for a camera. I'm calibrating wrt the ground. I have taken 4 points on the ground. I tried to use the solvePnP_P3P flag because I was using exactly 4 points but I get an error when I run the function.

System details: Windows 10. OpenCV 4.1

Code snippet:

import numpy as np
from numpy.linalg import inv
import cv2
import sys


# with open('./calib/calibration.yaml') as f:
#     loadeddict = yaml.load(f)
# camera_matrix = loadeddict.get('camera_matrix')
# dist_coeffs = loadeddict.get('dist_coeff')


camera_matrix = [[1029.61564, 0.00000000, 916.314412],
 [0.00000000 ,1026.37518 ,526.909999],
 [0.00000000, 0.00000000, 1.00000000]]

dist_coeffs = [[-0.3725, 0.21018, -0.001127, 0.00013219, -0.09244]] 

#tnsPoints = [(0.0, 1.0, 0.0), (3.0, 1.0, 0.0), (2.0, 6.0, 0.0), (0.0, 6.0, 0.0)]
tnsPoints = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)]

imPoints = [(809, 915), (1181, 893), (1020, 362), (811, 372)]

retval, rvec, tvec = cv2.solvePnP(np.array(tnsPoints),np.array(imPoints),np.asarray(camera_matrix),np.asarray(dist_coeffs), flags=cv2.SOLVEPNP_P3P)

Error that I get:

Traceback (most recent call last):
File "C:\Users\pavithra\Pictures\Camera Roll\project_3D_to_2D.py", line 2016, in <module>
retval, rvec, tvec = cv2.solvePnP(np.array(tnsPoints),np.array(imPoints),np.asarray(camera_matrix),np.asarray(dist_coeffs), flags=cv2.SOLVEPNP_P3P)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\calib3d\src\solvepnp.cpp:92: error: (-215:Assertion failed) ( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) in function 'cv::solvePnP'

'cv::solvePnP'

Please let me know if anybody has any idea of what is going on.

Thank you.