66 @license MIT
77 @date 2025.7.30
88'''
9- from enum import auto
9+
1010from 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+
1118import cv2
1219import numpy as np
20+ import os
1321
1422
1523DEBUG = False
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# 初始化摄像头
5973detector = nn .YOLOv5 (model = model_path , dual_buff = True )
6074
6478else :
6579 cam = camera .Camera (detector .input_width (), detector .input_height (), detector .input_format (), buff_num = cam_buff_num )
6680if not auto_awb :
67- cam .awb_mode (camera .AwbMode .Manual )
81+ cam .awb_mode (camera .AwbMode .Manual )
6882 cam .set_wb_gain (awb_gain )
6983cam .constrast (contrast )
7084# cam.set_windowing([448, 448])
7185
72- disp = display .Display ()
73-
7486def 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