Esempio n. 1
0
if __name__ == '__main__':
    url = sys.argv[1]

    cf = Classifier('../models/deploy.prototxt',
                    '../models/pretrained.caffemodel',
                    '../models/mean.binaryproto', '../models/labels.txt')

    quit = False

    def cb_image(img):
        global quit, cf

        if img is None:
            print 'end'
            quit = True
        else:
            pred = cf.predicate(img)
            f = cv2.resize(img, (480, 270))
            cv2.imshow('show', f)
            key = cv2.waitKey(1)
            print pred[0][1].decode('utf-8').encode(
                'gbk') + ' score:', pred[0][2]

    vc = VideoCap(url, (256, 256), "1/3")
    vc.start(cb_image)

    while not quit:
        time.sleep(1.0)

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
Esempio n. 2
0
    if image is None:
        quit = True
        return
   
    if stamp_begin < 0.0:
        stamp_begin = time.time()

    pred = cf.predicate(image)
    stamp = time.time() - stamp_begin

    # FIXME: 使用 'CR:' 作为一条分析结果的前缀,解析起来更方便 :)
    print "CR:", stamp, pr(pred[0][1]), pred[0][2], pr(pred[1][1]), pred[1][2], pr(pred[2][1]), pred[2][2]
    sys.stdout.flush()


def pr(s):
    global curr_encoding
    return s.decode('UTF-8').encode(curr_encoding)


quit = False
vc.start(cb_image)

while not quit:
    time.sleep(0.5)

vc.stop()

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4