局部二值模式(LBP)示例
import csi
import time
import image
csi0 = csi.CSI()
csi0.reset()
csi0.contrast(1)
csi0.gainceiling(16)
csi0.framesize(csi.HQVGA)
csi0.pixformat(csi.GRAYSCALE)
face_cascade = image.HaarCascade("/rom/haarcascade_frontalface.cascade", stages=25)
print(face_cascade)
for i in range(0, 30):
img = csi0.snapshot()
img.draw_string((0, 0), "Please wait...")
d0 = None
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
objects = img.find_features(face_cascade, threshold=0.5, scale=1.25)
if objects:
face = objects[0]
d1 = img.find_lbp(roi=face)
if d0 is None:
d0 = d1
else:
dist = image.match_descriptor(d0, d1)
img.draw_string((0, 10), "Match %d%%" % (dist))
img.draw_rectangle(face)
img.draw_string((0, 0), "FPS:%.2f" % (clock.fps()))