本文整理汇总了Python中cv2.TrackerKCF_create方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.TrackerKCF_create方法的具体用法?Python cv2.TrackerKCF_create怎么用?Python cv2.TrackerKCF_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.TrackerKCF_create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_tracker_constructor
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def call_tracker_constructor(self, tracker_type):
# -- TODO: remove this if I assume OpenCV version > 3.4.0
if int(self.major_ver == 3) and int(self.minor_ver) < 3:
tracker = cv2.Tracker_create(tracker_type)
# --
else:
if tracker_type == 'CSRT':
tracker = cv2.TrackerCSRT_create()
elif tracker_type == 'KCF':
tracker = cv2.TrackerKCF_create()
elif tracker_type == 'MOSSE':
tracker = cv2.TrackerMOSSE_create()
elif tracker_type == 'MIL':
tracker = cv2.TrackerMIL_create()
elif tracker_type == 'BOOSTING':
tracker = cv2.TrackerBoosting_create()
elif tracker_type == 'MEDIANFLOW':
tracker = cv2.TrackerMedianFlow_create()
elif tracker_type == 'TLD':
tracker = cv2.TrackerTLD_create()
elif tracker_type == 'GOTURN':
tracker = cv2.TrackerGOTURN_create()
return tracker
示例2: test_blob_update
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def test_blob_update():
_bounding_box = [1, 1, 4, 4]
_type = 'car'
_confidence = 0.99
_tracker = cv2.TrackerKCF_create()
blob = Blob(_bounding_box, _type, _confidence, _tracker)
_new_bounding_box = [2, 2, 5, 5]
_new_type = 'bus'
_new_confidence = 0.35
_new_tracker = cv2.TrackerCSRT_create()
blob.update(_new_bounding_box, _new_type, _new_confidence, _new_tracker)
assert blob.bounding_box == _new_bounding_box
assert blob.type == _new_type
assert blob.type_confidence == _new_confidence
assert blob.tracker == _new_tracker
示例3: predictionCallback
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def predictionCallback(self, client, userdata, message):
print('<< predictionCallback() >>')
data = json.loads(message.payload.decode())
if len(data['prediction']) > 0 and data['prediction'][0][0] > -1:
self.last_confidence = round(data['prediction'][0][2]*100,2)
self.last_detected_class = int(data['prediction'][0][0])
x1 = data['prediction'][0][2]*self.IMAGE_WIDTH
y1 = data['prediction'][0][3]*self.IMAGE_HEIGHT
x2 = data['prediction'][0][4]*self.IMAGE_WIDTH
y2 = data['prediction'][0][5]*self.IMAGE_HEIGHT
w = x2-x1
h = y2-y1
print("({},{},{},{})".format(x1,x2,y1,y2))
print("({},{})".format(w,h))
self.initBB = (int(x1), int(y1), int(w), int(h))
# self.tracker = cv2.TrackerMOSSE_create()
# self.tracker = cv2.TrackerKCF_create()
self.tracker = cv2.TrackerCSRT_create()
self.tracker.init(self.inferenceFrame, self.initBB)
self.trackerInitialized = True
示例4: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def __init__(self, args):
self.args = args
# self.tracker = cv2.TrackerMedianFlow_create()
self.tracker = cv2.TrackerKCF_create()
示例5: initTracker
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def initTracker(self, img, bbox):
bbox_xywh = self.xyxy2xywh(bbox)
self.tracker = cv2.TrackerKCF_create()
# self.tracker = cv2.TrackerMedianFlow_create()
ok = self.tracker.init(img, bbox_xywh)
return ok
示例6: call_tracker_constructor
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def call_tracker_constructor(self, tracker_type):
if tracker_type == 'DASIAMRPN':
tracker = dasiamrpn()
else:
# -- TODO: remove this if I assume OpenCV version > 3.4.0
if int(self.major_ver == 3) and int(self.minor_ver) < 3:
#tracker = cv2.Tracker_create(tracker_type)
pass
# --
else:
try:
tracker = cv2.TrackerKCF_create()
except AttributeError as error:
print(error)
print('\nMake sure that OpenCV contribute is installed: opencv-contrib-python\n')
if tracker_type == 'CSRT':
tracker = cv2.TrackerCSRT_create()
elif tracker_type == 'KCF':
tracker = cv2.TrackerKCF_create()
elif tracker_type == 'MOSSE':
tracker = cv2.TrackerMOSSE_create()
elif tracker_type == 'MIL':
tracker = cv2.TrackerMIL_create()
elif tracker_type == 'BOOSTING':
tracker = cv2.TrackerBoosting_create()
elif tracker_type == 'MEDIANFLOW':
tracker = cv2.TrackerMedianFlow_create()
elif tracker_type == 'TLD':
tracker = cv2.TrackerTLD_create()
elif tracker_type == 'GOTURN':
tracker = cv2.TrackerGOTURN_create()
return tracker
示例7: init
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def init(self, first_frame, bbox):
if self.name == 'KCF':
self.tracker = cv2.TrackerKCF_create()
elif self.name == 'MOSSE':
self.tracker = cv2.TrackerMOSSE_create()
elif self.name == 'CSRDCF':
self.tracker = cv2.TrackerCSRT_create()
else:
raise NotImplementedError
self.tracker.init(first_frame, bbox)
示例8: test_blob_creation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def test_blob_creation():
_bounding_box = [1, 1, 4, 4]
_type = 'car'
_confidence = 0.99
_tracker = cv2.TrackerKCF_create()
blob = Blob(_bounding_box, _type, _confidence, _tracker)
assert isinstance(blob, Blob), 'blob is an instance of class Blob'
assert blob.bounding_box == _bounding_box
assert blob.type == _type
assert blob.type_confidence == _confidence
assert isinstance(blob.tracker, cv2.Tracker), 'blob tracker is an instance of OpenCV Tracker class'
示例9: _kcf_create
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def _kcf_create(bounding_box, frame):
'''
Create an OpenCV KCF Tracker object.
'''
tracker = cv2.TrackerKCF_create()
tracker.init(frame, tuple(bounding_box))
return tracker
示例10: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import TrackerKCF_create [as 别名]
def __init__(self, tracker_type, bbox, img, keep_height_ratio=1.):
""" Wrapper class for various visual trackers."
Args:
tracker_type (str): name of the tracker. either the ones provided by opencv-contrib or KCF2 for a different
implementation for KCF (requires https://github.com/uoip/KCFcpp-py-wrapper)
bbox (tuple): box to initialize the tracker (x1, y1, x2, y2)
img (numpy.ndarray): image to intialize the tracker
keep_height_ratio (float, optional): float between 0.0 and 1.0 that determines the ratio of height of the
object to track to the total height of the object for visual tracking.
"""
if tracker_type == 'KCF2' and not KCF:
tracker_type = 'KCF'
if not VisTracker.kcf2_warning_printed:
print("[warning] KCF2 not available, falling back to KCF. please see README.md for further details")
VisTracker.kcf2_warning_printed = True
self.tracker_type = tracker_type
self.keep_height_ratio = keep_height_ratio
if tracker_type == 'BOOSTING':
self.vis_tracker = cv2.TrackerBoosting_create()
elif tracker_type == 'MIL':
self.vis_tracker = cv2.TrackerMIL_create()
elif tracker_type == 'KCF':
self.vis_tracker = cv2.TrackerKCF_create()
elif tracker_type == 'KCF2':
self.vis_tracker = KCF.kcftracker(False, True, False, False) # hog, fixed_window, multiscale, lab
elif tracker_type == 'TLD':
self.vis_tracker = cv2.TrackerTLD_create()
elif tracker_type == 'MEDIANFLOW':
self.vis_tracker = cv2.TrackerMedianFlow_create()
elif tracker_type == 'GOTURN':
self.vis_tracker = cv2.TrackerGOTURN_create()
elif tracker_type == 'NONE': # dummy tracker that does nothing but fail
self.vis_tracker = None
self.ok = False
return
else:
raise ValueError("Unknown tracker type '{}".format(tracker_type))
y_max = img.shape[0] - 1
x_max = img.shape[1] - 1
#
bbox = list(bbox)
bbox[0] = max(0, min(bbox[0], x_max))
bbox[2] = max(0, min(bbox[2], x_max))
bbox[1] = max(0, min(bbox[1], y_max))
bbox[3] = max(0, min(bbox[3], y_max))
bbox = [bbox[0], bbox[1], bbox[2] - bbox[0], bbox[3] - bbox[1]] # x1, y1, x2, y2 -> x1, y1, w, h
bbox[3] *= self.keep_height_ratio
if self.tracker_type == 'KCF2':
self.vis_tracker.init(bbox, img)
self.ok = True
else:
self.ok = self.vis_tracker.init(img, tuple(bbox))
pass