Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ObjectDetection_for_images.ipynb #967

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) + \"%\")"
]
Expand Down
Loading