Closed harshmgoyal closed 4 years ago
Hello @harshmgoyal, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , Docker Image, and Google Cloud Quickstart Guide for example environments.
If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.
If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:
For more information please visit https://www.ultralytics.com.
Setting the '--save-txt' argument on detect.py will output the bounding box locations and classes into /inference/output/ with one file per image. You can simply read in these files and crop the bboxes out of the appropriate images or video frames using OpenCV etc.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
https://github.com/ultralytics/yolov5/issues/2608#issuecomment-809094537
U can refer to my reply in the above link.
Hi! have added the saving option of the detected objects which will be in project/name/cropped when using detect.py. I have made a PR to this repo but you can check the changes in my folk yolov5
@harshmgoyal @cjsLindquist Prediction box cropping is now available in YOLOv5 via PR https://github.com/ultralytics/yolov5/pull/2827! PyTorch Hub models can use results.crop()
or detect.py can be called with the --save-crop
argument. Example usage:
python detect.py --save-crop
How to extract text from the --save-crop images having multiple classes will be saving the images in a crop folder i need the text as well for that specific cropped image can anyone help me how we can do that.
@bachimanchiajay ๐ Hello! Thanks for asking about cropping results with YOLOv5 ๐. Cropping bounding box detections can be useful for training classification models on box contents for example. This feature was added in PR https://github.com/ultralytics/yolov5/pull/2827. You can crop detections using either detect.py or YOLOv5 PyTorch Hub:
Crops will be saved under runs/detect/exp/crops
, with a directory for each class detected.
python detect.py --save-crop
Crops will be saved under runs/detect/exp/crops
if save=True
, and also returned as a dictionary with crops as numpy arrays.
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, custom
# Images
img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list
# Inference
results = model(img)
# Results
crops = results.crop(save=True)
# -- or --
crops = results.crop(save=True, save_dir='runs/detect/exp') # specify save dir
Good luck ๐ and let us know if you have any other questions!
I can able to see the cropped results but i have to extract text from the cropped images before cropping i have to pass these predicted coordina To the textract for ocr.
On Tue, 18 Oct 2022 at 5:25 PM, Glenn Jocher @.***> wrote:
@bachimanchiajay https://github.com/bachimanchiajay ๐ Hello! Thanks for asking about cropping results with YOLOv5 ๐. Cropping bounding box detections can be useful for training classification models on box contents for example. This feature was added in PR #2827 https://github.com/ultralytics/yolov5/pull/2827. You can crop detections using either detect.py or YOLOv5 PyTorch Hub: detect.py
Crops will be saved under runs/detect/exp/crops, with a directory for each class detected.
python detect.py --save-crop
[image: Original] https://user-images.githubusercontent.com/26833433/139577918-65cc8f5d-741d-4a88-8753-0154013c624d.jpg
[image: Crop] https://user-images.githubusercontent.com/26833433/139577896-aa26b07c-466d-4057-9bfe-b01b56007587.png YOLOv5 PyTorch Hub
Crops will be saved under runs/detect/exp/crops if save=True, and also returned as a dictionary with crops as numpy arrays.
import torch
Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, custom
Images
img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list
Inference
results = model(img)
Results
crops = results.crop(save=True)
-- or --
crops = results.crop(save=True, save_dir='runs/detect/exp') # specify save dir
Good luck ๐ and let us know if you have any other questions!
โ Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov5/issues/1028#issuecomment-1282267078, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQB7G663IDUTMWR7QSBX2DWD2F3JANCNFSM4RXYISZQ . You are receiving this because you were mentioned.Message ID: @.***>
Can I change the file extension from .jpg to .png before used '--save-crop'.
@gobspn hello! Yes, you can change the file extension from .jpg to .png before using '--save-crop' in detect.py or results.crop(save=True)
in YOLOv5 PyTorch Hub. The saved cropped images will also have the same file extension as the input images.
โQuestion
how to take out coordinates of bounding box image after detection ? or is there any other method to crop ?
Additional context