在OpenMV中,画出识别色块后画出的矩形框中心,生成代码
时间: 2023-12-12 09:02:35 浏览: 131
以下是在OpenMV中识别颜色块并画出矩形框中心的示例代码:
```python
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
# 设置要识别的颜色范围
red_threshold = (30, 100, 15, 127, 15, 127)
while(True):
img = sensor.snapshot()
# 寻找符合颜色范围的区域
blobs = img.find_blobs([red_threshold])
# 如果找到了区域
if blobs:
# Draw rectangles around blobs
for blob in blobs:
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print("目标中心坐标:({0}, {1})".format(blob.cx(), blob.cy()))
time.sleep(100)
```
上述代码中,我们通过 `find_blobs` 函数寻找符合颜色范围的区域,然后使用 `draw_rectangle` 函数在该区域周围画出矩形框,并使用 `draw_cross` 函数在该框中心画出十字形。同时,我们还在控制台输出了该中心坐标。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)