yolov2_demo.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:yolov2_tensorflow 作者: biyaa 项目源码 文件源码
def detect(img):
    #print img
    img_h, img_w, _ = img.shape
    inputs = cv2.resize(img, (cfg.image_size, cfg.image_size)).astype(np.float32)

    #inputs = cv2.cvtColor(inputs, cv2.COLOR_BGR2RGB).astype(np.float32)
    inputs = (inputs / 255.0) 
    inputs = np.reshape(inputs, (1, cfg.image_size, cfg.image_size, 3))
    #inputs = np.transpose(inputs,(0,3,2,1))

    result = detect_from_cvmat(inputs)[0]

    for i in range(len(result)):
        left = (result[i][1] - result[i][3]/2)*img_w
        right = (result[i][1] + result[i][3]/2)*img_w
        top = (result[i][2] - result[i][4]/2)*img_h
        bot = (result[i][2] + result[i][4]/2)*img_h
        result[i][1] = left if left>0 else 0
        result[i][2] = right if right<img_w-1 else img_w-1
        result[i][3] = top if top>0 else 0
        result[i][4] = bot if bot<img_h-1 else img_h-1

    print "result:", result
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号