# Saving crops from yolo model inference

**URL:** <https://community.ultralytics.com/t/saving-crops-from-yolo-model-inference/453>\
**Category:** Support\
**Tags:** code\
**Created:** [October 30, 2024, 10:17am UTC](https://community.ultralytics.com/t/saving-crops-from-yolo-model-inference/453 "2024-10-30T10:17:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fahim\_Anwar](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/fahim_anwar/32/341_2.png) [@Fahim\_Anwar](https://community.ultralytics.com/u/Fahim_Anwar)\
**Post date:** [October 30, 2024, 10:17am UTC](https://community.ultralytics.com/t/saving-crops-from-yolo-model-inference/453/1 "2024-10-30T10:17:07Z")

</div>

oad the image  
frame = cv2.imread(image\_path)

# Check if the image was successfully loaded

if frame is None:  
print(f"Error: Could not load image from {image\_path}")  
exit(1)

# Resize the frame to fit the screen resolution if it’s too large

screen\_width = 1280  
screen\_height = 720  
(h, w) = frame.shape[:2]  
if w \> screen\_width or h \> screen\_height:  
scale = min(screen\_width / w, screen\_height / h)  
new\_width = int(w \* scale)  
new\_height = int(h \* scale)  
frame = cv2.resize(frame, (new\_width, new\_height))

# Run YOLO model inference on the frame

results = model(frame)

# Annotate the frame with the detection results

annotated\_frame = results[0].plot() # Plot detections on the frame

# Optionally, display the frame (press ‘q’ to exit)

cv2.imshow(‘YOLOv8 Inference’, annotated\_frame)

# Wait for the user to press ‘q’ to exit the display

while True:  
if cv2.waitKey(1) & 0xFF == ord(‘q’):  
break

# Release resources

cv2.destroyAllWindows()

 ![Screenshot from 2024-10-30 16-07-03](https://us1.discourse-cdn.com/flex001/uploads/ultralytics1/original/1X/7abe77fcf14b47c0f9d18fe2c746743009be1a25.png)

this is the detected bounding boxes. Now i want to save the crop from this bouding boxes. Give me solutions

---

<div class="post-metadata">

**Author:** ![BurhanQ](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/burhanq/32/7_2.png) [@BurhanQ](https://community.ultralytics.com/u/BurhanQ)\
**Post date:** [October 30, 2024, 12:08pm UTC](https://community.ultralytics.com/t/saving-crops-from-yolo-model-inference/453/2 "2024-10-30T12:08:08Z")

</div>

1. Please don’t demand answers, “Give me solutions” is not a considerate way to ask for assistance.
2. You should **always** check the documentation for existing capabilities or examples, as there are many already outlined (including this one). If you have trouble finding an answer in the documentation, try using the search feature 🔍 to locate what you’re looking for.  
 ![image](https://us1.discourse-cdn.com/flex001/uploads/ultralytics1/original/1X/009b27bcb9c1f57d82d94415bc9deb58bb5161a4.jpeg)
3. You’ll find what you’re looking for under [inference arguments](https://docs.ultralytics.com/modes/predict/#inference-arguments) in the documentation. You can use the argument `save_crop=True` when executing inference with your model.
