I'm using OpenCV to compare thousands of images to one reference image. The process is very lengthy and I'm considering multiprocessing as a way to accelerate it.
How should I make it so that it'll do the "cv.matchTemplate(...)" function for each image, and without looping re-doing the function on the same image?
def myFunction():
values_for_each_image =[]
for image in thousands_of_images:
result = cv.matchTemplate(reference_image, image, cv.TM_CCOEFF_NORMED)
values_for_each_image.append(result[1])
return values_for_each_image
Theoretically, I know that I could do something like this (but it's unrealistic for thousands of images):
def do_image1():
return cv.matchTemplate(reference_image, image1, cv.TM_CCOEFF_NORMED)
def do_image2():
return cv.matchTemplate(reference_image, image2, cv.TM_CCOEFF_NORMED)
p1 = multiprocessing.Process(target=do_image1)
p2 = multiprocessing.Process(target=do_image2)
if __name__ == '__main__':
p1.start()
p2.start()
...