Monday, 12 November 2018

Python OpenCV speedup for multiprocessing

I am trying to run my image processing algorithm on a live feed from the webcam. I want this to run in a parallel process from the multiprocessing module, how can i implement this? This is my current code without parallel coding:

from cv2 import VideoCapture , imshow , waitKey ,imwrite
import numpy as np
from time import time

def greenify (x):
    return some_value

skip = 4

video = VideoCapture(0)
video.set(3,640/skip)
video.set(4,480/skip)

total = 0
top_N = 100

while True:
    image = video.read()[1]        
    if waitKey(1) == 27:
        break

    arr = array([list(map(greenify,j)) for j in image])

    result = unravel_index(argpartition(arr,arr.size-top_N,axis=None)[-top_N:], arr.shape)
    centre = skip*np.median(result[0]) , skip*np.median(result[1])

    imshow('Feed', image)

print('Time taken:',total)
video.release()



from Python OpenCV speedup for multiprocessing

No comments:

Post a Comment