Вычислить евклидово расстояние между двумя обнаруженными объектами TensorFlow - PullRequest
0 голосов
/ 19 июня 2019

Я создаю программу, которая может определять, когда рука поднимается, используя opencv и tenorflow. Мой предыдущий подход состоял в использовании HAAR-Cascade, и он дает и «хорошо» результат, но я хочу изучить возможности использования tenorflow вместо этого.

Мой предыдущий метод с использованием HAAR-Cascade и opencv - это вычисление евклидова расстояния между центром лица и центром руки, и я понимаю, что это с помощью cvRectangle, но в случае с тензорным потоком не используется cvRectangle, и как мне сообщить программе обнаруживаемый объект - это рука или лицо.

Метод HAAR:


#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")

Tensorflow:

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)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...