I am using this code to create a mask which split every image in half (left-right).
import cv2
import numpy as np
image = cv2.imread('box.png')
h = image.shape[0]
w = image.shape[1]
mask_l = np.zeros(image.shape[:2], dtype="uint8")
roi = cv2.rectangle(mask_l, (w//2, 0), (0, h), 255, -1) # LEFT MASK
masked_l = cv2.bitwise_and(image, image, mask=mask_l)
cv2.imshow("Left", masked_l)
cv2.waitKey(0)
mask_r = np.zeros(image.shape[:2], dtype="uint8")
cv2.rectangle(mask_r, (w//2, 0), (w, h), 255, -1) # RIGHT MASK
masked_r = cv2.bitwise_and(image, image, mask=mask_r)
cv2.imshow("Right", masked_r)
cv2.waitKey(0)
How can I save the visible part of the image to a ROI ? Possible, if the saved rectangle take the name as source image as part of filename. Es: input --> box.png --> output --> box1.png, box2.png
Thanks
cv2.imwrite(). Also update with sample input and sample outputcropped = image[w//2:0, 0:h]doesn't work...