yolo opencv_如何使用Yolo,SORT和Opencv跟踪足球运动员。
yolo opencv
介紹 (Introduction)
In this post, I will show how I detect and track players using Yolov3, Opencv and SORT from video clip, and turn the detections to the bird’s-eye view as shown above.
在這篇文章中,我將展示如何使用視頻片段中的Yolov3,Opencv和SORT來檢測和跟蹤播放器,并將檢測結果變為鳥瞰圖,如上所示。
Inspired by Sam Blake’s great work (https://medium.com/hal24k-techblog/how-to-track-objects-in-the-real-world-with-tensorflow-sort-and-opencv-a64d9564ccb1), I will do the following steps for this project:
受山姆·布雷克 ( Sam Blake )的出色著作( https://medium.com/hal24k-techblog/how-to-track-objects-in-the-real-world-with-tensorflow-sort-and-opencv-a64d9564ccb1 )的啟發,我將為此項目執行以下步驟:
足球視頻數據集 (Football video dataset)
In order to have a stable tracking and perspective transform, I need a video clip without camera moving around. I downloaded the video from IPL Ball Detection Datasets. Please be noted that the ball is not tracked in this project, it was already tracked (green bounding box) from the source.
為了獲得穩定的跟蹤和透視變換,我需要一個沒有相機四處移動的視頻剪輯。 我從IPL球檢測數據集下載了視頻。 請注意,此項目未跟蹤該球,它已從源中被跟蹤(綠色邊框)。
here)此處下載)物體檢測 (Object Detection)
The first step is to load the video and detect the players.
第一步是加載視頻并檢測播放器。
I used the pre-trained Yolov3 weight and used Opencv’s dnn module and only selected detections classified as ‘person’.
我使用了預先訓練的Yolov3權重,并使用了Opencv的dnn模塊,并且只選擇了歸類為“人”的檢測項。
I drew bounding boxes for detected players and their tails for previous ten frames.
我為檢測到的球員畫了邊框,并為前十幀畫了他們的尾巴。
Player tracking using Yolov3 and Opencv使用Yolov3和Opencv進行玩家跟蹤Looks like the pre-trained model is doing quite okay.
看起來像經過預訓練的模型還算不錯。
對象追蹤 (Object Tracking)
Next I want to track the player and assign unique IDs to them. I used Alex Bewley’s SORT algorithm(simple online and realtime tracking), which I applied to my previous work.
接下來,我要跟蹤播放器并為其分配唯一的ID。 我使用了Alex Bewley的SORT算法(簡單的在線和實時跟蹤),該算法已應用于我以前的工作中。
Player tracking using SORT.使用SORT跟蹤玩家。Now each player has a unique ID assigned and displayed in the video.
現在,每個播放器都有一個唯一的ID,該ID已分配并顯示在視頻中。
透視變換 (Perspective Transform)
The video looks good now, but I still want to have players’ motion in bird’s-eye view. It can be done by doing perspective transform. There are a little bit math involved, fortunately Opencv’s getPerspectiveTransform function make it a lot easier.
該視頻現在看起來不錯,但我仍想以鳥瞰視角讓玩家運動。 可以通過執行透視變換來完成。 涉及到一些數學運算,幸運的是, Opencv的getPerspectiveTransform函數使它變得更加容易。
I need to find 4 fixed points as reference and identify the coordinations from the video and also from the bird’s-eye view image.
我需要找到4個固定點作為參考,并從視頻和鳥瞰圖圖像中識別出坐標。
First I identify 4 reference points from the video as show in in red spot and get the pixel coordinations.
首先,我從視頻中識別出4個參考點,如紅色點所示,并獲得像素坐標。
np.array([[1, 47], # Upper left
[878, 54], # Upper right
[1019, 544], # Lower right
[1, 546] # Lower left
])4 reference points marked on video(red spot)視頻上標有4個參考點(紅色斑點)
I did not really see very solid reference points from the video so I roughly identified 4 points and marked these locations on the bird’s-eye view and got the corresponding pixel coordinations. It will be more precise if the reference points are more robust.
我沒有從視頻中真正看到非常堅實的參考點,因此我大致確定了4個點,并在鳥瞰圖上標記了這些位置,并獲得了相應的像素坐標。 如果參考點更健壯,它將更加精確。
np.array([[871, 37], # Upper left
[1490, 39], # Upper right
[1458, 959], # Lower right
[1061, 955] # Lower left
])4 reference points marked on bird’s-eye view(red spot)鳥瞰圖上標有4個參考點(紅色斑點)
Then by applying Opencv’s getPerspectiveTransform using these reference points, we can transform the detections from video to bird’s-eye view.
然后,通過使用這些參考點應用Opencv的getPerspectiveTransform ,我們可以將檢測結果從視頻轉換為鳥瞰圖。
Player tracking on video and bird’s-eye view.播放器跟蹤視頻和鳥瞰圖。With player’s movement information, it is possible to do further analysis such as players’ running distance and velocity.
利用運動員的運動信息,可以進行進一步分析,例如運動員的跑步距離和速度。
The speed for running this player tracking is around 0.3 second per frame on my 2016 Macbook Pro Intel i5 CPU. It is possible to do this real time by using GPU for some applications if necessary.
在我的2016 Macbook Pro Intel i5 CPU上,運行此播放器跟蹤的速度約為每幀0.3秒。 如有必要,可以通過將GPU用于某些應用程序來實時執行此操作。
Thanks for reading, comments and suggestions are welcome!
感謝您的閱讀,歡迎提出意見和建議!
In my next post, I used OpenCV to identify players’s team based on their jersey color. Feel free to take a look!
在我的下一篇文章中,我使用OpenCV根據球員的球衣顏色來識別他們的球隊。 隨意看看!
翻譯自: https://towardsdatascience.com/how-to-track-football-players-using-yolo-sort-and-opencv-6c58f71120b8
yolo opencv
總結
以上是生活随笔為你收集整理的yolo opencv_如何使用Yolo,SORT和Opencv跟踪足球运动员。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 快手关注请求怎么取消
- 下一篇: 首发 i7-1360P,微星新款 Sum