def trackPoint(grayimage1, grayimage2):
moveData = [] # initialize list of movementCenterPoints
biggestArea = MIN_AREA
# Get differences between the two greyed images
differenceImage = cv2.absdiff( grayimage1, grayimage2 )
# Blur difference image to enhance motion vectors
differenceImage = cv2.blur( differenceImage,(BLUR_SIZE,BLUR_SIZE ))
# Get threshold of blurred difference image based on THRESHOLD_SENSITIVITY variable
retval, thresholdImage = cv2.threshold( differenceImage, THRESHOLD_SENSITIVITY, 255, cv2.THRESH_BINARY )
try:
thresholdImage, contours, hierarchy = cv2.findContours( thresholdImage, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE )
except:
contours, hierarchy = cv2.findContours( thresholdImage, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE )
if contours != ():
for c in contours:
cArea = cv2.contourArea(c)
if cArea > biggestArea:
biggestArea = cArea
( x, y, w, h ) = cv2.boundingRect(c)
cx = int(x + w/2) # x center point of contour
cy = int(y + h/2) # y center point of contour
moveData = [cx, cy, w, h]
return moveData
#-----------------------------------------------------------------------------------------------
评论列表
文章目录