运行非常好,由于文件太大,请自己下载yolov3.weights添加到yolo-coco文件夹下面
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 138 2019-01-04 20:03 物体识别成功案例.ideaencodings.xml
文件 294 2019-01-04 20:03 物体识别成功案例.ideamisc.xml
文件 307 2019-01-04 20:03 物体识别成功案例.ideamodules.xml
文件 239 2019-01-04 20:05 物体识别成功案例.ideaother.xml
文件 7044 2019-01-04 20:28 物体识别成功案例.ideaworkspace.xml
文件 534 2019-01-04 20:04 物体识别成功案例.idea物体识别成功案例.iml
文件 54989 2019-01-04 19:57 物体识别成功案例imagesird.jpg
文件 51596 2019-01-04 20:01 物体识别成功案例imagespeople1.jpg
文件 940204 2019-01-04 20:16 物体识别成功案例output1.PNG
文件 894003 2019-01-05 12:49 物体识别成功案例output2.PNG
文件 705 2019-01-04 16:33 物体识别成功案例yolo-cocococo.names
文件 9131 2019-01-04 16:33 物体识别成功案例yolo-cocoyolov3.cfg
文件 4499 2019-01-04 20:13 物体识别成功案例yolo.py
文件 284 2019-01-06 17:13 物体识别成功案例说明.txt
目录 0 2019-01-04 20:28 物体识别成功案例.idea
目录 0 2019-01-04 20:14 物体识别成功案例images
目录 0 2019-01-05 12:49 物体识别成功案例output
目录 0 2019-01-04 19:51 物体识别成功案例yolo-coco
目录 0 2019-01-04 20:30 物体识别成功案例
----------- --------- ---------- ----- ----
1963967 19
# import the necessary packages
import numpy as np
import argparse
import time
import cv2
import os
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument(“-i“ “--image“ required=True
help=“path to input image“)
ap.add_argument(“-y“ “--yolo“ required=True
help=“base path to YOLO directory“)
ap.add_argument(“-c“ “--confidence“ type=float default=0.5
help=“minimum probability to filter weak detections“)
ap.add_argument(“-t“ “--threshold“ type=float default=0.3
help=“threshold when applying non-maxima suppression“)
args = vars(ap.parse_args())
# load the COCO class labels our YOLO model was trained on
labelsPath = os.path.sep.join([args[“yolo“] “coco.names“])
LABELS = open(labelsPath).read().strip().split(“
“)
# initialize a list of colors to represent each possible class label
np.random.seed(42)
COLORS = np.random.randint(0 255 size=(len(LABELS) 3)
dtype=“uint8“)
# derive the paths to the YOLO weights and model configuration
weightsPath = os.path.sep.join([args[“yolo“] “yolov3.weights“])
configPath = os.path.sep.join([args[“yolo“] “yolov3.cfg“])
# load our YOLO object detector trained on COCO dataset (80 classes)
print(“[INFO] loading YOLO from disk...“)
net = cv2.dnn.readNetFromDarknet(configPath weightsPath)
# load our input image and grab its spatial dimensions
image = cv2.imread(args[“image“])
(H W) = image.shape[:2]
# determine only the *output* layer names that we need from YOLO
ln = net.getlayerNames()
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutlayers()]
# construct a blob from the input image and then perform a forward
# pass of the YOLO object detector giving us our bounding boxes and
# associated probabilities
blob = cv2.dnn.blobFromImage(image 1 / 255.0 (416 416)
swapRB=True crop=False)
net.setInput(blob)
start = time.time()
layerOutputs = net.forward(ln)
end = time.time()
# show timing information on YOLO
print(“[INFO] YOLO took {:.6f} seconds“.format(end - start))
# initialize our lists of detected bounding boxes confidences and
# class IDs respectively
boxes = []
confidences = []
classIDs = []
# loop over each of the layer outputs
for output in layerOutputs:
# loop over each of the detections
for detection in output:
# extract the class ID and confidence (i.e. probability) of
# the current object detection
scores = detection[5:]
classID = np.argmax(scores)
confidence = scores[classID]
# filter out weak predictions by ensuring the detected
# probability is greater than the minimum probability
if confidence > args[“confidence“]:
# scale the bounding box coordinates back relative to the
# size of the image keeping in mind that YOLO actually
# returns the center (x y)-coordinates of the bounding
# box followed by
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 138 2019-01-04 20:03 物体识别成功案例.ideaencodings.xm
文件 294 2019-01-04 20:03 物体识别成功案例.ideamisc.xm
文件 307 2019-01-04 20:03 物体识别成功案例.ideamodules.xm
文件 239 2019-01-04 20:05 物体识别成功案例.ideaother.xm
文件 7044 2019-01-04 20:28 物体识别成功案例.ideaworkspace.xm
文件 534 2019-01-04 20:04 物体识别成功案例.idea物体识别成功案例.iml
文件 54989 2019-01-04 19:57 物体识别成功案例imagesird.jpg
文件 51596 2019-01-04 20:01 物体识别成功案例imagespeople1.jpg
文件 940204 2019-01-04 20:16 物体识别成功案例output1.PNG
文件 894003 2019-01-05 12:49 物体识别成功案例output2.PNG
文件 705 2019-01-04 16:33 物体识别成功案例yolo-cocococo.names
文件 9131 2019-01-04 16:33 物体识别成功案例yolo-cocoyolov3.cfg
文件 4499 2019-01-04 20:13 物体识别成功案例yolo.py
文件 284 2019-01-06 17:13 物体识别成功案例说明.txt
目录 0 2019-01-04 20:28 物体识别成功案例.idea
目录 0 2019-01-04 20:14 物体识别成功案例images
目录 0 2019-01-05 12:49 物体识别成功案例output
目录 0 2019-01-04 19:51 物体识别成功案例yolo-coco
目录 0 2019-01-04 20:30 物体识别成功案例
----------- --------- ---------- ----- ----
1963967 19
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)