OpenCV with Python - 蒙版png图像上的粗糙边缘

时间:2015-05-09 02:23:47

标签: python opencv computer-vision webcam

我正在尝试将此png图像放在网络摄像头中的眼睛上 - http://i.imgur.com/qdHHOpF.png

但是将图像放在眼睛上时,边缘会混淆并呈现白色。 http://i.imgur.com/Nhw0Q20.png

以下是创建蒙版的代码段 -

# Create the mask for the glasses
imgGlassesGray = cv2.cvtColor(imgGlasses, cv2.COLOR_BGR2GRAY)

ret, orig_mask = cv2.threshold(imgGlassesGray, 0, 255, cv2.THRESH_BINARY)

# Create the inverted mask for the glasses
orig_mask_inv = cv2.bitwise_not(orig_mask)

这是加入的部分 -

            roi = roi_color[y1:y2, x1:x2]            

            roi_bg = cv2.bitwise_and(roi,roi,mask = mask)

            roi_fg = cv2.bitwise_and(glasses,glasses,mask = mask_inv)

            dst = cv2.add(roi_bg,roi_fg)

            roi_color[y1:y2, x1:x2] = dst

我做错了什么?

编辑 - 这是调整大小的部分 -

            glasses = cv2.resize(imgGlasses, (glassesWidth,glassesHeight), interpolation = cv2.INTER_AREA)
            mask = cv2.resize(orig_mask, (glassesWidth,glassesHeight), interpolation = cv2.INTER_AREA)
            mask_inv = cv2.resize(orig_mask_inv, (glassesWidth,glassesHeight), interpolation = cv2.INTER_AREA)

0 个答案:

没有答案