2

hello i am working on this project in YOLOv5. i want to only save the image when the boundary box is 20% or more of the total image size. i also want it to only save the detection when it is atleast 10% away from all sides of the image here is visualization of what im trying to do hope it helps https://i.stack.imgur.com/g8Ne4.png

currently i have this code that displays x1 1277 y1 641 x2 1819 y2 829 H 188 W 542 Img size : 1080 2048

x1 = int(xyxy[0].item())
                y1 = int(xyxy[1].item())
                x2 = int(xyxy[2].item())
                y2 = int(xyxy[3].item())
                print("x1 ", x1)
                print("y1 ", y1)
                print("x2 ", x2)
                print("y2 ", y2)

        # Bounding box size (Alternativt så kan du bruke xywh objektet)
                w = x2 - x1
                h = y2 - y1
                print("H ", h)
                print("W ",w)

        # Image size
                height, width, channels = imc.shape
                print("Img size : ",height, width)
                
                savename= (Path(path).name).replace(".", "_")
                print("Savename : ",savename)
                print("Frame :", frame)

1 Answers1

0

You can Implement this as mentioned below.

            x1 = int(xyxy[0].item())
            y1 = int(xyxy[1].item())
            x2 = int(xyxy[2].item())
            y2 = int(xyxy[3].item())
            print("x1 ", x1)
            print("y1 ", y1)
            print("x2 ", x2)
            print("y2 ", y2)

            w = x2 - x1
            h = y2 - y1

            print("H ", h)
            print("W ",w)
            height, width, channels = imc.shape
            print("Img size : ",height, width)
            
            width_less_ten_percent = width*0.9
            height_less_ten_percent = height * 0.9
            
            #check size of bounding box greater than 20% of image size
            if ((h >= (height *0.2)) and (w>=(width *0.2))):  
                savename= (Path(path).name).replace(".", "_")
                print("Savename : ",savename)
                print("Frame :", frame)
                   
            #save image, with bouding box at least 10% from width, height 
            if((h<=height_less_ten_percent) and (w<=width_less_ten_percent)):
                savename= (Path(path).name).replace(".", "_")
                print("Savename : ",savename)
                print("Frame :", frame)

This is a pseudocode, you will need to change things according to your code.