-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcolor_detection.py
35 lines (29 loc) · 1.02 KB
/
color_detection.py
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
import video, sensor, image, lcd, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
v = video.open("/sd/capture.avi", record=1, interval=200000, quality=50)
def get_average(histogram):
sum = 0
average = 0
for object in histogram:
sum = average + object
average = sum / 8
return average
r = [(320//2)-(50//2), (240//2)-(50//2), 50, 50] # 50x50 center of QVGA.
tim = time.ticks_ms()
while(time.ticks_diff(time.ticks_ms(), tim)<30000):
img = sensor.snapshot()
img.draw_rectangle(r)
hist = img.get_statistics(bins=8,roi=r)
rgb_value = image.lab_to_rgb((hist.l_mean(),hist.a_mean(),hist.b_mean()))
img.draw_string(0, 0, str(rgb_value), color = (rgb_value[0], rgb_value[1], rgb_value[2]), scale = 2)
img_len = v.record(img)
lcd.display(img)
print("finish")
v.record_finish()
lcd.clear()