Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
868 B
29 lines
868 B
import numpy as np |
|
import cv2 |
|
|
|
from multiprocessing.pool import ThreadPool |
|
from collections import deque |
|
|
|
|
|
if __name__ == '__main__': |
|
def process_frame(frame): |
|
# some intensive computation... |
|
frame = cv2.medianBlur(frame, 19) |
|
frame = cv2.medianBlur(frame, 19) |
|
frame = cv2.medianBlur(frame, 19) |
|
return frame |
|
|
|
threadn = 8 |
|
cap = cv2.VideoCapture(0) |
|
pool = ThreadPool(processes = threadn) |
|
pending = deque() |
|
while True: |
|
while len(pending) > 0 and pending[0].ready(): |
|
res = pending.popleft().get() |
|
cv2.imshow('result', res) |
|
if len(pending) < threadn+1: |
|
ret, frame = cap.read() |
|
task = pool.apply_async(process_frame, (frame.copy(),)) |
|
pending.append(task) |
|
if cv2.waitKey(1) == 27: |
|
break
|
|
|