openMV_瞳孔识别轨迹记录_学习笔记


前言

openMVCam M7实现人眼的识别以及轨迹记录 此篇仅为菜鸡个人笔记 若存在错误希望各位大佬指正


一、什么是openMV?

OpenMV是一个开源,低成本,功能强大的机器视觉模块。
图片来自网络
本文全程使用openMVCamM7为基础配合openMV的IDE进行学习
openMVCamM7 使用ARM CortexM7处理器,216 MHz ,512KB RAM,2 MB flash. 所有的 I/O 引脚输出 3.3V 并且 5V 耐受。

二、使用步骤

1.安装好openMV IDE

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

下载地址:https://openmv.io/pages/download.

这个安装很简单不做记录(注意选择和自己电脑相符的下载地址)

2.连接openMV与IDE

用数据线连接openMV和电脑
在设备管理器(右键 开始 )里可以看见端口

然后在IDE 里点击连接

三、基本思路

1、流程图

Created with Raphaël 2.2.0 开始 设置阈值 摄像头捕捉瞳孔 成功识别 标记出瞳孔中心并框选瞳孔 采集当前图像,并进行储存 获取瞳孔位置信息 在空白图片中标记位置 连接各个标记点 判断阈值 存储空白图片 结束 yes no yes no

2、基本思路

利用openmv对瞳孔的识别

四、代码示例

openMV可使用MicroPython进行程序编写,以下为MicroPython代码注释

	import sensor,time,image,lcd,pyb 
import导入所需要使用的第三方库
sensor感光元件(摄像头)
time记录时间
image处理图像
lcdlcd屏幕(openMV可通过长脚引母连接lcd屏幕)
pybI/O引脚

#以上功能仅为当前项目中所使用到的功能,这些库能做的远远不止这些

sensor.reset()  #相机传感器初始化
sensor.set_contrast(3)#设置相机图像对比度
sensor.set_gainceiling(16)#设置相机图像增益上限
sensor.set_framesize(sensor.VGA)#设置相机模块的帧大小
sensor.set_windowing((220, 190, 200, 100))#将相机的分辨率设置为当前分辨率的子分辨率
sensor.set_pixformat(sensor.GRAYSCALE)#设置相机模块的像素模式
lcd.init()#LCD屏幕初始化
p6=pyb.Pin("P6",pyb.Pin.OUT_PP)#设置引脚6为输出
p6.high()#p6输出高电频
eyes_cascade = image.HaarCascade("eye", stages=24)#利用HaarCascade加载haar-eye模块
n = 20 #设置照片张数
x1 = 0
while (n):
    clock.tick() #
    img0 = sensor.snapshot() #将当前图像保存为img0
    eyes = img0.find_features(eyes_cascade, threshold=0.5, scale=1.5) #加载
    lcd.display(sensor.snapshot())#设置lcd屏
 for e in eyes:   
        iris = img0.find_eye(e)
        #img0.draw_rectangle(e)
        img0.draw_cross(iris[0], iris[1])
        img0.draw_circle(iris[0], iris[1], 20, color=(255,0,0),fill = False)
        img0.save("singtown/s%s.pgm" %  n )
        img = image.Image("data.pgm")
        img.draw_circle(iris[0], iris[1], 1, color=(255,0,0),fill = True)
 if (n % 2) == 0:
            if x1 != 0:
                x0=x1
                y0=y0
                x0=iris[0]
                y0=iris[1]
                img.draw_line(x0, y0, x1, y1, color=(255,0,0) ,thickness=1)
            else:
                x0=iris[0]
                y0=iris[1]
        else:
            x1=iris[0]
            y1=iris[1]
            img.draw_line(x0, y0, x1, y1, color=(255,0,0) ,thickness=1)

       
if n==20:
            img.draw_circle(iris[0], iris[1], 1, color=(0,0,255),fill = True)
        if  n==0:
            img.draw_circle(iris[0], iris[1], 1, color=(0,255,0),fill = True)
            break
img.save("data.pgm")#保存当前笔迹
        n=n-1
  print(clock.fps())输出fps
p6.low()#关闭灯光

以下为源码

# Tris_Detation - By: Ash、Scum - 周二 8月 4 2020

import sensor,time,image,lcd,pyb 

sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((220, 190, 200, 100))
sensor.set_pixformat(sensor.GRAYSCALE)
lcd.init()

p6=pyb.Pin("P6",pyb.Pin.OUT_PP)

p6.high()

eyes_cascade = image.HaarCascade("eye", stages=24)

print(eyes_cascade)

clock = time.clock()

n = 20
x1 = 0
while (n):
    clock.tick()

    img0 = sensor.snapshot()

    eyes = img0.find_features(eyes_cascade, threshold=0.5, scale=1.5)

    lcd.display(sensor.snapshot())

    for e in eyes:
        iris = img0.find_eye(e)
        #img0.draw_rectangle(e)
        img0.draw_cross(iris[0], iris[1])
        img0.draw_circle(iris[0], iris[1], 20, color=(255,0,0),fill = False)
        img0.save("singtown/s%s.pgm" %  n )
        img = image.Image("data.pgm")
        img.draw_circle(iris[0], iris[1], 1, color=(255,0,0),fill = True)

        if (n % 2) == 0:
            if x1 != 0:
                x0=x1
                y0=y0
                x0=iris[0]
                y0=iris[1]
                img.draw_line(x0, y0, x1, y1, color=(255,0,0) ,thickness=1)
            else:
                x0=iris[0]
                y0=iris[1]
        else:
            x1=iris[0]
            y1=iris[1]
            img.draw_line(x0, y0, x1, y1, color=(255,0,0) ,thickness=1)

        if n==20:
            img.draw_circle(iris[0], iris[1], 1, color=(0,0,255),fill = True)
        if  n==0:
            img.draw_circle(iris[0], iris[1], 1, color=(0,255,0),fill = True)
            break

        img.save("data.pgm")
        n=n-1

    print(clock.fps())

p6.low()

代码可以实现自动识别人眼并自动标识瞳孔中心以及瞳孔
在这里插入图片描述
并将保存图片保存在sd卡中为pgm文件(用ps打开)
在这里插入图片描述

与此同时记录每一次瞳孔位置将其轨迹在空白图片中(空白图片需手动更新)
在这里插入图片描述

五、视频演示

链接: https://www.bilibili.com/video/BV1YV411y7rD/.
https://www.bilibili.com/video/BV1YV411y7rD/

自制眼动轨迹仪演示

  • 9
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值