python数据挖掘视频_python+opencv实时视频目标检测

python+opencv实时视频目标检测

opencv环境

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

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

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

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

运行代码

修改

从本地获取。

# 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)

运行

推荐使用命令:

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

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

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())

我们插入一行:

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

然后在初始化视频流时,修改为:

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

运行命令修改为

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值