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
评论列表
文章目录