完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
程序如下,不知道为什么一运行就报错,内存超了,可以怎么修改呀在保留原本功能的情况下
固件版本 0.4.0 import os, time, gcfrom media.sensor import *from media.display import *from media.media import *from machine import TOUCHfrom Mylib.key import KeyButtonWIDTH, HEIGHT = 800, 480 # 保持原分辨率key = KeyButton()roi1 = (200, 120, 450, 250) # 保持原ROIthreshold = [15, 228] # 保持原阈值black_threshold = [threshold]sensor = Sensor()sensor.reset()sensor.set_framesize(chn=CAM_CHN_ID_0, width=WIDTH, height=HEIGHT)sensor.set_pixformat(Sensor.RGB565, chn=CAM_CHN_ID_0)sensor.set_framesize(chn=CAM_CHN_ID_1, width=WIDTH, height=HEIGHT)sensor.set_pixformat(Sensor.RGB565, chn=CAM_CHN_ID_1)Display.init(Display.ST7701, width=WIDTH, height=HEIGHT, to_ide=True)MediaManager.init()sensor.run()tp = TOUCH(0)status_text = ""exit_text = "按按键退出"try: while True: os.exitpoint() gc.collect() # 检查退出条件 if key.is_rising_edge(): print("退出黑色胶带检测") break # 通道1用于识别处理 img_roi = sensor.snapshot(chn=CAM_CHN_ID_1) img_roi.to_grayscale(inplace=True) # 通道0用于显示 display_img = sensor.snapshot(chn=CAM_CHN_ID_0) # 图像处理(使用原地操作) img_roi.binary(black_threshold, inplace=True) img_roi.dilate(1, inplace=True) img_roi.erode(1, inplace=True) # 检测外轮廓矩形 outer_rects = [] if roi1 is not None and isinstance(roi1, (tuple, list)) and len(roi1) == 4: outer_rects = img_roi.find_rects(roi=roi1) else: outer_rects = img_roi.find_rects() outer_rect = None inner_rect = None if outer_rects: # 筛选最大的外矩形 outer_rect = max(outer_rects, key=lambda r: r.w() * r.h()) x, y, w, h = outer_rect.rect() display_img.draw_rectangle(x, y, w, h, color=(255, 0, 0), thickness=2) # 尝试检测内部矩形 padding = 3 min_x, max_x = x + padding, x + w - padding min_y, max_y = y + padding, y + h - padding if min_x < max_x and min_y < max_y: inner_rects = img_roi.find_rects(roi=(min_x, min_y, max_x - min_x, max_y - min_y)) if inner_rects: # 筛选最大的内矩形 inner_rect = max(inner_rects, key=lambda r: r.w() * r.h()) ix, iy, iw, ih = inner_rect.rect() display_img.draw_rectangle(ix, iy, iw, ih, color=(0, 0, 255), thickness=2) # 更新状态文本 if outer_rect and inner_rect: status_text = "胶带检测中: 已识别内外矩形" status_color = (0, 255, 0) elif outer_rect: status_text = "胶带检测中: 仅识别外矩形" status_color = (255, 255, 0) else: status_text = "胶带检测中: 未识别" status_color = (255, 0, 0) # 绘制状态信息 display_img.draw_string_advanced(10, 10, 20, status_text, status_color) # 绘制退出提示 display_img.draw_string_advanced(WIDTH - 200, HEIGHT - 30, 18, exit_text, (255, 255, 255)) # 显示图像 Display.show_image(display_img) del display_img del img_roi gc.collect() time.sleep_ms(50)except KeyboardInterrupt: print("程序被用户中断")except BaseException as e: print(f"[ERROR] 出现异常: {e}")finally: # 释放资源 try: sensor.stop() Display.deinit() MediaManager.deinit() except: pass gc.collect() print("资源已释放") 你好,可以尝试降低做图像运算的图像分辨率 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
AI_cube训练模型得到了npy文件,没有kmodel文件
772 浏览 0 评论
请问K230 V3.0版本烧录固件和使用IDE到底是烧录哪个啊?
739 浏览 0 评论
443浏览 4评论
AI Cube进行yolov8n模型训练,创建项目目标检测时显示数据集目录下存在除标注和图片外的其他目录如何处理?
463浏览 3评论
autodl算力云在.pt转换onnx文件时正常,但onnx转.kmodel文件时报错,为什么?
552浏览 2评论
如何在大核rtt上把kd_mpi_vicap_start_stream三个摄像头各自出的流拼成一个流呢?
165浏览 2评论
564浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 15:07 , Processed in 0.638134 second(s), Total 73, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
276
