logo

关于自己训练的xml文件运行的问题

2018-03-21 16:14
5
wang123

我用我自己训练出来的xml 文件,转成.cascade 文件后,在程序里改了路径运行后,运行到feature函数时,图像只要一动的频率快了,程序就自己退出来了,我这个是啥问题?

是我.cascade文件的问题还是feature函数的问题?

2018-03-21 20:56
X
Yuan

请附上详细的操作步骤和代码,这样我们才能重现问题

2018-03-21 21:33
5
wang123

下面是我的代码:

import sensor, time, image, uio

import sys,os,uos



iiii = {0};
# Reset sensor
sensor.reset()

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

# Set resolution to VGA.
sensor.set_framesize(sensor.VGA)
sensor.set_brightness(-3)

# 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
# By default this will use all stages, lower satges is faster but less accurate.
#eyes_cascade = image.HaarCascade("eye", stages=24)
#eyes_cascade = image.HaarCascade("frontalface.cascade", stages=24)
eyes_cascade = image.HaarCascade("haarcascade_eye.cascade", stages=24)

print(eyes_cascade)
#print("frontalface")
print("haarcascade_eye")
# FPS clock
clock = time.clock()



while (True):
    clock.tick()
    # Capture snapshot
    img = sensor.snapshot()

    time.sleep(250)




    # 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.1, scale_factor=500)
        # Find iris
    for e in eyes:

        iris = img.find_eye(e)

        img.draw_rectangle(e)


        img.draw_cross(iris[0], iris[1])



    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    #print(eyes_cascade)
2018-03-21 21:38
5
wang123

我先用openmv_cascade.py将自己训练出来的xml文件转成cascade文件,然后将文件添加到根目录里面,

再将“eye”改成文件名,如下:

eyes_cascade = image.HaarCascade("haarcascade_eye.cascade", stages=24)

然后运行程序时,画面没有检测到目标时程序正常运行,只要一检测到目标,程序就自己退出来了,我觉得是下面这个函数检测的问题,

eyes = img.find_features(eyes_cascade, threshold=0.1, scale_factor=500)

2018-03-21 22:03
5
wang123

@yuan 请问大神 我的这个问题在哪?

2018-03-21 22:16
X
Yuan

@wang123 我不清楚你的具体cascade文件是什么,我把文件换成了内置的eye,用你的代码,识别没有问题。

你可以把你的文件一起发上来,我测试一下。

2018-03-21 22:25
5
wang123

@yuan 恩 现在不行 我明天再发

2018-03-22 08:24
5
wang123

@yuan [链接文本](链接:https://pan.baidu.com/s/1Igr8GGKff_r-rmGJiOg8gQ 密码:s5th)

2018-03-22 12:56
X
Yuan

试了一下你的文件,一运行的确会退出来。

会不会是因为你训练的文件太大了?

2018-03-22 15:35
5
wang123

我也用过openmv源码里面自带的xml文件训练,结果还是这样

2018-03-22 16:35
5
wang123

@yuan 我把自己训练的xml文件弄小之后还是这样,但是我用openmv自带的cascade文件就没错,源码自带的cascade文件有啥特别的吗?自带的cascade是用哪个xml 文件转化的?

2018-03-23 12:25
X
Yuan

OpenMV用户自己训练文件转化的话,是使用OpenMV在github中提供的xml文件转化。

你这个问题,我也不太清楚了。

2018-03-24 15:53
5
wang123

@yuan en 谢谢大神 能给我发个链接吗?就是xml 文件转化后能用的,我试了好多网上的也还是不能用