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

Added Item-detection using Yolov8 #207

Merged
merged 2 commits into from
Oct 22, 2023
Merged
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
27 changes: 27 additions & 0 deletions PYTHON/image_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from PIL import Image
from ultralytics import YOLO
import os
# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')
#THIS IS FOR IMAAAAAAGEEEEEEEEEE DETECTION !!
img_count = 0
image_paths = []
image_directory = "F:\\GFG\\Images\\" #enter the path for image folder here !
for filename in os.listdir(image_directory):
if filename.endswith(".jpg") or filename.endswith(".JPG") or filename.endswith(".jpeg") or filename.endswith(".png"):
image_paths.append(os.path.join(image_directory, filename))
img_count += 1
# Now, image_paths contains the paths of the images
print(f'Total number of images in the folder {image_directory} : ',img_count)
# # For example, if you have a directory with multiple image files:
# image path example : 'F:\\GFG\\Images\\img3.jpg'
count = 0
for i in image_paths:
results = model(i) # results list
count += 1
# Show the results
for r in results:
im_array = r.plot() # plot a BGR numpy array of predictions
im = Image.fromarray(im_array[..., ::-1]) # RGB PIL image
im.show() # show image
im.save(f'F:\\GFG\\static\\detection_result\\{count}.jpg') # save image