├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── color_detection.py ├── detect_eyes.py ├── find non_inf_lines.py ├── find_circles.py ├── find_inf_lines.py └── find_rectangles.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # AIWIntermuteAI 4 | buy_me_a_coffee: # hardwareai 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dmitry Maslov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # maixpy-openmv-demos 2 | Codes and micropython binary for Sipeed MaiX Bit OpenMV demos 3 | 4 | Examples are from OpenMV Github repository with some minor changes to work with Sipeed MaiX Bit and enbale video recording. 5 | Micropython binary is compiled using source code from MaixPy Github repository. 6 | 7 | UPDATE 2024/03/18: Find the MaxiPy for K210 repository here https://github.com/sipeed/maixpy-v1 and precompiled binaries 8 | here http://dl.sipeed.com/MAIX/MaixPy/release/master/. You probably will need maixpy_*_openmv_kmodel_v4_with_ide_support or maixpy_*.bin. 9 | -------------------------------------------------------------------------------- /color_detection.py: -------------------------------------------------------------------------------- 1 | import video, sensor, image, lcd, time 2 | 3 | sensor.reset() 4 | sensor.set_pixformat(sensor.RGB565) 5 | sensor.set_framesize(sensor.QVGA) 6 | sensor.run(1) 7 | sensor.skip_frames(30) 8 | sensor.set_auto_gain(False) # must be turned off for color tracking 9 | sensor.set_auto_whitebal(False) # must be turned off for color tracking 10 | 11 | v = video.open("/sd/capture.avi", record=1, interval=200000, quality=50) 12 | 13 | def get_average(histogram): 14 | sum = 0 15 | average = 0 16 | for object in histogram: 17 | sum = average + object 18 | average = sum / 8 19 | return average 20 | 21 | r = [(320//2)-(50//2), (240//2)-(50//2), 50, 50] # 50x50 center of QVGA. 22 | tim = time.ticks_ms() 23 | 24 | while(time.ticks_diff(time.ticks_ms(), tim)<30000): 25 | img = sensor.snapshot() 26 | img.draw_rectangle(r) 27 | hist = img.get_statistics(bins=8,roi=r) 28 | rgb_value = image.lab_to_rgb((hist.l_mean(),hist.a_mean(),hist.b_mean())) 29 | img.draw_string(0, 0, str(rgb_value), color = (rgb_value[0], rgb_value[1], rgb_value[2]), scale = 2) 30 | img_len = v.record(img) 31 | lcd.display(img) 32 | print("finish") 33 | v.record_finish() 34 | lcd.clear() 35 | 36 | -------------------------------------------------------------------------------- /detect_eyes.py: -------------------------------------------------------------------------------- 1 | import video, sensor, image, lcd, time 2 | 3 | lcd.init() 4 | # Reset sensor 5 | sensor.reset() 6 | 7 | # Sensor settings 8 | sensor.set_contrast(1) 9 | sensor.set_gainceiling(16) 10 | sensor.set_framesize(sensor.QVGA) 11 | sensor.set_pixformat(sensor.RGB565) 12 | sensor.run(1) 13 | sensor.skip_frames(30) 14 | v = video.open("/sd/capture_eyes.avi", record=1, interval=200000, quality=50) 15 | 16 | # Load Haar Cascade 17 | # By default this will use all stages, lower satges is faster but less accurate. 18 | face_cascade = image.HaarCascade("frontalface", stages=25) 19 | eyes_cascade = image.HaarCascade("eye", stages=24) 20 | tim = time.ticks_ms() 21 | 22 | while(time.ticks_diff(time.ticks_ms(), tim)<30000): 23 | # Capture snapshot 24 | img = sensor.snapshot() 25 | objects = img.find_features(face_cascade, threshold=0.5, scale_factor=1.5) 26 | for face in objects: 27 | img.draw_rectangle(face) 28 | eyes = img.find_features(eyes_cascade, threshold=0.5, scale_factor=1.2, roi=face) 29 | for e in eyes: 30 | img.draw_rectangle(e) 31 | img_len = v.record(img) 32 | lcd.display(img) 33 | print("finish") 34 | v.record_finish() 35 | lcd.clear() 36 | -------------------------------------------------------------------------------- /find non_inf_lines.py: -------------------------------------------------------------------------------- 1 | #find non-infinite lines 2 | import video, sensor, image, lcd, time 3 | lcd.init() 4 | sensor.reset() 5 | sensor.set_pixformat(sensor.RGB565) # grayscale is faster 6 | sensor.set_framesize(sensor.QVGA) 7 | sensor.run(1) 8 | sensor.skip_frames(30) 9 | v = video.open("/sd/capture_lines.avi", record=1, interval=200000, quality=50) 10 | tim = time.ticks_ms() 11 | while(time.ticks_diff(time.ticks_ms(), tim)<30000): 12 | img = sensor.snapshot() 13 | for l in img.find_line_segments(merge_distance = 10, max_theta_diff = 25, roi=(80,60,160,120)): 14 | img.draw_line(l.line(), color = (255, 0, 0)) 15 | lcd.display(img) 16 | img_len = v.record(img) 17 | print("finish") 18 | v.record_finish() 19 | lcd.clear() 20 | -------------------------------------------------------------------------------- /find_circles.py: -------------------------------------------------------------------------------- 1 | #find circles 2 | import video, sensor, image, lcd, time 3 | 4 | lcd.init() 5 | sensor.reset() 6 | sensor.set_contrast(1) 7 | sensor.set_gainceiling(16) 8 | sensor.set_pixformat(sensor.RGB565) 9 | sensor.set_framesize(sensor.QVGA) 10 | sensor.run(1) 11 | sensor.skip_frames(30) 12 | v = video.open("/sd/capture_circles.avi", record=1, interval=200000, quality=50) 13 | 14 | tim = time.ticks_ms() 15 | 16 | while(time.ticks_diff(time.ticks_ms(), tim)<30000): 17 | img = sensor.snapshot() 18 | for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2,roi=(80,60,160,120)): 19 | img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) 20 | img.draw_rectangle(80,60,160,120) 21 | img_len = v.record(img) 22 | lcd.display(img) 23 | print("finish") 24 | v.record_finish() 25 | lcd.clear() 26 | 27 | -------------------------------------------------------------------------------- /find_inf_lines.py: -------------------------------------------------------------------------------- 1 | #find infinite lines 2 | import video, sensor, image, lcd, time 3 | enable_lens_corr = True 4 | lcd.init() 5 | sensor.reset() 6 | sensor.set_pixformat(sensor.RGB565) 7 | sensor.set_framesize(sensor.QVGA) 8 | sensor.run(1) 9 | sensor.skip_frames(time = 2000) 10 | 11 | v = video.open("/sd/capture_inf_lines.avi", record=1, interval=200000, quality=50) 12 | min_degree = 0 13 | max_degree = 179 14 | tim = time.ticks_ms() 15 | 16 | while(time.ticks_diff(time.ticks_ms(), tim)<30000): 17 | img = sensor.snapshot() 18 | for l in img.find_lines(threshold = 4000, theta_margin = 25, rho_margin = 25): 19 | if (min_degree <= l.theta()) and (l.theta() <= max_degree): 20 | img.draw_line(l.line(), color = (255, 0, 0)) 21 | print(l) 22 | lcd.display(img) 23 | img_len = v.record(img) 24 | print("finish") 25 | v.record_finish() 26 | lcd.clear() 27 | -------------------------------------------------------------------------------- /find_rectangles.py: -------------------------------------------------------------------------------- 1 | #find rects 2 | import video, sensor, image, lcd, time 3 | 4 | lcd.init() 5 | sensor.reset() 6 | sensor.set_contrast(1) 7 | sensor.set_gainceiling(16) 8 | sensor.set_pixformat(sensor.RGB565) 9 | sensor.set_framesize(sensor.QVGA) 10 | sensor.run(1) 11 | sensor.skip_frames(30) 12 | v = video.open("/sd/capture_rects.avi", record=1, interval=200000, quality=50) 13 | tim = time.ticks_ms() 14 | 15 | while(time.ticks_diff(time.ticks_ms(), tim)<30000): 16 | img = sensor.snapshot() 17 | for r in img.find_rects(threshold = 18000,roi=(80,60,160,120)): 18 | img.draw_rectangle(r.rect(), color = (255, 0, 0)) 19 | for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) 20 | img.draw_rectangle(80,60,160,120) 21 | img_len = v.record(img) 22 | lcd.display(img) 23 | print("finish") 24 | v.record_finish() 25 | lcd.clear() 26 | --------------------------------------------------------------------------------