def overlay_img(self):
"""Overlay the transparent, transformed image of the arc onto our CV image"""
#overlay the arc on the image
rows, cols, channels = self.transformed.shape
roi = self.cv_image[0:rows, 0:cols]
#change arc_image to grayscale
arc2gray = cv2.cvtColor(self.transformed, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(arc2gray, 10, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
#black out area of arc in ROI
img1_bg = cv2.bitwise_and(roi, roi, mask=mask_inv)
img2_fg = cv2.bitwise_and(self.transformed, self.transformed, mask=mask)
#put arc on ROI and modify the main image
dst = cv2.add(img1_bg, img2_fg)
self.cv_image[0:rows, 0:cols] = dst
评论列表
文章目录