I'm newbie to computer vision. I'm trying to calculate depth from stereo webcam. I flowed this steps:
- Camera calibration:Calibrate each camera individually,i got Rms 0.2 and 0.18 then i calibrate both cameras (Rms:0.8) using openCv3.
- Calculate Disparity map using ximgproc and opencv3 (create left matcher the right matcher and then createDisparityWLSFilter)
- detect and object (using colors)
- Use this equation: depth=base_line*focal_length/disparity to get depth I got strange values,i even tried to used cv2.reprojectImageTo3D but it gave same problem.
I cannot have fix values. when the ball is farther the depth is smaller.
I didn't understand the (x,y,z) given from the 3D reconstitution
here is my code.
Please help
code
while(True): if not (left.grab() and right.grab()): print("No more frames") break _, leftFrame = left.retrieve() _, rightFrame = right.retrieve() leftFrame = cv2.remap(leftFrame,leftMapX,leftMapY,cv2.INTER_LINEAR) rightFrame = cv2.remap(rightFrame,rightMapX,rightMapY,cv2.INTER_LINEAR)
displ = left_matcher.compute(rightFrame,leftFrame).astype(np.float32)/16
dispr = right_matcher.compute(leftFrame ,rightFrame ).astype(np.float32)/16
displ = np.int16(displ)
dispr = np.int16(dispr)
filteredImg=None
filteredImg = wls_filter.filter(displ, rightFrame, None, dispr) # important to put "imgL" here!!!
filteredImg = cv2.normalize(src=filteredImg, dst=filteredImg, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX);
filteredImg = np.uint8(filteredImg)
cv2.imshow('disparity', filteredImg)
center=bd.ball_detection(rightFrame)
points_3D = cv2.reprojectImageTo3D(filteredImg, Q)
if center!= None:
x= points_3D[center][0]
y= points_3D[center][1]
z= points_3D[center][2]
print("1",triangulation_constant/filteredImg[center])
print("2",x,y,z)