目录
  • 基于openmv的图像识别
  • 一、数字识别

基于openmv的图像识别

openmv简介

什么是openmv

openmv是由美国克里斯团队基于micropython发起的开源机器视觉项目,目的是创建低成本,可扩展,使用python驱动的机器视觉模块。openmv搭载了micropython解释器,使其可以在嵌入式端进行python开发,关于micropython可以参照我之前的博客专栏:micropython. openmv基于32位,arm cortex-m7内核的openmv-h7, 并结合各种摄像头,可以进行多种机器视觉应用的实现,比如人脸检测,物体分类等。

openmv是一个开源,低成本,功能强大的机器视觉模块,以stm32f427cpu为核心,集成了ov7725摄像头芯片,在小巧的硬件模块上,用c语言高效地实现了核心机器视觉算法,提供python编程接口 。同时 openmv也是一个可编程的摄像头,通过python语言可实现你想要的逻辑。而且摄像头本身也内置了一些图像处理的算法,使用起来也更加的方便,仅需要写一些简单的python代码,即可轻松的完成各种机器视觉相关的任务。在此,我们通过openmv实现了数字识别。

在打开openmv摄像头链接电脑时,会弹出让你升级的窗口

这时切忌一定要选择cancel键,

不能选择升级!!!

不能选择升级!!!

不能选择升级!!!

然后在进行下一步的操作

openmv中文入门视频教程

一、数字识别

数字识别的基础是需要配置使用ncc模板匹配。通过ncc模板的匹配可把

需要识别的数字模板图片保存到sd卡中,然后可进行下一步的识别。

1、可以通过打开模板匹配的历程来直接打开代码进行使用

2、如果运行出现这个窗口就说明没有保存模板图片

所以这时就需要创建一个模板图片:创建模板图片的详细视频教程

创建一个模板图片首先要打开一个helloworld历程文件

然后在helloworld历程文件中进行匹配0~9这样的基本数字,对这些数字进

行一一截取,用它们来作为我们的模板图片。

在右边的frame buffer框中进行截取,注意:不要点zoom,因为zoom展示

的是放大后的效果,在识别时可能会导致失帧。

然后点击左键选出一个框(如图所示)

选完框后点击右键选择save image selection to pc

最后把截取的数字图片进行保存,一定要保存到openmv的sd卡中,保存的文件名可自己

定义

3、把template.pgm改为你创建的模板图片的名称

(注意:模板图片的格式一定要是pgm的格式,转换格式可以在

https://convertio.co/zh/bmp-pgm/网站直接进行转换)

4、改完之后就可以运行

下面展示一些 有关数字识别的代码。

此代码为源代码,可根据自己的需求在上面进行改动。

代码来源:数字识别代码,可直接引用并修改

# 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 enviorments
# 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 reamin to show
# that the functionality exists, but, in its current state is inadequate.

import time, sensor, image
from image import search_ex, 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.
template8 = image.image("/8.pgm")
template9 = image.image("/9.pgm")
clock = time.clock()

# 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 8= img.find_template(template8, 0.70, step=4, search=search_ex) #, roi=(10, 0, 60, 60))
    if r8:
        img.draw_rectangle(r8)
   r 9= img.find_template(template9, 0.70, step=4, search=search_ex) #, roi=(10, 0, 60, 60))
    if r9:
        img.draw_rectangle(r9)

    print(clock.fps())

运行的结果如图所示

到此这篇关于基于openmv的图像识别之数字识别的文章就介绍到这了,更多相关openmv图像识别内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!