I try to play a ROI of the window as shown in the picture by receiving the image with the Webcam.
- Conditions
1) The size of the main window is 400x300.
2) ROI is set to 320x240 at (30,30).
3) Put a red border on the ROI.
Here is how I did it:
- Create a mask with the same size as the frame.
- Make a square ROI on the mask.
- Use cv2.add to synthesize frame and mask, and assign it to dst.
- Check dst with cv2.imshow.
Here is code
import numpy as np, cv2
capture = cv2.VideoCapture(0)
if capture.isOpened() is None:
raise Exception("Camera not connected")
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 300)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 400)
while True:
ret, frame = capture.read()
if not ret:
break
mask = np.zeros(frame.shape[:2], np.uint8)
cv2.rectangle(mask, (30, 30), (320, 240), (0, 0, 255), -1)
dst = cv2.add(frame, frame, mask = mask)
cv2.imshow("mask", mask)
cv2.imshow("frame", frame)
cv2.imshow("dst", dst)
if cv2.waitKey(10) == 27:
break
capture.release()
cv2.destroyAllWindows()
But, I don't solve it
Any other way?
Thanks for the feedback.