本文整理汇总了Python中PostProcessing.distance_two_squares方法的典型用法代码示例。如果您正苦于以下问题:Python PostProcessing.distance_two_squares方法的具体用法?Python PostProcessing.distance_two_squares怎么用?Python PostProcessing.distance_two_squares使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PostProcessing
的用法示例。
在下文中一共展示了PostProcessing.distance_two_squares方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import PostProcessing [as 别名]
# 或者: from PostProcessing import distance_two_squares [as 别名]
def run(self, cur_frame, next_frame,):
# Setup the termination criteria, either 10 iteration or move by at least 1 pt
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1)
new_list_of_objects = []
for obj_tuple in self.list_of_objects:
hsv_roi = None
if len(obj_tuple) == 4:
obj, hsv_roi, n_in_frame, n_not_moving = obj_tuple
if (hsv_roi is not None) and (obj[2] > 0 or obj[3] > 0):
mask = cv2.inRange(hsv_roi, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
roi_hist = cv2.calcHist([hsv_roi], [0], mask, [180], [0, 180])
cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX)
# track in next frame
# backprojection
hsv = cv2.cvtColor(next_frame, cv2.COLOR_BGR2HSV)
dst = cv2.calcBackProject([hsv], [0], roi_hist, [0, 180], 1)
# apply meanshift to get the new location
ret, obj_new = cv2.meanShift(dst, obj, term_crit)
n_in_frame += 1
if PostProcessing.distance_two_squares(obj, obj_new) < 1:
n_not_moving += 1
else:
n_not_moving = 0
x, y, w, h = obj_new
if n_not_moving < 20:
new_list_of_objects.append((obj_new, hsv_roi, n_in_frame, n_not_moving))
# draw
cv2.rectangle(next_frame, (x, y), (x + w, y + h), 255, 2)
self.list_of_objects = new_list_of_objects
pass