Divide a string in python using specific substring -
i have txt file information regarding bounding boxes in image. open txt file automatically read information , crop image using coordinates of bounding box. text file has following format:
folder\file_0001.jpg 75 165 87 177 106.750000 108.250000 143.750000 108.750000 131.250000 127.250000 106.250000 155.250000 142.750000 155.250000 folder\file_0002.jpg 86 162 93 169 104.750000 110.750000 145.750000 114.250000 126.250000 139.750000 104.250000 155.250000 139.250000 159.750000
the useful bounding boxes coordinates first 4 integer after file name. how can separate values , use cropping images in python?
you can use split
split string on spaces, slice returned list elements out interested in.
with open('text.txt') f: line in f: coords = line.split()[1:5] # use slicing 2nd through 5th elements
Comments
Post a Comment