一浓若、從git把代碼拉下來
代碼地址: https://github.com/Zhongdao/Towards-Realtime-MOT
環(huán)境中有ffmpeg通危, 這是用來記錄、轉(zhuǎn)換數(shù)字音頻、視頻遣臼,并能將其轉(zhuǎn)化為流的開源計算機程序铐料。需要自行安裝編譯
二定铜、下載權(quán)重文件
注意下載兩個權(quán)重文件
下載后在項目下新建文件weights改基,放入將兩個權(quán)重文件
由于我之前下載過yolov3的權(quán)重,所以直接粘貼過來咖为,沒有的話可以下官網(wǎng)提供的darknet-53
三秕狰、修改demo.py文件
1.把默認(rèn)的權(quán)重文件所在路徑替換
2.修改調(diào)用ffmpeg命令
補全ffmpeg路徑,并且指定編譯器 libx264
四躁染、運行demo.py文件
python demo.py --input-video path/to/your/input/video --output-root path/to/output/root
運行過程中找不到哪個模塊就安裝哪個模塊
五鸣哀、使用cv將圖片合成視頻
如果不想安裝ffmpeg,或者ffmpeg編譯不成功吞彤∥页模可以用cv合成視頻
import cv2
if opt.output_format == 'video':
# 原代碼使用ffmpeg將圖片合成視頻
# output_video_path = osp.join(result_root, 'result.mp4')
# cmd_str = 'E:\lqj\\ffmpeg\\bin\\ffmpeg -f image2 -i {}/%05d.jpg -vcodec libx264 -r 25 -b 382k {}'.format(osp.join(result_root, 'frame') ,output_video_path)
# os.system(cmd_str)
fps = 10
img = cv2.imread(frame_dir + "\\00000.jpg")
size = img.shape[:2]
videowriter = cv2.VideoWriter(result_root + "\\result.mp4", cv2.VideoWriter_fourcc('m', 'p', '4', 'v'), fps, size)
for i in os.listdir(frame_dir):
frame = cv2.imread(frame_dir + '\\' + i)
videowriter.write(frame)
cv2.imshow('track', frame)
c = cv2.waitKey(10) & 0xff
if c == 27:
videowriter.release()
break
videowriter.release()
cv2.destroyAllWindows()
運行的正確結(jié)果,有藍(lán)色字體輸出
六饰恕、踩坑
1.pip install cython_bbox報錯
報錯信息如下:
(track_env) E:\lqj\05_Towards-Realtime-MOT>pip install cython_bbox
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting cython_bbox
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fa/b9/fc7d60e8c3b29cc0ff24a3bb3c4b7457e10b7610fbb2893741b623487b34/cython_bbox-0.1.3.tar.gz (41 kB)
|████████████████████████████████| 41 kB 81 kB/s
Building wheels for collected packages: cython-bbox
Building wheel for cython-bbox (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'D:\Miniconda3\envs\track_env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox\setup.py'"'"'; file='"'"'C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\DLML\AppData\Local\Temp\pip-wheel-siwa8t6t'
cwd: C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox
Complete output (11 lines):
running bdist_wheel
running build
running build_ext
building 'cython_bbox' extension
creating build
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Miniconda3\envs\track_env\lib\site-packages\numpy\core\include -ID:\Miniconda3\envs\track_env\include -ID:\Miniconda3\envs\track_env\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" /Tcsrc/cython_bbox.c /Fobuild\temp.win-amd64-3.8\Release\src/cython_bbox.obj -Wno-cpp
cl: 命令行 error D8021 :無效的數(shù)值參數(shù)“/Wno-cpp”
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
ERROR: Failed building wheel for cython-bbox
Running setup.py clean for cython-bbox
Failed to build cython-bbox
Installing collected packages: cython-bbox
Running setup.py install for cython-bbox ... error
ERROR: Command errored out with exit status 1:
command: 'D:\Miniconda3\envs\track_env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox\setup.py'"'"'; file='"'"'C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\DLML\AppData\Local\Temp\pip-record-en1l_gbw\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Miniconda3\envs\track_env\Include\cython-bbox'
cwd: C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox
Complete output (11 lines):
running install
running build
running build_ext
building 'cython_bbox' extension
creating build
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Miniconda3\envs\track_env\lib\site-packages\numpy\core\include -ID:\Miniconda3\envs\track_env\include -ID:\Miniconda3\envs\track_env\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" /Tcsrc/cython_bbox.c /Fobuild\temp.win-amd64-3.8\Release\src/cython_bbox.obj -Wno-cpp
cl: 命令行 error D8021 :無效的數(shù)值參數(shù)“/Wno-cpp”
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\Miniconda3\envs\track_env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox\setup.py'"'"'; file='"'"'C:\Users\DLML\AppData\Local\Temp\pip-install-p_l1_mma\cython-bbox\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\DLML\AppData\Local\Temp\pip-record-en1l_gbw\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Miniconda3\envs\track_env\Include\cython-bbox' Check the logs for full command output.
<meta charset="utf-8">
2.無法執(zhí)行ffmpeg
安裝ffmpeg: https://www.videohelp.com/software/ffmpeg/old-versions
Python運行ffmpeg 解析視頻中碰到的路徑問題: https://blog.csdn.net/wangliuqi123/article/details/80493695