Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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()

click to hide/show revision 2
None

updated 2018-11-18 11:12:14 -0600

berak gravatar image

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

cv2 def mouse_drawing(event, x, y, flags, params): if event == cv2.EVENT_LBUTTONDOWN: print("Left click") circles.append((x,y))

circles.append((x,y)) cap = cv2.VideoCapture(0)

cv2.VideoCapture(0) circles = []

[] cv2.namedWindow("Frame") if len(circles) < 4: cv2.setMouseCallback("Frame", mouse_drawing)

mouse_drawing) while True: _, frame = cap.read()

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()

cap.release() cv2.destroyAllWindows()