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源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。

相關文章
相關標籤/搜索