confidence_score = scores[class1]
IndexError: index 172 is out of bounds for axis 0 with size 5
import cv2
import numpy as np
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg.txt")
classes = []
img1 = cv2.imread('img1.jpg')
img1 = cv2.resize(img1,None, fx =0.4, fy =0.4)
height,width,chanels = img1.shape
with open("coco.names.txt", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_name = net.getLayerNames()
output_layers = [layer_name[i[0] - 1] for i in net.getUnconnectedOutLayers()]
floaty =0.004
blob = cv2.dnn.blobFromImage(img1,floaty,(416,416),(0,0,0),True)
# true to convert RBG
for b in blob:
for n,img_blog in enumerate(b):
cv2.imshow(str(n), img_blog)
net.setInput(blob)
out = net.forward(output_layers)
#trying to show or detect
for show in out:
for detection in out:
scores = detection[:5]
class1 = np.argmax(scores)
confidence_score = scores[class1]
if confidence_score > 0.6:
center_x = int[detection[0] * width]
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)
cv2.circle(img1,(center_x,center_y),12,(0,255,0),2)
cv2.imshow('image', img1)
cv2.waitKey(0)
cv2.destroyAllWindows()