我正在用 OpenCV 实现一种警报系统。我需要跟踪“安全区域”内的人,并检测并通知他是否超出范围。
我已经实现了运动跟踪。现在我需要定义一个 ROI(地板上的安全区域矩形;摄像机位于天花板上)并检测它与人的边界矩形之间的交集。
与此类似的东西。
我有以下内容:
while True:
# Grab frame from webcam
ret, color_frame = vid.read()
# resize the frame, convert it to grayscale, and blur it
color_frame = imutils.resize(color_frame, width=500)
gray = cv2.cvtColor(color_frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
# MOTION TRACKING #
# Defining safe zone area on the floor.
roi = cv2.rectangle(color_frame, (50, 50), (500, 500), (0, 0, 0), 2)
# First frame to compare motion
if firstFrame is None:
firstFrame = gray …Run Code Online (Sandbox Code Playgroud)