1,040
社区成员
发帖
与我相关
我的任务
分享这是我参加朝闻道知识分享大赛的第十一篇文章
OpenMV是由美国克里斯团队基于MicroPython发起的开源机器视觉项目,OpenMV搭载了MicroPython解释器,使其可以在嵌入式端进行python开发,OpenMV基于32位,ARM Cortex-M7内核的OpenMV-H7, 并结合各种摄像头,可以进行多种机器视觉应用的实现,比如人脸检测,物体分类等。
然后这里介绍两款基础OpenMV的相关信息
上面简单介绍了openmv基本信息,那么它可以应用在哪呢?
可以与无人机相结合

可以运用在电子设计大赛中

除了上述案例外,2022全国大学生电子设计大赛小车识别数字以及2023全国大学生电子设计大赛云台追踪激光也运用到了openmv。
上面看到了许多OpenMV的应用,现在我们就来进行一次OpenMV使用的简单举例。
本次通过OpenMV完成模版匹配,模板匹配就是在给定的图片中,查找和模板最相似的区域,算法的输入包括模板和图片,通过不断移动模板图片,计算其与图片对应区域匹配度,将匹配度最高区域选择为最终结果。
现在我们可以看看模版匹配相关代码
# Template Matching Example - Normalized Cross Correlation (NCC)
#
# This example shows off how to use the NCC feature of your OpenMV Cam to match
# image patches to parts of an image... expect for extremely controlled environments
# NCC is not all to useful.
#
# WARNING: NCC supports needs to be reworked! As of right now this feature needs
# a lot of work to be made into somethin useful. This script will remain to show
# that the functionality exists, but, in its current state is inadequate.
import time
import sensor
import image
import math
from image import SEARCH_EX
from pyb import UART
# from image import SEARCH_DS
# Reset sensor
sensor.reset()
# Set sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# Max resolution for template matching with SEARCH_EX is QQVGA
sensor.set_framesize(sensor.QQVGA)
# You can set windowing to reduce the search image.
# sensor.set_windowing(((640-80)//2, (480-60)//2, 80, 60))
sensor.set_pixformat(sensor.GRAYSCALE)
# Load template.
# Template should be a small (eg. 32x32 pixels) grayscale image.
template = image.Image("5.pgm")
clock = time.clock()
uart = UART(3, 115200)
# Run template matching
while True:
clock.tick()
img = sensor.snapshot()
# find_template(template, threshold, [roi, step, search])
# ROI: The region of interest tuple (x, y, w, h).
# Step: The loop step used (y+=step, x+=step) use a bigger step to make it faster.
# Search is either image.SEARCH_EX for exhaustive search or image.SEARCH_DS for diamond search
#
# Note1: ROI has to be smaller than the image and bigger than the template.
# Note2: In diamond search, step and ROI are both ignored.
r = img.find_template(
template, 0.70, step=4, search=SEARCH_EX
) # , roi=(10, 0, 60, 60))
if r:
img.draw_rectangle(r)
print(clock.fps())
这里的 “emplate = image.Image("5.pgm")” 就是识别sd卡中5.pgm图片,识别到相同图片即可框出。
OpenMV的应用非常广泛,尤其最近两年全国大学生电子设计大赛中加重了摄像头模块的使用,这也是现在智能化发展的趋势,本次只是举了一个简单的例子,接下来我们将讲解OpenMV与stm32之间的通信。
本次知识分享也到此结束