This example shows you how to remove the background of an image using depth camera with range filter.
Copy thresholdValueUp = 530
thresholdValueDown = 385
input = cv2 . waitKey ( 1 )
if input == ord ( 'p' ):
if thresholdValueUp + 5 <= 2000 :
thresholdValueUp += 5
else :
thresholdValueUp = 2000
print ( f "Threshold Value (Up): { thresholdValueUp } (Down): { thresholdValueDown } " )
elif input == ord ( 'o' ):
if thresholdValueUp - 5 >= 0 and thresholdValueUp - 5 >= thresholdValueDown :
thresholdValueUp -= 5
print ( f "Threshold Value (Up): { thresholdValueUp } (Down): { thresholdValueDown } " )
elif input == ord ( 'x' ):
if thresholdValueDown + 5 <= 2000 and thresholdValueDown + 5 <= thresholdValueUp :
thresholdValueDown += 5
print ( f "Threshold Value (Up): { thresholdValueUp } (Down): { thresholdValueDown } " )
elif input == ord ( 'z' ):
if thresholdValueDown - 5 >= 0 :
thresholdValueDown -= 5
else :
thresholdValueDown = 0
print ( f "Threshold Value (Up): { thresholdValueUp } (Down): { thresholdValueDown } " )
elif input == ord ( 'q' ):
break
Using these two values to create range filter mask image like we did before.
Copy _ , thres = cv2 . threshold (thres, thresholdValueDown, 1024 , cv2.THRESH_TOZERO)
_ , thres = cv2 . threshold (thres, thresholdValueUp, 1024 , cv2.THRESH_TOZERO_INV)
_ , thres = cv2 . threshold (thres, 1 , 1024 , cv2.THRESH_BINARY)
Copy thres = cv2 . convertScaleAbs (thres, alpha = 255.0 / 1024.0 )
res = cv2 . bitwise_and (rgbMat, rgbMat, mask = thres)