How can I fill ROI, so that the image is placed in the centre of the ROI?
The ROI is found with (x, y, w, h) = cv2.boundingRect(contour)
and I insert the input image with
image = cv2.resize(input_image, (w, h)) img2gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) _, image_mask = cv2.threshold(img2gray, 1, 255, cv2.THRESH_BINARY) roi = frame[y:y+h, x:x+w] roi[np.where(image_mask)] = 0 roi += image
The h
and w
are the dimensions of my input image.
How can I add the offsets so that the ROI += image
will result like shown in the image?