opencv 运动追踪_足球运动员追踪-使用OpenCV根据运动员的球衣颜色识别运动员的球队
opencv 運動追蹤
介紹 (Introduction)
In my previous work, I used pre-trained Yolov3 model to detect and used SORT (simple online and realtime tracking) to track football players from video. Then I used OpenCV’s getPerspectiveTransform function to convert the video to bird’s-eye view.
在我以前的工作中,我使用了預先訓練的Yolov3模型來檢測并使用SORT(簡單的在線和實時跟蹤)從視頻中跟蹤足球運動員。 然后,我使用OpenCVgetPerspectiveTransform函數將視頻轉換為鳥瞰圖。
One of the problems of this work is that the model cannot tell the difference between teams. It will be good if the program is able to identify players’ team instead of just detecting ‘person’. To further improve this, I wish to include a function which tells the difference based on the colors of players’ jersey.
這項工作的問題之一是模型無法區分團隊之間的差異。 如果程序能夠識別玩家的團隊而不僅僅是檢測“人”,那將是很好的。 為了進一步改善這一點,我希望包含一個功能,該功能根據球員球衣的顏色來區分差異。
Two approaches I can think of now to this problem.
我現在可以想到兩種解決這個問題的方法。
I decided to try approach 2 using OpenCV.
我決定嘗試使用OpenCV方法2。
足球視頻 (Football video)
The stationary football video is downloaded from here.
固定式足球視頻可從此處下載。
“T. D’Orazio, M.Leo, N. Mosca, P.Spagnolo, P.L.Mazzeo A Semi-Automatic System for Ground Truth Generation of Soccer Video Sequences, 6th IEEE International Conference on Advanced Video and Signal Surveillance, Genoa, Italy September 2–4 2009”
“T。 D'Orazio,M.Leo,N.Mosca,P.Spagnolo,PLMazzeo,用于足球視頻序列地面真相生成的半自動系統,第六屆IEEE國際高級視頻和信號監視國際會議,意大利熱那亞,2009年9月2日至4日”
彩色面膜由OpenCV (Color Mask By OpenCV)
The major difference among teams and referee is jersey color — one team is white, the other is blue and the referee is red. I want to determine the player’s team based on the jersey color.
球隊和裁判之間的主要區別是球衣顏色-一個隊是白色,另一隊是藍色,而裁判是紅色。 我想根據球衣顏色確定球員的球隊。
One frame from the video.視頻一幀。First I identified the range for the three colors.
首先,我確定了三種顏色的范圍。
color_list=['red','blue','white']boundaries = [([17, 15, 75], [50, 56, 200]), #red
([43, 31, 4], [250, 88, 50]), #blue
([187,169,112],[255,255,255]) #white
]
Then I applied OpenCV’s inRange function to create masks for three colors.
然后,我使用OpenCVinRange函數為三種顏色創建蒙版。
mask = cv2.inRange(image, lower, upper)Then use bitwise_and to apply masks to the frame.
然后使用bitwise_and將遮罩應用于幀。
output = cv2.bitwise_and(image, image, mask = mask)Three colors are extracted now
現在提取三種顏色
Red, blue and white masks applied to the image.紅色,藍色和白色蒙版應用于圖像。Now we need to apply these mask to the detection. I cropped the image based on the bounding box detected then applied the masks.
現在我們需要將這些蒙版應用于檢測。 我根據檢測到的邊界框裁剪圖像,然后應用蒙版。
crop_img = frame[ymin:ymax, xmin:xmax]Masks applied on the detection. The jersey is identified as blue based on the non-black/total pixel ratio.口罩應用于檢測。 根據非黑色/總像素比率,將球衣標識為藍色。The way I identify the color is to count the non-black pixels and calculated the ratio (non-black/total pixel) for the output images of the three colors. The highest ratio is the color of the jersey. For the example above, the blue has highest ratio, so the jersey is identified as blue.
我識別顏色的方法是對非黑色像素進行計數,并計算三種顏色的輸出圖像的比率(非黑色/總像素)。 比例最高的是球衣的顏色。 對于上面的示例,藍色的比率最高,因此球衣被識別為藍色。
Now I integrated this function to the player detection script, here are some examples of the masks and player detections.
現在,我將此功能集成到播放器檢測腳本中,以下是一些遮罩和播放器檢測的示例。
Samples of detections檢測樣本Based on the results of jersey color, I can draw the bounding boxes with different colors.
根據球衣顏色的結果,我可以繪制不同顏色的邊界框。
Football players tracking. Color of the bounding box represents the color of jersey.足球運動員跟蹤。 邊界框的顏色代表球衣的顏色。Then similar to my previous post, by using Opencv’s getPerspectiveTransform, I obtained the bird’s-eye view as shown in the beginning.
然后類似于我以前的文章,通過使用Opencv的getPerspectiveTransform ,我獲得了如開始所示的鳥瞰圖。
結論 (Conclusion)
There are still some problems:
仍然存在一些問題:
Some applications for this kind of tracking:
這種跟蹤的一些應用程序:
Thanks for reading, suggestions and feedback are welcome.
感謝您的閱讀,歡迎提出建議和反饋。
翻譯自: https://towardsdatascience.com/football-players-tracking-identifying-players-team-based-on-their-jersey-colors-using-opencv-7eed1b8a1095
opencv 運動追蹤
總結
以上是生活随笔為你收集整理的opencv 运动追踪_足球运动员追踪-使用OpenCV根据运动员的球衣颜色识别运动员的球队的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 树莓派 神经网络植入_使用自动编码器和T
- 下一篇: 犀牛建模软件的英文语言包_使用tidyt