如何使用Ptython OpenCV从广播视频中检测羽毛球穿梭

时间:2019-07-10 06:28:30

标签: python opencv

我正在尝试从广播的羽毛球视频中检测羽毛球穿梭。

首先,我尝试使用白色的bitwise_or遮罩来识别羽毛球场线,因为大多数线是白色的。

然后,我从OpenCV应用了背景减法功能以消除帧中的背景噪声。

以下是我从编写的代码中得到的结果:

输入框 Input frame

输出框架
Output Frame


我在上面的图片中用红色圆圈手动标记了穿梭车使其可见。

有什么方法可以检查航天飞机是否掉线或越过线,以便可以验证是否得分?

以下是我编写的用于掩盖和删除背景的代码:

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```


0 个答案:

没有答案