我正在使用背景减法来分析室外场景的移动物体.当太阳出来时我有阴影问题.我正在使用轮廓来隔离对象.目前我只是分析轮廓的上半部分,因为阴影通常位于下半部分.
想象一下橡皮鸭的轮廓,我想要做的是找到鸭子颈部的y位置,即轮廓处于最小水平尺寸的位置.有人可以指出我如何找到"鸭脖"的正确方向?
在代码中,binary是移动对象的阈值图像,HIGHT并且WIDTH是图像的高度和宽度,lab是LAB颜色空间中的相同图像.
我想half = int(h/2)用函数替换该行来找到水平线的y位置以切断"鸭脖".
_,contours,_ = cv2.findContours(binary.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
# loop over the contours
for i, cnt in enumerate(contours):
# compute the bounding box for the contour
(x, y, w, h) = cv2.boundingRect(cnt)
# reject contours outside size range
if w > 250 or w < 30 or h > 250 or h < 30 :
continue
# make sure the box is inside the frame
if x …Run Code Online (Sandbox Code Playgroud)