Ask Your Question
0

error: (-215) on solvePnP

asked 2017-06-28 17:09:11 -0600

swiss_knight gravatar image

updated 2017-06-28 17:34:28 -0600

The following code produce the error (cv2 on Python 2.7):

error: (-215) npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) in function solvePnP

I can't figure out why.

This is the code:

import os, sys
import math
import numpy as np
import cv2
img_folder = ('/home/username/images/')
img_file   = os.path.join(img_folder,'1.jpg')
img        = cv2.imread(img_file,0)
h,w = img.shape

obj_pts = np.array([[10,60,0],
                    [10,60,12.6],
                    [24,60,0],
                    [24,60,12.6],
                    [24,74,0],
                    [24,74,12.6],
                    [30,70,0],
                    [30,70,8.8],
                    [47.7,70,0],
                    [47.7,70,8.8]
                   ], dtype=np.float32)

img_pts = np.array([[800,970],
                    [689,329],
                    [1380,1175],
                    [1363,458],
                    [1842,881],
                    [1875,256],
                    [1977,1051],
                    [1994,592],
                    [2959,1347],
                    [3052,852]
                   ], dtype=int)
img_pts = np.fliplr(img_pts)
if True:
    ppa     = (w/2., h/2.)
    fm      = 7.5/1e3
    sensor  = (7.14e-3, 5.36e-3)
    focal   = w*(fm / sensor[0])
    cam_mat = np.array( [[focal, 0, ppa[0]],
                         [0, focal, ppa[1]],
                         [0, 0, 1]], dtype = np.float64
                      )
    dist_coeffs = np.zeros((5,1))
    rvec = np.zeros((3,1))
    tvec = np.zeros((3,1)) 
    flag = cv2.SOLVEPNP_ITERATIVE # tried with SOLVEPNP_EPNP, same error.
    retval,  rvec, tvec = cv2.solvePnP(obj_pts, img_pts, cam_mat, dist_coeffs, rvec, tvec, flags=flag)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-06-29 02:48:41 -0600

berak gravatar image

updated 2017-06-29 02:49:43 -0600

if you look at the assertion: std::max(ipoints.checkVector(2, CV_32F)

your img_points must be dtype=np.float32, not np.int

edit flag offensive delete link more

Comments

You're right. Image points requires to be as dtype=np.float32. Object points may also be dtype=np.float64 if needed.

swiss_knight gravatar imageswiss_knight ( 2017-06-29 13:53:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-28 17:09:11 -0600

Seen: 11,499 times

Last updated: Jun 29 '17