for b in blob: #img.draw_rectangle(b.rect(), color = (250,0,0))#画红色矩形 img.draw_edges(b.min_corners(), color=(0,255,0))#蓝色,绘制边缘线 img.draw_cross(b.cx(),b.cy(),color=(0,255,0))#以圆心画十字 #print("Dia
时间: 2023-06-17 17:08:50 浏览: 112
这段代码是用于处理图像中的目标物体,具体来说,它会对每一个检测到的物体进行以下操作:
1. 画一个红色的矩形框出该物体的位置和大小。
2. 用蓝色绘制该物体的边缘线。
3. 以物体中心为中心,在图像上画一个十字符号。
同时,这段代码中注释掉了一个画红色矩形的语句,如果需要的话可以取消注释来显示红色矩形。
相关问题
img.draw_rectangle(blob.rect())
img.draw_rectangle(blob.rect())是OpenMV中的一个函数调用,用于在图像上绘制一个矩形框,该矩形框的位置和大小由blob.rect()提供。\[1\]这个函数通常用于在色块识别过程中,将识别到的色块框出来以便进行后续处理。在这个函数调用中,blob.rect()返回的是色块的边界框值,即一个矩形数组,包含了矩形框的左上角坐标和宽高信息。通过调用img.draw_rectangle()函数并传入blob.rect()作为参数,就可以在图像上绘制出这个矩形框。\[3\]
#### 引用[.reference_title]
- *1* [【手拉手 带你准备电赛】单色块识别(基于openmv)](https://blog.csdn.net/weixin_54354252/article/details/124226631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [openmv传承(一):自动灰度颜色跟踪示例](https://blog.csdn.net/qq_52528413/article/details/124849833)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
ROI_height = 90 ROI = [0, int(120 - ROI_height), 160, ROI_height] blobs = img.find_blobs([white_thre],roi=ROI) #for blob in blobs: #img.draw_cross(blob.cx(), blob.cy(),(0,0,0)) #img.draw_rectangle(blob.rect()) if blobs: # max_blob不一定是赛道,但是如果如果硬件动作组不偏离中线,应可以直接这么写。 # 应设计多个不同条件下的转弯和移动动作组,使用手掰编程或者改变原有动作的转角即可。 max_blob = find_max(blobs) img.draw_cross(max_blob.cx(), max_blob.cy(),(0,0,0)) img.draw_rectangle(max_blob.rect()) #print(max_blob.cx(), max_blob.cy(), max_blob.rect()[2], max_blob.rect()[3], max_blob.pixels()) #print(max_blob.density(), max_blob.w(), max_blob.h()) blob_white_height_prob = 0.4 # TODO 可调 height_prob = max_blob.h()/ROI_height print('height_prob: '+ str(height_prob) + ' ' + 'density:' + str(max_blob.density())) if flag == 1 and sent_count <= 3: if max_blob.cx()<ROI_height: # TODO 重点改的对象。使用height_prob, max_blob.density(), max_blob.cx()进行赛道的识别 uart.write('8''\r\n') # print('turn left!') led.on() sent_count = sent_count + 1 elif action_cx >=130 : uart.write('3''\r\n') # print('turn right!' led.on() sent_count = sent_count + 1 continue你帮我在代码里修改判断机器狗左转的条件,给我一个更好的代码
根据代码注释和实际情况,我建议你修改以下代码:
```
if flag == 1 and sent_count <= 3:
if max_blob.cx()<ROI_height: # TODO 重点改的对象。使用height_prob, max_blob.density(), max_blob.cx()进行赛道的识别
uart.write('8''\r\n')
# print('turn left!')
led.on()
sent_count = sent_count + 1
elif action_cx >=130 :
uart.write('3''\r\n')
# print('turn right!'
led.on()
sent_count = sent_count + 1
continue
```
修改建议如下:
```
if flag == 1 and sent_count <= 3:
if max_blob.cx() < ROI[0] + ROI[2] / 2 - max_blob.w() / 2:
uart.write('8''\r\n')
# print('turn left!')
led.on()
sent_count += 1
elif max_blob.cx() > ROI[0] + ROI[2] / 2 + max_blob.w() / 2:
uart.write('3''\r\n')
# print('turn right!'
led.on()
sent_count += 1
continue
```
这个修改后的代码使用了max_blob的宽度和ROI来计算赛道的中心线,从而判断机器狗是否需要左转或右转。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)