2017-09-16 10 views
1

テンソルフローオブジェクト検出apiを使用してフレームの領域からオブジェクトを検出したいと考えています。 、唯一の地域1フレームの特定領域のオブジェクトを検出する

def detect_objects(image_np, sess, detection_graph): 

    region_1 = image_np[zone1[1]: zone1[3], zone1[0]:zone1[2]] 
    region_2 = image_np[zone2[1]: zone2[3], zone2[0]:zone2[2]] 

    image_np_expanded = np.expand_dims(image_np, axis=0) 
    image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') 

    boxes = detection_graph.get_tensor_by_name('detection_boxes:0') 

    scores = detection_graph.get_tensor_by_name('detection_scores:0') 
    classes = detection_graph.get_tensor_by_name('detection_classes:0') 
    num_detections = detection_graph.get_tensor_by_name('num_detections:0') 

    (boxes, scores, classes, num_detections) = sess.run(
     [boxes, scores, classes, num_detections], 
     feed_dict={image_tensor: image_np_expanded}) 

    vis_util.visualize_boxes_and_labels_on_image_array(
     image_np, 
     np.squeeze(boxes), 
     np.squeeze(classes).astype(np.int32), 
     np.squeeze(scores), 
     category_index, 
     use_normalized_coordinates=True, 
     line_thickness=1) 
    return image_np 
+0

TensorFlowのオブジェクト検出APIへのリンクを共有することで、いくつかの背景を提供できますか? –

答えて

1

にあなたはimage_npは前にあった場所に興味を持っている地域を代用する必要があり、私はregion_1とregion_2にフレームを分割しているが、どのように私はフレームからのみregion_1で検出を実行し、四角形を描画します

image_np_expanded = np.expand_dims(region_1, axis=0) 

:そうに

image_np_expanded = np.expand_dims(image_np, axis=0) 

を変更

へ:あなたはregion_1側に描かれたボックスのみで、元の画像を返したい場合は

vis_util.visualize_boxes_and_labels_on_image_array(
     region_1, 
     np.squeeze(boxes), 
     np.squeeze(classes).astype(np.int32), 
     np.squeeze(scores), 
     category_index, 
     use_normalized_coordinates=True, 
     line_thickness=1) 
return region_1 

あなたがする必要がありますどちらか(ボックスは、元の画像の大きさに戻ってregion_1の次元座標から変換され

vis = np.concatenate((img1, img2), axis=0) 

がIMG2の左側に(水平IMG1を積層する):IMG2上(IMG1)垂直スタックに :ハードバック互いに異なるデータTFがそのnp.arraysに使用するタイプ)またはconcatenate領域が与えられます:

vis = np.concatenate((img1, img2), axis=1) 
関連する問題