Skip to content

Instantly share code, notes, and snippets.

@hiroto-takatoshi
Last active September 24, 2017 11:49
Show Gist options
  • Save hiroto-takatoshi/ed8d2c86046846a899cad1596eeda9bf to your computer and use it in GitHub Desktop.
Save hiroto-takatoshi/ed8d2c86046846a899cad1596eeda9bf to your computer and use it in GitHub Desktop.
para ver. pic subtraction
import multiprocessing
from multiprocessing import Pool
import cv2
import numpy as np
import ctypes
shared_array_base = multiprocessing.Array(ctypes.c_uint8, 1080*1920*3)
shared_array = np.ctypeslib.as_array(shared_array_base.get_obj())
shared_array = shared_array.reshape(1080, 1920, 3)
gray = cv2.imread('res34.png')
gray = cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
result = cv2.Canny(gray, 200, 20)
img_none = cv2.imread('empty.png')
def f(x,y):
if all(result[y,x] == (255,255,255)):
if not all(img_none[y,x] == (255,255,255)):
shared_array[y,x] = result[y,x]
r = [(x,y) for x in range(1920) for y in range(1080)]
p = Pool(8)
if __name__ == '__main__':
print("2")
p.starmap(f,r)
print("1")
cv2.imwrite('res33.png',shared_array)
print("3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment