2017-08-12 58 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) 

我想提請下巴此圖像中檢測..

原代碼

有像做一個能說會道的窗口.add_overlay但我有一個OpenCV的圖像。有沒有像cv2.add_overlay(圖像,形狀)?

回答

0

首先我們寫一個方法的形狀轉換爲使用到的OpenCV像numpy的陣列兼容的格式:

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)