python使用yolo来进行目标检测与识别代码
代码语言:python
所属分类:人工智能
代码描述:python使用yolo来进行目标检测与识别代码,可以识别人和物
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
import cv2 #import argparse import numpy as np import sys #parser = argparse.ArgumentParser() #parser.add_argument('--input', help='Path to input image.') #args = parser.parse_args() # Minimum confidence threshold. Increasing this will improve false positives but will also reduce detection rate. min_confidence=0.14 model = '/data/wwwroot/default/model/yolov2.weights' config = '/data/wwwroot/default/model/yolov2.cfg' #Load names of classes classes = None with open('/data/wwwroot/default/model/labels.txt', 'rt') as f: classes = f.read().rstrip('\n').split('\n') #print(classes) # Load weights and construct graph net = cv2.dnn.readNetFromDarknet(config, model) net.setPreferableBackend(cv2.dnn.DNN_BACKEND_DEFAULT) net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU) #winName = 'Running YOLO Model' #cv2.namedWindow(winName, cv2.WINDOW_NORMAL) #Read input image frame = cv2.imread("/data/wwwroot/default/asset/test.jpg") # Get width and height height,width,ch=frame.shape # Create a 4D blob from a frame. blob = cv2.dnn.blobFromImage(frame, 1.0/2.........完整代码请登录后点击上方下载按钮下载查看
网友评论0