Example explanation 25-Machine-Learning->nnn_haar_smile_detection smile recognition

(Note: This routine is deleted in firmware 3.6.5 and later. Use TensorFlow Lite instead, which has better results. See video tutorial 42 - Neural Network Target Detection: https://singtown.com/learn/50918/)

Video Tutorial 23 - Smile Detection: https://singtown.com/learn/50049/

Before running this example, please go to OpenMV IDE->Tools->Machine Vision->CNN Network Library and save the corresponding neural network file to the SD memory card of OpenMV.

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

sensor.reset()                          # 复位并初始化传感器。

sensor.set_contrast(2)
sensor.set_pixformat(sensor.RGB565)     # Set pixel format to RGB565
#设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种

sensor.set_framesize(sensor.QVGA)       # 将图像大小设置为QVGA (320x240)

sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)

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

# 加载人脸Haar算子
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

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

    # 捕获快照
    img = sensor.snapshot()

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

    # 检测笑脸
    for r in objects:
        # 调整大小和中心检测区域
        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())

Singtown Technology OpenMV official Chinese document function explanation:

Singtown Technology OpenMV official Chinese document function explanation:

results matching ""

    No results matching ""