File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ from PIL import Image
2+ from ultralytics import YOLO
3+ import os
4+ # Load a pretrained YOLOv8n model
5+ model = YOLO ('yolov8n.pt' )
6+ #THIS IS FOR IMAAAAAAGEEEEEEEEEE DETECTION !!
7+ img_count = 0
8+ image_paths = []
9+ image_directory = "F:\\ GFG\\ Images\\ " #enter the path for image folder here !
10+ for filename in os .listdir (image_directory ):
11+ if filename .endswith (".jpg" ) or filename .endswith (".JPG" ) or filename .endswith (".jpeg" ) or filename .endswith (".png" ):
12+ image_paths .append (os .path .join (image_directory , filename ))
13+ img_count += 1
14+ # Now, image_paths contains the paths of the images
15+ print (f'Total number of images in the folder { image_directory } : ' ,img_count )
16+ # # For example, if you have a directory with multiple image files:
17+ # image path example : 'F:\\GFG\\Images\\img3.jpg'
18+ count = 0
19+ for i in image_paths :
20+ results = model (i ) # results list
21+ count += 1
22+ # Show the results
23+ for r in results :
24+ im_array = r .plot () # plot a BGR numpy array of predictions
25+ im = Image .fromarray (im_array [..., ::- 1 ]) # RGB PIL image
26+ im .show () # show image
27+ im .save (f'F:\\ GFG\\ static\\ detection_result\\ { count } .jpg' ) # save image
You can’t perform that action at this time.
0 commit comments