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來檢測(cè)和跟蹤播放器,并將檢測(cè)結(jié)果變?yōu)轼B瞰圖,如上所示。
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 )的啟發(fā),我將為此項(xiàng)目執(zhí)行以下步驟:
足球視頻數(shù)據(jù)集 (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.
為了獲得穩(wěn)定的跟蹤和透視變換,我需要一個(gè)沒有相機(jī)四處移動(dòng)的視頻剪輯。 我從IPL球檢測(cè)數(shù)據(jù)集下載了視頻。 請(qǐng)注意,此項(xiàng)目未跟蹤該球,它已從源中被跟蹤(綠色邊框)。
here)此處下載)物體檢測(cè) (Object Detection)
The first step is to load the video and detect the players.
第一步是加載視頻并檢測(cè)播放器。
I used the pre-trained Yolov3 weight and used Opencv’s dnn module and only selected detections classified as ‘person’.
我使用了預(yù)先訓(xùn)練的Yolov3權(quán)重,并使用了Opencv的dnn模塊,并且只選擇了歸類為“人”的檢測(cè)項(xiàng)。
I drew bounding boxes for detected players and their tails for previous ten frames.
我為檢測(cè)到的球員畫了邊框,并為前十幀畫了他們的尾巴。
Player tracking using Yolov3 and Opencv使用Yolov3和Opencv進(jìn)行玩家跟蹤Looks like the pre-trained model is doing quite okay.
看起來像經(jīng)過預(yù)訓(xùn)練的模型還算不錯(cuò)。
對(duì)象追蹤 (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算法(簡(jiǎn)單的在線和實(shí)時(shí)跟蹤),該算法已應(yīng)用于我以前的工作中。
Player tracking using SORT.使用SORT跟蹤玩家。Now each player has a unique ID assigned and displayed in the video.
現(xiàn)在,每個(gè)播放器都有一個(gè)唯一的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.
該視頻現(xiàn)在看起來不錯(cuò),但我仍想以鳥瞰視角讓玩家運(yùn)動(dòng)。 可以通過執(zhí)行透視變換來完成。 涉及到一些數(shù)學(xué)運(yùn)算,幸運(yùn)的是, Opencv的getPerspectiveTransform函數(shù)使它變得更加容易。
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個(gè)固定點(diǎn)作為參考,并從視頻和鳥瞰圖圖像中識(shí)別出坐標(biāo)。
First I identify 4 reference points from the video as show in in red spot and get the pixel coordinations.
首先,我從視頻中識(shí)別出4個(gè)參考點(diǎn),如紅色點(diǎn)所示,并獲得像素坐標(biāo)。
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)視頻上標(biāo)有4個(gè)參考點(diǎn)(紅色斑點(diǎn))
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.
我沒有從視頻中真正看到非常堅(jiān)實(shí)的參考點(diǎn),因此我大致確定了4個(gè)點(diǎn),并在鳥瞰圖上標(biāo)記了這些位置,并獲得了相應(yīng)的像素坐標(biāo)。 如果參考點(diǎn)更健壯,它將更加精確。
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)鳥瞰圖上標(biāo)有4個(gè)參考點(diǎn)(紅色斑點(diǎn))
Then by applying Opencv’s getPerspectiveTransform using these reference points, we can transform the detections from video to bird’s-eye view.
然后,通過使用這些參考點(diǎn)應(yīng)用Opencv的getPerspectiveTransform ,我們可以將檢測(cè)結(jié)果從視頻轉(zhuǎn)換為鳥瞰圖。
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.
利用運(yùn)動(dòng)員的運(yùn)動(dòng)信息,可以進(jìn)行進(jìn)一步分析,例如運(yùn)動(dòng)員的跑步距離和速度。
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上,運(yùn)行此播放器跟蹤的速度約為每幀0.3秒。 如有必要,可以通過將GPU用于某些應(yīng)用程序來實(shí)時(shí)執(zhí)行此操作。
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根據(jù)球員的球衣顏色來識(shí)別他們的球隊(duì)。 隨意看看!
翻譯自: https://towardsdatascience.com/how-to-track-football-players-using-yolo-sort-and-opencv-6c58f71120b8
yolo opencv
總結(jié)
以上是生活随笔為你收集整理的yolo opencv_如何使用Yolo,SORT和Opencv跟踪足球运动员。的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 快手关注请求怎么取消
- 下一篇: 人工智能的搭便车指南