本文整理汇总了Python中SimpleCV.Image.track方法的典型用法代码示例。如果您正苦于以下问题:Python Image.track方法的具体用法?Python Image.track怎么用?Python Image.track使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Image
的用法示例。
在下文中一共展示了Image.track方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import track [as 别名]
def main():
camera = cv2.VideoCapture('video2.avi')
background_subtractor = cv2.BackgroundSubtractorMOG()
# Store previous tracking image
previous_track_image = Image()
while camera.isOpened():
is_success, image = camera.read()
if is_success:
mask = background_subtractor.apply(image, None, 0.1)
# Vehicles will be detected from this image
track_image = Image(ndimage.median_filter(mask, 3), cv2image=True)
blobs = track_image.findBlobs(minsize=250, maxsize=800)
if not blobs:
# print('No Blobs Found.')
continue
else:
# print("Width: {0}; Height: {1}".format(blobs[0].width(), blobs[0].height()))
# Only keep near square blobs
blobs = filter(lambda b: 0.25 < b.width() / b.height() < 4, blobs)
# print("Found {0} Blobs. {1}".format(len(blobs)))
if len(vehicle_track_set_list) == 0:
# Find first batch of blobs
for blob in blobs:
blob.drawRect(color=Color.BLUE, width=3, alpha=225)
# bounding_box = tuple(blob.boundingBox())
# print("Area: {0}".format(blob.area()))
track_set = track_image.track(method='mftrack', img=track_image, bb=blob.boundingBox())
if track_set:
vehicle_track_set_list.append(VehicleTrackSet(track_set))
track_set.drawBB(color=(255, 0, 0))
track_set.drawPath()
track_image.show()
else:
for blob in blobs:
blob.drawRect(color=Color.BLUE, width=3, alpha=225)
# print("Blob Coordinate: ({0}, {1}).".format(blob.x, blob.y))
update_track_set(track_image, previous_track_image, blob.boundingBox())
# Save current image
previous_track_image = track_image
# time.sleep(0.1)
else:
camera.release()
break