Skip to content

Commit

Permalink
feat: rotation option for infer.py tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre-Delplanque committed Jun 17, 2023
1 parent c0bfc31 commit b082fc4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tools/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Please contact the author Alexandre Delplanque (alexandre.delplanque@uliege.be) for any questions.
Last modification: March 29, 2023
Last modification: April 28, 2023
"""
__author__ = "Alexandre Delplanque"
__license__ = "CC BY-NC-SA 4.0"
Expand Down Expand Up @@ -60,6 +60,8 @@
help='thumbnail size. Defaults to 256.')
parser.add_argument('-pf', type=int, default=10,
help='print frequence. Defaults to 10.')
parser.add_argument('-rot', type=int, default=0,
help='number of degrees to rotate the images (counter clockwise). Defaults to 0.')

args = parser.parse_args()

Expand All @@ -86,10 +88,16 @@ def main():
if i.endswith(('.JPG','.jpg','.JPEG','.jpeg'))]
n = len(img_names)
df = pandas.DataFrame(data={'images': img_names, 'x': [0]*n, 'y': [0]*n, 'labels': [1]*n})

albu_transforms = []
if args.rot != 0:
albu_transforms.append(A.Rotate(limit=(args.rot,args.rot), p=1))
albu_transforms.append(A.Normalize(mean=img_mean, std=img_std))

dataset = CSVDataset(
csv_file = df,
root_dir = args.root,
albu_transforms = [A.Normalize(mean=img_mean, std=img_std)],
albu_transforms = albu_transforms,
end_transforms = [DownSample(down_ratio = 2, anno_type = 'point')]
)

Expand Down Expand Up @@ -147,6 +155,8 @@ def main():
img_names = numpy.unique(detections['images'].values).tolist()
for img_name in img_names:
img = Image.open(os.path.join(args.root, img_name))
if args.rot != 0:
img = img.rotate(args.rot, expand=True)
img_cpy = img.copy()
pts = list(detections[detections['images']==img_name][['y','x']].to_records(index=False))
pts = [(y, x) for y, x in pts]
Expand Down

0 comments on commit b082fc4

Please sign in to comment.