我正在尝试从广播的羽毛球视频中检测羽毛球穿梭。
首先,我尝试使用白色的bitwise_or
遮罩来识别羽毛球场线,因为大多数线是白色的。
然后,我从OpenCV应用了背景减法功能以消除帧中的背景噪声。
我在上面的图片中用红色圆圈手动标记了穿梭车使其可见。
有什么方法可以检查航天飞机是否掉线或越过线,以便可以验证是否得分?
以下是我编写的用于掩盖和删除背景的代码:
import numpy as np
import time
# KNN background subtraction function
subtractor = cv2.createBackgroundSubtractorKNN(50,50,0)
#capture video from file
cap = cv2.VideoCapture('../Videos/cropped.mp4')
while(1):
#reading the video frame by frame
ret,frame = cap.read()
if ret:
frame = cv2.resize(frame,(1366,768)) #resize the frame
hls = cv2.cvtColor(frame,cv2.COLOR_BGR2HLS) #converting the frame to hls color format
#white mask to detect white lines
lower_white = np.uint8([0, 200, 0])
upper_white = np.uint8([255, 255, 255])
white_mask = cv2.inRange(hls,lower_white,upper_white)
#yellow mask
lower_yellow = np.uint8([10, 0, 100])
upper_yellow = np.uint8([40, 255, 255])
yellow_mask = cv2.inRange(hls, lower_yellow, upper_yellow)
#combining the mask
mask = cv2.bitwise_or(white_mask, yellow_mask)
#remove the background from gray frame
bg_remove = subtractor.apply(gray)
#combining the result of masking and background removal
roi = cv2.bitwise_or(mask,bg_remove)
#displaying the result
cv2.imshow('ROI',roi)
k = cv2.waitKey(1)
if k == ord('q'):
break
cap.release()
cv2.destroyAllWindows```