'Is there feasible way to delete picture except detected object?

i want to detect a specific object with Yolov5 but i want to delete rest of picture except cardboard boxes. I have a code that measuring objects with opencv but it measuring everything. I want to detect only cardboard boxes. Should i delete rest of picture or is there any feasible solution for this?

measuring everything



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source