GitHub项目学习笔记-MegFlow
项目github地址
一、 安装 python3.x (推荐 conda)
1. $ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
2. $ chmod a+x Miniconda3-latest-Linux-x86_64.sh
3. $ ./Miniconda3-latest-Linux-x86_64.sh
4. 创建python3.8的环境
5. $ conda create --name py38 python=3.8
6. $ conda activate py38
主要问题:如果你的电脑中原先装有conda,这会使两者的环境变量冲突。
修改方法:打开bashrc文件
冲突情况下框里的内容为anaconda而不是miniconda,你可以将其修改为miniconda即可。
二、安装 Prebuilt 包
- 打开 release 页面下载对应 python 版本的 .whl 包,安装
- 在你的python环境下可以import megflow即为成功
主要问题:.whl 提供了 run_with_plugins命令,正常情况下运行run_with_plugins -h不会报错,出错是因为你的该文件没有加载到环境变量中。
找到run_with_plugins文件对应的目录,这里是.local/bin,将其加入到环境变量中即可正常运行
猫猫围栏
一、功能概述
注册的猫猫离开围栏,会收到一条告警信息。未注册的不会报警。 CPU 配置已提供,没有 GPU 也可以运行。
二、模型和自测数据下载
链接
https://pan.baidu.com/s/1SoxHZjdWyPRIAwfcHWUQTQ
提取码: ebcn
$ cd flow-python/examples
$ ln -s ${DOWNLOAD_DIR}/models models
ps.你可以把下载好的整个model文件夹拉到git对应的model文件夹下
三、软件安装(每次运行服务之前都得注意打开redius服务器)
启动 redis-server
$ sudo apt install redis-server
$ redis-server & #开启服务器命令
安装 megengine(1.6.0 引入 lite 接口,简化推理并提供模型加密方案)
$ conda activate py38
$ python3 -m pip install --upgrade pip
$ python3 -m pip install megengine==1.6.0rc1 -f https://megengine.org.cn/whl/mge.html
四、图片注册
启动图片服务
$ cd flow-python/examples
$ pip3 install -r requires.txt
$ run_with_plugins -c cat_finder/image_gpu.toml -p cat_finder # 有 GPU 的机器执行这个
$ run_with_plugins -c cat_finder/image_cpu.toml -p cat_finder # 无 GPU 的 laptop 执行这句
使用你的浏览器打开 http://127.0.0.1:8081/docs
选择图片文件,然后命名并提交即为一个猫注册
在redius服务器可以看到对应的注册信息
五、视频识别
下面运行中的test1.ts文件处在百度网盘下载好的model文件夹对应路径下,你软链接到github上的文件夹对应的model文件夹后(或复制),找到对应路径运行命令即可
$ wget https://github.com/aler9/rtsp-simple-server/releases/download/v0.17.2/rtsp-simple-server_v0.17.2_linux_amd64.tar.gz
$ tar xvf rtsp-simple-server_v0.17.2_linux_amd64.tar.gz && ./rtsp-simple-server
$ ffmpeg -re -stream_loop -1 -i ${models}/cat_finder_testdata/test1.ts -c copy -f rtsp rtsp://127.0.0.1:8554/test1.ts
效果展示:
注意这里推送的视频流是一直运行的,除非你按q进行中止,你可以打开多个终端对多个视频进行推流,在推流的同时也可以不断打开浏览器网页对猫体进行注册
浏览器打开 http://127.0.0.1:8082/docs 。
try it out 后在 /start/{url} 接口输入 rtsp 地址(例如“rtsp://127.0.0.1:8554/test1.ts”),会返回 stream_id(例如 0)。
六,最终效果
在浏览器日志中即可看到对应的报警信息了
4电瓶车报警
功能概述
镜头前出现电瓶车立即报警,不会对同一辆车重复报警。本服务和猫猫围栏在推送时机上有区别:猫离开时才通知。
redius服务器使用过程中可能会遇到端口被占用的情况,找到对应端口并杀死即可
对于第二个项目,同样打开redius服务器
再运行./rtsp-simple-server,进行视频推流的预处理
$ ffmpeg -re -stream_loop -1 -i ${models}/cat_finder_testdata/test1.ts -c copy -f rtsp rtsp://127.0.0.1:8554/test1.ts #运行此命令将你想要监控的视频进行推流(rstp的作用感觉就是绑定对应端口)
再到对于目录下运行run_with_plugins
运行结果: