python+opencv实时视频目标检测

python+opencv实时视频目标检测

 

opencv环境

一、访问Python Extension Packages for Windows,下载python对应版本的opencv。css

好比小编下载的是opencv_python-3.3.0+contrib-cp36-cp36m-win_amd64.whl,cp36表示Python是3.6版本,win_amd64是表示安装的python是64bit的,+contrib表示包括contrib包。python

二、下载好后,把它放到C盘中,执行安装命令:nginx

pip install C:\opencv_python-3.3.0+contrib-cp36-cp36m-win_amd64.whl
 

运行代码

修改

从本地获取。git


# vs = VideoStream(src=0).start()# vs =cv2.VideoCapture('C:\\Users\\voidking\\Desktop\\real-time-object-detection\\test_video.flv')vs =cv2.VideoCapture('./test_video.flv')

# grab the frame from the threaded video stream and resize it# to have a maximum width of 400 pixels# frame = vs.read()# frame = imutils.resize(frame, width=400)
# grab the frame from the threaded video file stream(grabbed,frame) = vs.read()# if the frame was not grabbed, then we have reached the end# of the streamif not grabbed: breakframe = imutils.resize(frame, width=800)


运行

推荐使用命令:sql

python real_time_object_detection.py -p ./MobileNetSSD_deploy.prototxt.txt -m ./MobileNetSSD_deploy.caffemodel

或者,指定绝对路径,假设项目目录为C:\Users\voidking\Desktop\real-time-object-detection\,那么命令以下:bash

python real_time_object_detection.py -p "C:\Users\voidking\Desktop\real-time-object-detection\MobileNetSSD_deploy.prototxt.txt-m "C:\Users\voidking\Desktop\real-time-object-detection\MobileNetSSD_deploy.caffemodel"
 

进阶修改

咱们看到,prototxt和model都是指定的,那咱们的视频文件也用这种方式指定,就更加友好一点。微信


# construct the argument parse and parse the argumentsap = argparse.ArgumentParser()ap.add_argument("-p", "--prototxt", required=True, help="path to Caffe 'deploy' prototxt file")ap.add_argument("-m", "--model", required=True, help="path to Caffe pre-trained model")ap.add_argument("-c", "--confidence", type=float, default=0.2, help="minimum probability to filter weak detections")args = vars(ap.parse_args())


咱们插入一行:app

ap.add_argument("-v", "--video", required=True, help="path to Caffe video file")

而后在初始化视频流时,修改成ide

vs =cv2.VideoCapture(args["video"])

 

运行命令修改成ui

python real_time_object_detection.py -p ./MobileNetSSD_deploy.prototxt.txt -m ./MobileNetSSD_deploy.caffemodel -v ./test_video.flv

运行效果

 

 

源码分享

 https://gitee.com/lyc96/real-time_video_target_detection


本文分享自微信公众号 - Python爬虫数据分析挖掘(zyzx3344)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。

相关文章
相关标签/搜索