def main STANDARD_RIGHTS_REQU IRED 0xF0000 SYNCHRONIZE 0x100000 MUTANT

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def main():
STANDARD_RIGHTS_REQUIRED = 0xF0000
SYNCHRONIZE = 0x100000
MUTANT_QUERY_STATE = 0x1
target_center = [0, 0]
diff = [0, 0]
target_center_frame_before = [0, 0]
sharedmemory = mmap.mmap(0, SHARED_MEMORY_SIZE, shared_memory_name, mmap.ACCESS_READ)
texture1_mutex = win32event.OpenMutex(SYNCHRONIZE, False, texture1_mutex_name)
texture2_mutex = win32event.OpenMutex(SYNCHRONIZE, False, texture2_mutex_name)
texture_ready_event = win32event.OpenEvent(SYNCHRONIZE, False, texture_ready_name)
magenta_dark = np.array([H_LOW, S_LOW, V_LOW])
magenta_light = np.array([H_HIGH, S_HIGH, V_HIGH])
while True:
if win32event.WAIT_OBJECT_0 == win32event.WaitForSingleObject(texture_ready_event, -1):
meta = getmeta(sharedmemory)
data = np.array([])
data_size = meta[0] * meta[1] * 4
height = meta[1]
width = meta[0]
if meta[3] == 1:
if win32event.WaitForSingleObject(texture1_mutex, 0) == win32event.WAIT_OBJECT_0:
# print('texture 1')
data = getdata(sharedmemory, TEXTURE_1_OFFSET, data_size, height, width)
win32event.ReleaseMutex(texture1_mutex)
elif win32event.WaitForSingleObject(texture2_mutex, 0) == win32event.WAIT_OBJECT_0:
# print('texture 2')
data = getdata(sharedmemory, TEXTURE_2_OFFSET, data_size, height, width)
win32event.ReleaseMutex(texture2_mutex)
else:
continue
elif meta[3] == 2:
if win32event.WaitForSingleObject(texture2_mutex, 0) == win32event.WAIT_OBJECT_0:
# print('texture 1')
data = getdata(sharedmemory, TEXTURE_2_OFFSET, data_size, height, width)
win32event.ReleaseMutex(texture2_mutex)
elif win32event.WaitForSingleObject(texture1_mutex, 0) == win32event.WAIT_OBJECT_0:
# print('texture 2')
data = getdata(sharedmemory, TEXTURE_1_OFFSET, data_size, height, width)
win32event.ReleaseMutex(texture1_mutex)
else:
continue
else:
continue
cv2.imshow(title, img)
cv2.waitKey(1)