本文整理匯總了Python中cv2.KalmanFilter方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.KalmanFilter方法的具體用法?Python cv2.KalmanFilter怎麽用?Python cv2.KalmanFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.KalmanFilter方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: myKalman
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import KalmanFilter [as 別名]
def myKalman(tid):
if tid not in workers:
kalman = cv2.KalmanFilter(4, 2) # 4:狀態數,包括(x,y,dx,dy)坐標及速度(每次移動的距離);2:觀測量,能看到的是坐標值
kalman.measurementMatrix = np.array([[1, 0, 0, 0], [0, 1, 0, 0]], np.float32) # 係統測量矩陣
kalman.transitionMatrix = np.array([[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]], np.float32) # 狀態轉移矩陣
kalman.processNoiseCov = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]], np.float32)*0.03 # 係統過程噪聲協方差
KalmanNmae[tid] = kalman
示例2: create_kalman
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import KalmanFilter [as 別名]
def create_kalman(self):
"""Creates kalman filter."""
kalman = cv2.KalmanFilter(4, 2)
kalman.measurementMatrix = np.array([[1, 0, 0, 0], [0, 1, 0, 0]],
np.float32)
kalman.transitionMatrix = np.array(
[[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]], np.float32)
kalman.processNoiseCov = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
[0, 0, 0, 1]], np.float32) * 0.03
self.kalman = kalman
self.measurement = np.array((2, 1), np.float32)
self.prediction = np.zeros((2, 1), np.float32)
示例3: __init__
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import KalmanFilter [as 別名]
def __init__(self,
state_num=4,
measure_num=2,
cov_process=0.0001,
cov_measure=0.1):
"""Initialization"""
# Currently we only support scalar and point, so check user input first.
assert state_num == 4 or state_num == 2, "Only scalar and point supported, Check state_num please."
# Store the parameters.
self.state_num = state_num
self.measure_num = measure_num
# The filter itself.
self.filter = cv2.KalmanFilter(state_num, measure_num, 0)
# Store the state.
self.state = np.zeros((state_num, 1), dtype=np.float32)
# Store the measurement result.
self.measurement = np.array((measure_num, 1), np.float32)
# Store the prediction.
self.prediction = np.zeros((state_num, 1), np.float32)
# Kalman parameters setup for scalar.
if self.measure_num == 1:
self.filter.transitionMatrix = np.array([[1, 1],
[0, 1]], np.float32)
self.filter.measurementMatrix = np.array([[1, 1]], np.float32)
self.filter.processNoiseCov = np.array([[1, 0],
[0, 1]], np.float32) * cov_process
self.filter.measurementNoiseCov = np.array(
[[1]], np.float32) * cov_measure
# Kalman parameters setup for point.
if self.measure_num == 2:
self.filter.transitionMatrix = np.array([[1, 0, 1, 0],
[0, 1, 0, 1],
[0, 0, 1, 0],
[0, 0, 0, 1]], np.float32)
self.filter.measurementMatrix = np.array([[1, 0, 0, 0],
[0, 1, 0, 0]], np.float32)
self.filter.processNoiseCov = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]], np.float32) * cov_process
self.filter.measurementNoiseCov = np.array([[1, 0],
[0, 1]], np.float32) * cov_measure