我正在尝试通过多处理来加速OPENCV视频处理,但是队列中出现异常。
类管道,它获取图像和一些Kalman滤波器跟踪器,并返回包含跟踪的汽车,peds等的图像。
它在那里完成了所有计算。
错误:
TypeError:无法腌制_thread.lock对象
代码:
class DummyTask:
def __init__(self, data):
self.data = data
def ready(self):
return True
def get(self):
return self.data
if __name__ == "__main__":
video_name = '2016-11-18_07-30-01.h264'
cap = cv2.VideoCapture(video_name)
det = detector.CarDetector()
car_tracker = Sort_Algorithm.Sort()
ped_tracker = Sort_Algorithm.Sort()
df_region, df_line = load_filter()
threadn = cv2.getNumberOfCPUs()
pool = Pool(processes = 2)
pending = Queue()
threaded_mode = True
while True:
while pending.qsize() > 0:
res = pending.get()
cv2.imshow('video ', res)
if pending.qsize() < 2:
ret, frame = cap.read()
if threaded_mode:
t1 = time.time()
H = [-2.01134074616, -16.6502442427, -1314.05715739, -3.35391526592, -22.3546973012, 2683.63584335,
-0.00130731963137, -0.0396207582264, 1]
matrix = np.reshape(H, (3, 3))
dst = cv2.warpPerspective(frame.copy(), matrix, (frame.shape[1], frame.shape[0]))
task = pool.apply_async(pipeline, (frame.copy(),car_tracker, ped_tracker,df_region, df_line, det, dst, matrix))
cv2.imshow('dst', dst)
else:
task = DummyTask(pipeline,(frame.copy(),car_tracker, ped_tracker,df_region, df_line, det, dst, matrix))
pending.put(task)
ch = cv2.waitKey(1)
if ch == ord(' '):
threaded_mode = not threaded_mode
if ch == 27:
break