logo

瞳孔识别的坐标通过串口发不出去,例程也看了,都试了试,也不好使,新手,求教

2018-10-17 01:43
K
默默不熟
# 瞳孔识别例程
#
# 这个例子展示了如何找到图像中的眼睛后的瞳孔(瞳孔检测)。 该脚本使用
# find_eyes函数来确定应该包含瞳孔的roi的中心点。 它通过基本上找到瞳孔
# 中心的眼睛最黑暗的区域的中心。
#
# 注意:此脚本首先不会检测到脸部,请将其与长焦镜头一起使用。
#import time
#from pyb import UART

#uart = UART(3, 19200)

#while(True):
#   uart.write("Hello World!\r")
#   time.sleep(1000)

import sensor, time, image
from pyb import UART
# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)

# Set resolution to VGA.
sensor.set_framesize(sensor.VGA)

#拉近镜头,使眼睛的更多细节展现在摄像头中。
# Bin/Crop image to 200x100, which gives more details with less data to process
sensor.set_windowing((220, 190, 200, 100))

sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# 默认情况下,这将使用所有阶段,较低的阶段更快但不太准确。
# 加载眼睛的haar算子
eyes_cascade = image.HaarCascade("eye", stages=24)
print(eyes_cascade)

# FPS clock
clock = time.clock()


uart = UART(3, 19200)
iris=[]
while (True):
    clock.tick()
    # Capture snapshot
    img = sensor.snapshot()
    # Find eyes !
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    eyes = img.find_features(eyes_cascade, threshold=0.5, scale=1.5)
    #先利用find_features函数识别人眼。image.find_features(cascade, threshold=0.5, scale=1.5),thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
    
    # Find iris
    #在识别到的人眼中寻找瞳孔。
    
    for e in eyes:
        iris = img.find_eye(e)
        #image.find_eye((x, y, w, h)),find_eye的参数是一个矩形区域,左上顶点为
        #(x,y),宽w,高h,注意(x,y,w,h)是一个元组,不要漏掉括号()。上行代码中
        #的e即代表识别到的眼睛的矩形区域。
        #find_eye的原理是找到区域中颜色最深处的中心。
        img.draw_rectangle(e)
        img.draw_cross(iris[0], iris[1])
        #用矩形标记人眼,用十字形标记瞳孔。
        print(iris)
        uart.write("11111") 
        id=iris.id()
        uart.writechar(id)
    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    # print(clock.fps())
I
网红小智智 星瞳科技

先确定,是串口的问题?还是瞳孔识别的问题?

首先,运行串口的例子,推荐OpenMV 的串口调试扩展板,确定可以串口可以正常发送数据。

然后,确定瞳孔识别确实识别出数据。可以print识别到的瞳孔

K
默默不熟

串口我写的有问题

K
默默不熟

试了好多次都不对,帮看看哪里的问题吧

I
网红小智智 星瞳科技

你确定你是否会看串口的数据,是否会通过示波器或者USB转串口模块,查看串口的数据。

2018-10-17 02:04
K
默默不熟

这个我会,其实就是我不知道怎么将瞳孔的坐标发出去,

id=iris.id()

uart.writechar(id)

我是这么写的,有问题,而且我确定问题出在这里,因为我如果不让串口发送坐标,而是发送

11111是没有问题的我是这么写的串口助手也显示了出来

uart.write("11111")

2018-10-17 02:17
K
默默不熟

我真的很需要你的帮助,下周我就要交毕设了。帮帮忙

2018-10-17 02:33
I
网红小智智 星瞳科技

iris里面id哪来的?瞎猜的?瞎猜的肯定运行不了。

你应该早把报错提示贴出来。

iris[0], iris[1]是两个瞳孔的坐标,下面是代码

瞳孔0的x坐标=iris[0][0]

瞳孔0的y坐标=iris[0][1]

瞳孔1的x坐标=iris[1][0]

瞳孔1的y坐标=iris[1][1]

如果你要发送数字,那就

uart.writechar(瞳孔0的x坐标)

uart.writechar(瞳孔0的y坐标)

uart.writechar(瞳孔1的x坐标)

uart.writechar(瞳孔1的y坐标)

如果你要发送字符串,那就

uart.write(str(瞳孔0的x坐标))

uart.write(str(瞳孔0的y坐标))

uart.write(str(瞳孔1的x坐标))

uart.write(str(瞳孔1的y坐标))

2018-10-17 02:54
K
默默不熟

@sfdw 我刚写了这样写的

iri[0]=iris[0][0]

iri[1]=iris[0][1]

uart.writechar(iri[0])

uart.writechar(iri[1])

还是报错,报错如下

"int" object is not subscriptable

I
网红小智智 星瞳科技

你的语法有问题……你直接a,b,c,d当变量名算了。

K
默默不熟

@kidswong999

我刚写了这样写的

iri[0]=iris[0][0]

iri[1]=iris[0][1]

uart.writechar(iri[0])

uart.writechar(iri[1])

还是报错,报错如下

"int" object is not subscriptable

后来又这样写

x_1=iris[0][0]

Y_1=iris[0][1]

uart.writechar(x_1)

uart.writechar(Y_1)

还是报错,报错如下

"int" object is not subscriptable

两次报错一样,

K
默默不熟

@kidswong999

a=iris[0][0]

b=iris[0][1]

uart.writechar(a)

uart.writechar(b)

这样写也是报错一样的错误

2018-10-18 09:27
P
梦

应该是id=iris.id()这里错了,这个地方要加数据转换,如果坐标是浮点型数据的话这样写,id=“%.2f”%(iris.id())

2018-10-18 09:34
P
梦

我之前颜色识别发送中心坐标的时候,是这样写的,

output=“%.2f,%.2f”%(int(blob[5]),int(blob[6]))

uart.write(output)道理应该差不多,你可以参考一下