Skip to content

Commit d003619

Browse files
committed
optimize doc and load for find rect circle app
1 parent 74b557e commit d003619

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
model/*
2+

projects/demo_diansai_2025_E_circle_track/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
2025 电赛 E 题 MaixPy 实现
22
======
33

4+
## 题目
5+
6+
这是对 《2025 电赛 E 题 简易自行瞄准装置》的一个实现,官方题目在[这里](https://res.nuedc-training.com.cn/topic/2025/topic_from_30.html)
7+
48
## 效果
59

610
演示视频看[Bilibili](https://www.bilibili.com/video/BV18m8CzNEqT/)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
id: find_rect_circle
2+
name: Find rectangle circle
3+
version: 1.0.0
4+
author: Neucrack
5+
icon: assets/rectangle_circle.png
6+
desc: Find circle in black rectangle A4 paper
7+
files:
8+
- assets
9+
- model
10+
- app.yaml
11+
- main.py
1.63 KB
Loading

projects/demo_diansai_2025_E_circle_track/main.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
@license MIT
77
@date 2025.7.30
88
'''
9-
from enum import auto
9+
1010
from maix import camera, display, image, nn, app, time
11+
disp = display.Display()
12+
img = image.Image(disp.width(), disp.height())
13+
msg = "Loading ..."
14+
size = image.string_size(msg, scale = 1.5, thickness=2)
15+
img.draw_string((img.width() - size.width()) // 2, (img.height() - size.height()) // 2, msg, scale=1.5, thickness=2)
16+
disp.show(img)
17+
1118
import cv2
1219
import numpy as np
20+
import os
1321

1422

1523
DEBUG=False
@@ -55,6 +63,12 @@
5563

5664
###################################################################################
5765

66+
if not os.path.exists(model_path):
67+
model_path1 = "model/model_3356.mud"
68+
if not os.path.exists(model_path1):
69+
print(f"load model failed, please put model in {model_path}, or {os.path.getcwd()}/{model_path1}")
70+
model_path = model_path1
71+
5872
# 初始化摄像头
5973
detector = nn.YOLOv5(model=model_path, dual_buff = True)
6074

@@ -64,13 +78,11 @@
6478
else:
6579
cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format(), buff_num=cam_buff_num)
6680
if not auto_awb:
67-
cam.awb_mode(camera.AwbMode.Manual)
81+
cam.awb_mode(camera.AwbMode.Manual)
6882
cam.set_wb_gain(awb_gain)
6983
cam.constrast(contrast)
7084
# cam.set_windowing([448, 448])
7185

72-
disp = display.Display()
73-
7486
def find_laser_point(img, original_img):
7587
'''
7688
随便写的,有需要请自己修改算法
@@ -87,7 +99,7 @@ def find_laser_point(img, original_img):
8799
max_s = s
88100
max_b = b
89101
if DEBUG:
90-
laser_binary = img.binary(ths, copy=True)
102+
laser_binary = img.binary(ths, copy=True)
91103
original_img.draw_image(original_img.width() - laser_binary.width(), original_img.height() - laser_binary.height(), laser_binary)
92104
return max_b
93105

@@ -227,7 +239,7 @@ def debug_time(msg):
227239
# heightB = np.linalg.norm(tl - bl)
228240
# maxHeight = int(max(heightA, heightB) * img_ai_scale[1] * std_scale)
229241
# print(maxWidth, maxHeight)
230-
242+
231243

232244
maxWidth = std_res[0]
233245
maxHeight = std_res[1]
@@ -245,7 +257,7 @@ def debug_time(msg):
245257
[0, maxHeight - 1]], dtype="float32")
246258
M = cv2.getPerspectiveTransform(rect, dst)
247259
M_inv = np.linalg.inv(M)
248-
img_std_cv = cv2.warpPerspective(img_cv, M, (maxWidth, maxHeight))
260+
img_std_cv = cv2.warpPerspective(img_cv, M, (maxWidth, maxHeight))
249261
img_std = image.cv2image(img_std_cv, False, False)
250262
debug_time("get std img")
251263

@@ -380,7 +392,7 @@ def debug_time(msg):
380392
print("detected circle too small", img_std.width(), img_std.height())
381393
else:
382394
print(minW, minH, "rect not valid")
383-
395+
384396
# 绘制路径
385397
if approx is not None:
386398
cv2.drawContours(crop_ai_cv, [approx], -1, (255, 255, 255), 1)

0 commit comments

Comments
 (0)