python - 计算两个 TensorFlow 检测到的对象之间的欧几里得距离
问题描述
我正在创建一个程序,该程序可以使用 opencv 和 tensorflow 检测何时举手。我以前的方法是使用 HAAR-Cascade,它给出了“好的”结果,但我想探索使用 tensorflow 的可能性。
我之前使用 HAAR-Cascade 和 opencv 的方法是通过计算人脸中心和手心之间的欧几里德距离,我使用 cvRectangle 来理解它,但是在 tensorflow 的情况下不使用 cvRectangle 以及如何告诉程序被检测到的对象是手还是脸。
哈尔方法:
#detect faces and draw bounding box
face_gray = cv2.cvtColor(masked_img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(face_gray, 1.3, 5)
for (x_f,y_f,w_f,h_f) in faces:
cv2.rectangle(masked_img,(x_f,y_f),(x_f+w_f,y_f+h_f),(0,255,0),2)
cv2.rectangle(sourceImage,(x_f,y_f),(x_f+w_f,y_f+h_f),(0,255,0),2)
#detect hands and draw bounding box
hands = hand_cascade.detectMultiScale(masked_img, 1.3, 5)
for (x_h,y_h,w_h,h_h) in hands:
cv2.rectangle(masked_img,(x_h,y_h),(x_h+w_h,y_h+h_h),(0,0,255),2)
cv2.rectangle(sourceImage,(x_h,y_h),(x_h+w_h,y_h+h_h),(0,0,255),2)
#detect hand-raising
#euclidean distance between center of face and center of hand must be less than 2 times the width of face
#if fulfilled draw another bounding box
for (x_f,y_f,w_f,h_f) in faces:
for (x_h,y_h,w_h,h_h) in hands:
dx = math.fabs((x_f+0.5*w_f)-(x_h+0.5*w_h))
dy = math.fabs((y_f+0.5*h_f)-(y_h+0.5*h_h))
if (dx <= 2*w_f):
if dy <= 2*h_f:
cv2.rectangle(masked_img,(x_f-w_f,y_f-w_f),(x_f+2*w_f,y_f+2*h_f),(255,0,0,),2)
cv2.rectangle(sourceImage,(x_f-w_f,y_f-w_f),(x_f+2*w_f,y_f+2*h_f),(255,0,0,),2)
print("Hand Raised Detected")
张量流:
vis_util.visualize_boxes_and_labels_on_image_array(
frame,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8,
min_score_thresh=0.60)
解决方案
推荐阅读
- java - 如何从 2018 年 4 月至 2019 年 2 月的上午 00:00:00 开始编写石英表达式
- hyperledger-fabric - 管理超级账本结构中的隐私
- java - Target API - Will old devices still support deprecated features?
- ios - 故事板约束问题:屏幕高度的一半
- windows-10 - Windows 10 无需询问即可删除文件
- reactjs - Material-UI:模块解析失败:未终止的字符串常量 (18:5)
- angular - 类型上不存在 catchError (ret: any)
- vue.js - 当属性名称包含在值中时,Vue.js如何在html标签内输出属性?
- ios - How to attain opacity in a shape drawn in a layer of UIView that is a subView of a UIImageView?
- ansible - 尝试打印 firewalld 状态时出现 Ansible 致命错误