Merhaba obje tanmaya girmek istedim bunun için YouTube baktım bir video buldum Türk fakat her şeyi bitirdim şu hatayı alıyorum.
TypeError: only size-1 arrays can be converted to Python scalars
Kodum şu:
İmport CV2.
İmport numpy as NP.
İmg = cv2.imread("C:/Users/Rehabilite/yolo/office.jpg")
#Print (img)
İMG_WIDTH = img. Shape [1]
İMG_HEIGHT = img. Shape [0]
İMG_BLOB = cv2.dnn. Blobfromımage(img, 1/255, (416, 416),swaprb = true)
Labels =["person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
"trafficlight", "firehydrant", "stopsign", "parkingmeter", "bench", "bird", "cat",
"dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack",
"umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sportsball",
"kite", "baseballbat", "baseballglove", "skateboard", "surfboard", "tennisracket",
"bottle", "wineglass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
"sandwich", "orange", "broccoli", "carrot", "hotdog", "pizza", "donut", "cake", "chair",
"sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse",
"remote", "keyboard", "cellphone", "microwave", "oven", "toaster", "sink", "refrigerator",
"book", "clock", "vase", "scissors", "teddybear", "hairdrier", "toothbrush"]
Colors = ["255,255,0","0,255,0","0,255,255","255,0,255""0,0,255"]
Colors = [np.array(color.split(",")).astype("int") for color in colors]
Colors = np. Array(colors)
Colors = np. Tile (colors,(20, 1))
Model = cv2.dnn.readNetFromDarknet("C:/Users/Rehabilite/yolo/model/yolov3.cfg","C:/Users/Rehabilite/yolo/model/yolov3.weights")
Layers = model.getLayerNames()
OUTPUT_LAYER =[layers[layer[0]-1] for layer in model.getUnconnectedOutLayers() ]
Model. Setınput (img_blob)
DETECTION_LAYERS = model. Forward(output_layer)
For DETECTION_LAYER in DETECTION_LAYERS:
For OBJECT_DETECTION in DETECTION_LAYER:
Scores = OBJECT_DETECTION [5:]
PREDICTED_ID = np. Argmax(scores)
Confidence = scores[predicted_id]
If confidence > 0.30:
Label = labels [predicted_id]
BOUNDING_BOX = OBJECT_DETECTION[0:4] * np. Array ([img_width, img_height, img_width, img_height])
(Box_center_x, BOX_CENTER_Y, BOX_WIDTH, BOX_HEIGHT) = BOUNDING_BOX. Astype("int")
Start_x = int(box_center_x - (box_width/2))
Start_y = int (box_center_y - (box_height/2))
End_x = start_x + BOX_WIDTH.
End_y = start_y + BOX_HEIGHT.
BOX_COLOR = colors[predicted_id]
BOX_COLOR = [int(each) for each in box_color]
Cv2. rectangle(img, (start_x, start_y), (end_x, end_y), BOX_COLOR, 2)
Cv2.puttext(img, label,(start_x, stART_Y-20). Cv2. FONT_HERSHEY_SIMPLEX,0.5. BOX_COLOR, 1)
Cv2.imshow("tespit ekranı", img)