代码拉取完成,页面将自动刷新
#!/usr/bin/python
#
# Copyright (c) 2018. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Description:
# Detect Vehicle using AMD MIVisionX Inferencing Engine.
#
from __future__ import print_function
import os, timeit
import argparse
import numpy as np
import cv2
import yoloOpenVX
import inference
if __name__ == '__main__' :
parseHandle = argparse.ArgumentParser(description=
'Detect Vehicles in static video or a live feed.')
parseHandle.add_argument('--video', dest='video',
type=str, default="./media/demo.mp4",
help='path to video file.')
parseHandle.add_argument('--cam_ip', dest='cam_ip', type=str,
default='', help='IP address for video cam.')
args = parseHandle.parse_args()
if ( args.cam_ip ) :
# must be a mjpg or h264 streaming
window_title = args.cam_ip + "- AMD Object Detection on Live Feed"
feed = args.cam_ip
elif ( args.video ) :
window_title = os.path.basename(args.video) + "- AMD Object Detection on Recorded Feed"
feed = args.video
else:
print ("Error: no video source.");
exit(0);
yoloNet = inference.yoloInferenceNet(yoloOpenVX.weights);
cv2.namedWindow(window_title, cv2.WINDOW_GUI_EXPANDED)
cap = cv2.VideoCapture(feed)
if ( cap.isOpened() == False ):
print ("Error: could not open video feed", feed);
startTime = timeit.default_timer()
iframe = 0;
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break;
if ( iframe == 0 ):
cv2.resizeWindow(window_title, frame.shape[1], frame.shape[0])
iframe = iframe + 1
resized_frame = yoloNet.yoloInput(frame); # image to display
frame_array = np.concatenate((resized_frame[:,:,0], resized_frame[:,:,1], resized_frame[:,:,2]), 0)
boxes = yoloOpenVX.model.detectBoxes(yoloNet.handle, np.ascontiguousarray(frame_array, dtype=np.float32)/(255.0))
frame_w_boxes = yoloNet.addBoxes(frame, boxes);
cv2.imshow(window_title, frame_w_boxes)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
if ( os.path.splitext(args.cam_ip)[1] == ".jpg" ) :
cap = cv2.VideoCapture(feed); # required for static jpg like stream in Bosch cams
elapsedTime = timeit.default_timer() - startTime
print ("Processed a total of ", iframe, "frames in ", elapsedTime, "micro sec with ", iframe/(elapsedTime*1e-6), "fps.");
cap.release()
cv2.destroyAllWindows()
yoloNet.destroy();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。