Window环境下复现 MOT《Towards Real-Time Multi-Object Tracking》代码

一、从git把代码拉下来

代码地址: https://github.com/Zhongdao/Towards-Realtime-MOT

image.png

环境中有ffmpeg, 这是用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。需要自行安装编译

二、下载权重文件

注意下载两个权重文件

image.png

下载后在项目下新建文件weights,放入将两个权重文件
由于我之前下载过yolov3的权重,所以直接粘贴过来,没有的话可以下官网提供的darknet-53


image.png

三、修改demo.py文件

1.把默认的权重文件所在路径替换
image.png
2.修改调用ffmpeg命令

补全ffmpeg路径,并且指定编译器 libx264


image.png

四、运行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()

运行的正确结果,有蓝色字体输出


clipboard.png

六、踩坑

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 :无效的数值参数“/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 :无效的数值参数“/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.

clipboard.png
clipboard.png
clipboard.png
2.无法执行ffmpeg
clipboard.png

安装ffmpeg: https://www.videohelp.com/software/ffmpeg/old-versions
Python运行ffmpeg 解析视频中碰到的路径问题: https://blog.csdn.net/wangliuqi123/article/details/80493695

你可能感兴趣的:(Window环境下复现 MOT《Towards Real-Time Multi-Object Tracking》代码)