diff --git a/Artificial Intelligence/Basic/Object_Detection/ObjectDetection_for_images.ipynb b/Artificial Intelligence/Basic/Object_Detection/ObjectDetection_for_images.ipynb index 1f0aabae0..c65c47c6b 100644 --- a/Artificial Intelligence/Basic/Object_Detection/ObjectDetection_for_images.ipynb +++ b/Artificial Intelligence/Basic/Object_Detection/ObjectDetection_for_images.ipynb @@ -231,10 +231,25 @@ } ], "source": [ - "font_scale = 3\n", + "# Initialize font scale and font", + "font_scale = 1\n", "font = cv2.FONT_HERSHEY_PLAIN\n", - "for ClassInd,conf,boxes in zip(ClassIndex.flatten(),confidence.flatten(),bbox):\n", - " cv2.rectangle(img,boxes,(255,0,0),2)\n", + "# Loop over detections and draw bounding boxes\n" + "for ClassInd, conf, boxes in zip(ClassIndex.flatten(), confidence.flatten(), bbox):\n", + " # Get class label and confidence score ", + "class_label = classLabels[ClassInd - 1]", + "confidence_score = conf * 100", + " # Draw bounding box", + " color = (0, 255, 0) # Green color for all boxes", + " cv2.rectangle(img, boxes, color, 2)", +" # Draw class label and confidence score", + " cv2.putText(img, f'{class_label}: {confidence_score:.2f}%', (boxes[0] + 10, boxes[1] + 20)", + font, fontScale=font_scale, color=(0, 255, 0), thickness=2) + +# Display the final image with detections +plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) +plt.axis('off') # Turn off axis +plt.show()\n", " cv2.putText(img,classLabels[ClassInd - 1],(boxes[0] + 10,boxes[1] + 40),font,fontScale = font_scale,color = (0,255,0),thickness = 3)\n", " print(classLabels[ClassInd - 1] + \" : \" + str(conf * 100) + \"%\")" ]