提交 2a96f28b 编写于 作者: A Alexander Mordvintsev

get rid of Lock in gabor_threads.py

上级 5eac0419
......@@ -14,7 +14,6 @@ gabor_threads.py [image filename]
import numpy as np
import cv2
from threading import Lock
from multiprocessing.pool import ThreadPool
......@@ -36,13 +35,11 @@ def process(img, filters):
def process_threaded(img, filters, threadn = 8):
accum = np.zeros_like(img)
accum_lock = Lock()
def f(kern):
fimg = cv2.filter2D(img, cv2.CV_8UC3, kern)
with accum_lock:
np.maximum(accum, fimg, accum)
return cv2.filter2D(img, cv2.CV_8UC3, kern)
pool = ThreadPool(processes=threadn)
pool.map(f, filters)
for fimg in pool.imap_unordered(f, filters):
np.maximum(accum, fimg, accum)
return accum
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册