-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencv_send_fall.py
More file actions
51 lines (47 loc) · 1.46 KB
/
Copy pathopencv_send_fall.py
File metadata and controls
51 lines (47 loc) · 1.46 KB
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
import cv2
import numpy as np
import random
pile_obs = np.zeros([50], np.int16)
for _ in range(2000):
p = int(random.normalvariate(24, 10))
try:
pile_obs[p] += 1
except:
pass
while True:
for i in range(50):
left = pile_obs[i - 1 : i]
true_left = pile_obs[i]
right = pile_obs[i + 1 : i + 2]
true_right = pile_obs[i]
if len(left) == 1:
true_left = left[0]
if len(right) == 1:
true_right = right[0]
if true_left > true_right:
if pile_obs[i] - true_right > 1:
pile_obs[i] -= 1
pile_obs[i + 1] += 1
elif true_left < true_right:
if pile_obs[i] - true_left > 1:
pile_obs[i] -= 1
pile_obs[i - 1] += 1
else:
l = random.randint(0, 1)
if l:
if pile_obs[i] - true_left > 1:
pile_obs[i] -= 1
pile_obs[i - 1] += 1
else:
if pile_obs[i] - true_right > 1:
pile_obs[i] -= 1
pile_obs[i + 1] += 1
image = np.zeros([400, 200])
for x, v in enumerate(pile_obs):
cv2.rectangle(image, [4 * x, 400 - 4 * v], [3 + 4 * x, 400], 1, -1)
cv2.imshow("1", image)
mykey = cv2.waitKey(1)
# 按q退出循环,0xFF是为了排除一些功能键对q的ASCII码的影响
if mykey & 0xFF == ord("q"):
break
cv2.destroyAllWindows()