【CanMV K230】圆形检测


请添加图片描述
本篇内容:

  1. 什么是圆形检测
  2. 圆形检测应用领域
  3. K230应用(包含相应函数及例程)

B站视频链接:已做成合集 (求去点赞,或者发个弹幕也行呀。C友)
抖音链接:已做成合集(求去点赞,或者发个弹幕也行呀。C友)

什么是圆形检测

圆形检测是计算机视觉和图像处理中的一个常见任务,主要用于识别图像中的圆形物体

圆形检测应用领域

1.工业自动化

在工业生产中,圆形检测用于识别和定位圆形物体,如轴承、齿轮、管道等。这对于质量控制和自动化装配线至关重要。

在这里插入图片描述

2.机器人视觉

机器人视觉系统中的圆形检测可以帮助机器人识别和处理圆形物体,这对于导航、物体操纵和环境交互等功能非常重要。
在这里插入图片描述

3.医学图像分析

在医学领域,圆形检测用于分析X光、CT或MRI图像中的圆形结构,如肿瘤、囊肿或其他病理变化。
在这里插入图片描述

4.目标识别

圆形检测算法可以用于监控系统中,识别和跟踪圆形目标,如车辆、人脸或其他特定的圆形标记。
在这里插入图片描述

5.质量检测

在制造过程中,圆形检测用于确保产品的尺寸和形状符合标准,这对于提高产品质量和一致性至关重要。
在这里插入图片描述

6.研究和开发

在科学研究和新技术开发中,圆形检测可以作为一种工具来分析实验数据或开发新的检测算法。
在这里插入图片描述

K230应用

相关函数

find_circles对象

构造函数

image.find_circles([roi[, x_stride=2[, y_stride=1[, threshold=2000[, x_margin=10[, y_margin=10
                    [, r_margin=10[, r_min=2[, r_max[, r_step=2]]]]]]]]]])

找圆函数。返回一个image.circle圆形对象,该圆形对象有4个值: x, y(圆心), r (半径)和magnitude(量级);量级越大说明识别到的圆可信度越高。

参数说明
roi识别区域(x,y,w,h),未指定则默认整张图片。
threshold阈值。返回大于或等于threshold的圆,调整识别可信度。
x_stride y_stride霍夫变换时跳过x,y像素的量;
x_margin y_margin r_margin控制所检测圆的合并;
r_min r_max:控制识别圆形的半径范围;
r_step控制识别步骤。

使用方法
直接调用该函数。(大部分参数使用默认即可,不支持压缩图像和bayer图像)

官方例程

'''
实验名称:圆形检测
实验平台:01Studio CanMV K230
教程:wiki.01studio.cc
说明:推荐使用320x240以下分辨率,分辨率过大会导致帧率下降。
'''

import time, os, sys

from media.sensor import * #导入sensor模块,使用摄像头相关接口
from media.display import * #导入display模块,使用display相关接口
from media.media import * #导入media模块,使用meida相关接口

try:

    sensor = Sensor(width=1280, height=960) #构建摄像头对象,将摄像头长宽设置为4:3
    sensor.reset() #复位和初始化摄像头
    sensor.set_framesize(width=320, height=240) #设置帧大小,默认通道0
    sensor.set_pixformat(Sensor.RGB565) #设置输出图像格式,默认通道0

    Display.init(Display.ST7701, to_ide=True) #同时使用3.5寸mipi屏和IDE缓冲区显示图像,800x480分辨率
    #Display.init(Display.VIRT, sensor.width(), sensor.height()) #只使用IDE缓冲区显示图像

    MediaManager.init() #初始化media资源管理器

    sensor.run() #启动sensor

    clock = time.clock()

    while True:

        os.exitpoint() #检测IDE中断

        ################
        ## 这里编写代码 ##
        ################
        clock.tick()

        img = sensor.snapshot() #拍摄一张图片

        # 圆形类有 4 个参数值: 圆心(x, y), r (半径)和 magnitude(量级);
        # 量级越大说明识别到的圆可信度越高。
        # `threshold` 参数控制找到圆的数量,数值的提升会降低识别圆形的总数。
        # `x_margin`, `y_margin`, and `r_margin`控制检测到接近圆的合并调节.
        # r_min, r_max, and r_step 用于指定测试圆的半径范围。
        for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin= 10,
                                  r_margin = 10,r_min = 2, r_max = 100, r_step = 2):
            #画红色圆做指示
            img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0),thickness=2)

            print(c) #打印圆形的信息

        #Display.show_image(img) #显示图片

        #显示图片,仅用于LCD居中方式显示
        Display.show_image(img, x=round((800-sensor.width())/2),y=round((480-sensor.height())/2))

        print(clock.fps()) #打印FPS

###################
# IDE中断释放资源代码
###################
except KeyboardInterrupt as e:
    print("user stop: ", e)
except BaseException as e:
    print(f"Exception {e}")
finally:
    # sensor stop run
    if isinstance(sensor, Sensor):
        sensor.stop()
    # deinit display
    Display.deinit()
    os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
    time.sleep_ms(100)
    # release media buffer
    MediaManager.deinit()

在这里插入图片描述

HDMI屏幕使用圆形检测

'''
实验名称:圆形检测测试
实验平台:01Studio CanMV K230
说明:实现图像在HDMI显示器进行圆形检测
测试人:咸鱼浆 2024年9月6日21:02:15
'''

import time, os, sys

from media.sensor import * #导入sensor模块,使用摄像头相关接口
from media.display import * #导入display模块,使用display相关接口
from media.media import * #导入media模块,使用meida相关接口

try:

    sensor = Sensor(width=1280, height=960) #构建摄像头对象,将摄像头长宽设置为4:3
    sensor.reset() #复位和初始化摄像头
    sensor.set_framesize(width=640, height=480) #设置帧大小为(width=640, height=480)太大了就显示不出来了,默认通道0
    sensor.set_pixformat(Sensor.RGB565) #设置输出图像格式,默认通道0

    #使用IDE缓冲区输出图像,显示尺寸和sensor配置一致。
    Display.init(Display.LT9611, to_ide=True)

    MediaManager.init() #初始化media资源管理器

    sensor.run() #启动sensor


    while True:
        os.exitpoint() #检测IDE中断
        ################
        ## 这里编写代码 ##
        ################
        img = sensor.snapshot() #拍摄一张图
        # 圆形类有 4 个参数值: 圆心(x, y), r (半径)和 magnitude(量级);
        # 量级越大说明识别到的圆可信度越高。
        # `threshold` 参数控制找到圆的数量,数值的提升会降低识别圆形的总数。
        # `x_margin`, `y_margin`, and `r_margin`控制检测到接近圆的合并调节.
        # r_min, r_max, and r_step 用于指定测试圆的半径范围。
        for c in img.find_circles(threshold = 3000, x_margin = 10, y_margin= 10,
                                          r_margin = 10,r_min = 2, r_max = 100, r_step = 2):
                    #画红色圆做指示
            img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0),thickness=2)

            print(c) #打印圆形的信息

        Display.show_image(img, x=round((1920-sensor.width())/2),y=round((1080-sensor.height())/2))



        #Display.show_image(img) #显示图片




###################
# IDE中断释放资源代码
###################
except KeyboardInterrupt as e:
    print("user stop: ", e)
except BaseException as e:
    print(f"Exception {e}")
finally:
    # sensor stop run
    if isinstance(sensor, Sensor):
        sensor.stop()
    # deinit display
    Display.deinit()
    os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
    time.sleep_ms(100)
    # release media buffer
    MediaManager.deinit()

在这里插入图片描述
在这里插入图片描述

### K230 on Linux System Specifications and Usage #### Overview of K230 Processor The K230 processor is designed specifically for embedded systems and low-power computing environments. This processor supports various operating systems including Linux, making it versatile for different application scenarios. #### Key Features of K230 on Linux Systems - **Low Power Consumption**: Optimized power management features allow efficient operation under Linux. - **Peripheral Support**: Comprehensive support for peripherals such as USB, UART, SPI, I2C, etc., ensuring compatibility with external devices[^1]. #### Running Linux on K230 To run Linux on the K230 platform, several steps are involved: ```bash # Install necessary packages sudo apt-get update && sudo apt-get install build-essential u-boot-tools device-tree-compiler # Download appropriate kernel sources or pre-built images compatible with K230 wget https://example.com/path/to/kernel-image-for-k230.tar.gz tar -xzvf kernel-image-for-k230.tar.gz # Configure U-Boot environment variables to boot from SD card/flash memory env default -a saveenv ``` For specific configurations like modifying Device Tree Blob (DTB), one can refer to similar processes used in QEMU setups where DTBs are manipulated using `dtc` tools[^3]: ```bash # Convert existing .dtb file into editable .dts format dtc -I dtb -O dts -o k230-custom.dts k230-original.dtb # Edit the generated .dts file according to requirements nano k230-custom.dts # Recompile modified .dts back into binary form (.dtb) dtc -I dts -O dtb -o k230-modified.dtb k230-custom.dts ``` This approach allows customization of hardware interfaces through software configuration without altering physical connections directly. #### Development Tools Integration When developing applications targeting both PowerVR GPUs alongside K230 processors running Linux, leveraging frameworks provided by SDKs becomes crucial. For instance, integrating the PowerVR Graphics SDK facilitates accelerated graphics processing tasks within these platforms[^2]. --related questions-- 1. What are some common challenges faced when porting Linux onto custom ARM-based SoCs? 2. How does the choice between monolithic vs microkernel architectures impact performance on small footprint CPUs like K230? 3. Can you provide guidance on setting up a cross-compilation toolchain tailored for building Linux kernels intended for K230 boards?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咸鱼桨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值