示例#1
0
def sampling(user, cnt, interval=500):
    # maxFace = THRESHOLD_SIZE_MIN
    maxFace = samplingSkip(SAMPLING_SKIP)
    clearUser(user)
    for n in range(cnt):
        #红灯亮
        pyb.LED(RED_LED_PIN).on()
        sensor.skip_frames(
            time=interval)  # Give the user time to get ready.等待3s,准备一下表情。

        #红灯灭,蓝灯亮
        pyb.LED(RED_LED_PIN).off()
        pyb.LED(BLUE_LED_PIN).on()

        #保存截取到的图片到SD卡
        photoDpath = "photo/%s" % (user)
        photoFpath = photoDpath + "/%s.bmp" % (n)
        try:
            os.listdir(photoDpath)
        except:
            os.mkdir(photoDpath)

        face = None
        img = None

        while not face:
            img = sensor.snapshot()
            face = facsTest(img)
            checkDisplay(img)
            if face:
                size = face[2] * face[3]
                if size < maxFace * 0.88:
                    face = None
                elif size > maxFace:
                    maxFace = maxFace * 0.35 + size * (1 - 0.35)

        img.save(photoFpath, face)  # or "example.bmp" (or others)

        descDpath = "desc/%s" % (user)
        descFpath = descDpath + "/%s.lbp" % (n)
        try:
            os.listdir(descDpath)
        except:
            os.mkdir(descDpath)

        d0 = img.find_lbp(face)
        image.save_descriptor(d0, descFpath)

        pyb.LED(BLUE_LED_PIN).off()
        print(descFpath)
    print("finished!")
def unittest(data_path, temp_path):
    import image, os
    # Load image and find keypoints
    img = image.Image(data_path+"/graffiti.pgm", copy_to_fb=True)
    kpts1 = img.find_keypoints(max_keypoints=150, threshold=20, normalized=False)

    # Save descriptor
    image.save_descriptor(kpts1, temp_path+"/graffiti2.orb")

    # Load descriptor
    kpts2 = image.load_descriptor(temp_path+"/graffiti2.orb")

    # Match keypoints
    match = image.match_descriptor(kpts1, kpts2, threshold=85)
    return  (match.cx()     == 138 and match.cy()     == 117 and \
             match.x()      == 36  and match.y()      == 34  and \
             match.w()      == 251 and match.h()      == 167 and \
             match.count()  == 150 and match.theta()  == 0)
示例#3
0
def unittest(data_path, temp_path):
    import image, os
    # Load image and find keypoints
    img = image.Image(data_path + "/graffiti.pgm", copy_to_fb=True)
    kpts1 = img.find_keypoints(max_keypoints=150,
                               threshold=20,
                               normalized=False)

    # Save descriptor
    image.save_descriptor(kpts1, temp_path + "/graffiti2.orb")

    # Load descriptor
    kpts2 = image.load_descriptor(temp_path + "/graffiti2.orb")

    # Match keypoints
    match = image.match_descriptor(kpts1, kpts2, threshold=85)
    return  (match.cx()     == 138 and match.cy()     == 117 and \
             match.x()      == 36  and match.y()      == 34  and \
             match.w()      == 251 and match.h()      == 167 and \
             match.count()  == 150 and match.theta()  == 0)
示例#4
0
# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((320, 240))
sensor.set_pixformat(sensor.GRAYSCALE)

sensor.skip_frames(30)
sensor.set_auto_gain(False, value=100)

FILE_NAME = "desc"
img = sensor.snapshot()
# NOTE: See the docs for other arguments
# NOTE: By default find_keypoints returns multi-scale keypoints extracted from an image pyramid.
kpts = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)

if (kpts == None):
    raise (Exception("Couldn't find any keypoints!"))

image.save_descriptor(kpts, "/%s.orb" % (FILE_NAME))
img.save("/%s.pgm" % (FILE_NAME))

img.draw_keypoints(kpts)
sensor.snapshot()
time.sleep(1000)
raise (Exception("Done! Please reset the camera"))
# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((320, 240))
sensor.set_pixformat(sensor.GRAYSCALE)

sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False, value=100)

FILE_NAME = "desc"
img = sensor.snapshot()
# NOTE: See the docs for other arguments
# NOTE: By default find_keypoints returns multi-scale keypoints extracted from an image pyramid.
kpts = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)

if (kpts == None):
    raise(Exception("Couldn't find any keypoints!"))

image.save_descriptor(kpts, "/%s.orb"%(FILE_NAME))
img.save("/%s.pgm"%(FILE_NAME))

img.draw_keypoints(kpts)
sensor.snapshot()
time.sleep(1000)
raise(Exception("Done! Please reset the camera"))