Output 3D points change everytime in triangulatePoints using in Python 2.7 with OpenCV 3.3 -
i want know 3d points stereo cameras using triangulatepoints
in python 2.7 , opencv 3.3. that, calibrated stereo cameras , stored matrices in folder. rectified images using cv2.stereorectify
, using cv2.initundistortrectifymap
undistort images. saved images projection matrices p1 , p2 , find corresponding point in both images. point in left image ptl = np.array([304,277])
, corresponding point in right image ptr = np.array([255,277])
. after tried points = cv2.triangulatepoints(p1,p2,ptl,ptr)
. code is:
import cv2 import numpy np import matplotlib.pyplot plt cameramatrixl = np.load('mtx_left.npy') distcoeffsl = np.load('dist_left.npy') cameramatrixr = np.load('mtx_right.npy') distcoeffsr = np.load('dist_right.npy') r = np.load('r.npy') t = np.load('t.npy') # following matrices saved got stereorectify r1 = np.load('r1.npy') r2 = np.load('r2.npy') p1 = np.load('p1.npy') p2 = np.load('p2.npy') q = np.load('q.npy') # upload alreday distorted , rectified images imgl = cv2.imread('d:\python/triangulate in 3 d\left.png',0) imgr = cv2.imread('d:\python/triangulate in 3 d/right.png',0) ptl = np.array([304,277]) # point in left image ptr = np.array([255,277]) # corresponding point in right image points = cv2.triangulatepoints(p1,p2,ptl,ptr) print points
but when ever run code results got changed (also results wrong). 1 time results like
[[ 518845863] [ 1667138857] [-1189385102] [ -661713]]
another time results like
[[-1766436066] [ 0] [ 0] [-1299735447]]
sometimes looks
[[ 0] [ 0] [697559541] [ 0]]
i don't know why results changing parameters same only? also, these 3d points incorrect. how correct these problems?
edit: i observed 1 thing in code, after running not completed. neither shows process finished exit code 0
nor process finished exit code 1
. when pressed red stop button finished process finished exit code 1
. why so? think due above error coming. why code not running process finished exit code 0
?
finally, after many tries found out mistake doing. actually, defining points in code in wrong way. according triangulatepoints document, points should
projpoints1 – 2xn array of feature points in first image.
but in code wrote
ptl = np.array([304,277]) # point in left image ptr = np.array([255,277]) # corresponding point in right image
means defining 1x2
array while should define 2x1
array single point. likewise 5 points array should 2x5
. n
points offcourse 2xn
. initially, didn't notice because used traingulation in matlab , there corresponding points used nx2 array.now put points
l = np.array([[ 304],[ 277]],dtype=np.float) r = np.array([[ 255 ],[ 277]],dtype=np.float)
and got above code working.
one more point dtype=np.float
important in defining point array avoid wrong results.
results got not accurate , shows error of 20-25 mm solved above problem answer question , have find out way minimise errors. if knows how reduce error please tell me.
Comments
Post a Comment