例程讲解25-Machine-Learning->nnn_haar_smile_detection笑脸识别

视频教程23 - 笑脸检测:https://singtown.com/learn/50049/

运行此例程前,请先在OpenMV IDE->工具->机器视觉->CNN网络库 中,将相应的神经网络文件保存到OpenMV的SD内存卡中哦。

# 笑脸识别例程
import sensor, time, image, os, nn

sensor.reset()                          # Reset and initialize the sensor.
sensor.set_contrast(2)
sensor.set_pixformat(sensor.RGB565)     # Set pixel format to RGB565
sensor.set_framesize(sensor.QVGA)       # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)

# 加载微笑检测网络
net = nn.load('/smile.network')

# Load Face Haar Cascade
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

# FPS clock
clock = time.clock()
while (True):
    clock.tick()

    # Capture snapshot
    img = sensor.snapshot()

    # 识别人脸
    objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)

    # 检测笑脸
    for r in objects:
        # Resize and center detection area
        r = [r[0]+10, r[1]+25, int(r[2]*0.70), int(r[2]*0.70)]
        img.draw_rectangle(r)
        out = net.forward(img, roi=r, softmax=True)
        img.draw_string(r[0], r[1], ':)' if (out[0] > 0.8) else ':(', color=(255), scale=2)

    print(clock.fps())

星瞳科技OpenMV官方中文文档函数讲解:

星瞳科技OpenMV官方中文文档函数讲解:

results matching ""

    No results matching ""