视觉/图像重磅干货,第一时间送达
import math
import cv2
import cvzone
from cvzone.ColorModule import ColorFinder
import numpy as np
cv2.VideoCapture() # grabbing frames from the video file `Videos/vid (3).mp4
myColorFinder = ColorFinder(False)
hsvVals = {'hmin': 8, 'smin': 96, 'vmin': 115, 'hmax': 14, 'smax': 255, 'vmax': 255}
imgContours, contours = cvzone.findContours(img, mask, minArea=500)
if contours:
posListX.append(contours[0]['center'][0])
posListY.append(contours[0]['center'][1])
A, B, C = np.polyfit(posListX, posListY, 2)
a = A
b = B
c = C - 590 # 590 represents the y-value threshold for the "basket" area
x = int((-b - math.sqrt(b ** 2 - (4 * a * c))) / (2 * a))
prediction = 330 < x < 430 # Basket zone
if prediction:
cvzone.putTextRect(imgContours, "Basket", (50, 150), scale=5, thickness=5, colorR=(0, 200, 0), offset=20)
else:
cvzone.putTextRect(imgContours, "No Basket", (50, 150), scale=5, thickness=5, colorR=(0, 0, 200), offset=20)
—THE END—
觉得有用,麻烦给个赞和在看