Commit 2a96f28b authored by Alexander Mordvintsev's avatar Alexander Mordvintsev

get rid of Lock in gabor_threads.py

parent 5eac0419
...@@ -14,7 +14,6 @@ gabor_threads.py [image filename] ...@@ -14,7 +14,6 @@ gabor_threads.py [image filename]
import numpy as np import numpy as np
import cv2 import cv2
from threading import Lock
from multiprocessing.pool import ThreadPool from multiprocessing.pool import ThreadPool
...@@ -36,13 +35,11 @@ def process(img, filters): ...@@ -36,13 +35,11 @@ def process(img, filters):
def process_threaded(img, filters, threadn = 8): def process_threaded(img, filters, threadn = 8):
accum = np.zeros_like(img) accum = np.zeros_like(img)
accum_lock = Lock()
def f(kern): def f(kern):
fimg = cv2.filter2D(img, cv2.CV_8UC3, kern) return cv2.filter2D(img, cv2.CV_8UC3, kern)
with accum_lock:
np.maximum(accum, fimg, accum)
pool = ThreadPool(processes=threadn) pool = ThreadPool(processes=threadn)
pool.map(f, filters) for fimg in pool.imap_unordered(f, filters):
np.maximum(accum, fimg, accum)
return accum return accum
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment