2017-08-12 4 views
-1

次のDLib操作の結果をOpenCVイメージにオーバーレイするにはどうすればよいですか?私はあごがこの画像で検出描画したいOpenCV上のOpenCV DLibハイブリッドオーバーレイライブラリ

dets = detector(image, 1) 
print("Number of faces detected: {}".format(len(dets))) 

for k, d in enumerate(dets): 
     shape = predictor(image, d) 

...元のコードで

がglibの窓に行わ.add_overlayのようなものがあるが、私はOpenCVのイメージを持っています。 cv2.add_overlay(image、shape)のようなものがありますか?

答えて

0

まず、使用numpyのアレイのような互換性のあるフォーマットをOpenCVのために形状を変換する方法を記述します

def shape_to_np(shape, dtype="int"): 
    # initialize the list of (x, y)-coordinates 
    coords = np.zeros((68, 2), dtype=dtype) 

    # loop over the 68 facial landmarks and convert them 
    # to a 2-tuple of (x, y)-coordinates 
    for i in range(0, 68): 
     coords[i] = (shape.part(i).x, shape.part(i).y) 

    # return the list of (x, y)-coordinates 
    return coords 

そしてようにそれを使用する:

shape = shape_to_np(shape) 

# loop over the (x, y)-coordinates for the facial landmarks 
# and draw them on the image 
for (x, y) in shape: 
    cv2.circle(image, (x, y), 1, (0, 0, 255), -1)