Can I use real-time detection only inside drawen polygon on the frames
I just want to draw a polygon by points. And than use detect algorithms only inside this polygon area. Anyone know about that? (I dont want to use only rectangle-areas)
import numpy as np
import cv2
def mouse_drawing(event, x, y, flags, params):
if event == cv2.EVENT_LBUTTONDOWN:
print("Left click")
circles.append((x,y))
cap = cv2.VideoCapture(0)
circles = []
cv2.namedWindow("Frame")
if len(circles) < 4:
cv2.setMouseCallback("Frame", mouse_drawing)
while True:
_, frame = cap.read()
for center_position in circles:
cv2.circle(frame, center_position, 2, (0, 0, 255), -1)
points = np.array(circles)
if len(circles) >= 4:
cv2.polylines(frame, np.int32([points]), 1, (255, 255, 255))
cv2.imshow("Frame", frame)
key = cv2.waitKey(1)
if key == 27:
break
elif key == ord("d"):
circles = []
cap.release()
cv2.destroyAllWindows()
i don't think, this is possible, as all the algorithms in the library expect a rectangular region to work on.
(you can ofc. warp your polygon to a rectangle, but that will distort the content inside)