visualize_dataset.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # visualize created dataset
5 # You can view next image by pressing keys ('q' is quit)
6 
7 import argparse
8 import cv2
9 import numpy as np
10 import os
11 import os.path as osp
12 from PIL import Image as Image_
13 import rospkg
14 
15 
16 def visualize():
17  parser = argparse.ArgumentParser()
18  parser.add_argument('type', help='visualize train or test', choices=['train', 'test'])
19  args = parser.parse_args()
20  rospack = rospkg.RosPack()
21  data_dir = osp.join(rospack.get_path('sound_classification'),
22  'train_data', 'dataset')
23  print("Press 'q' to exit. Press any other keys to show next image.")
24  for f in os.listdir(data_dir):
25  if not f.startswith(args.type) or f.endswith('txt'):
26  continue
27  img = np.array(Image_.open(osp.join(data_dir, f)))
28  img = img[:, :, [2, 1, 0]] # bgr -> rgb
29  cv2.imshow('RGB labeled Image', img)
30  print('{}'.format(f))
31  key = cv2.waitKey(0)
32  if key == ord('q'):
33  exit()
34 
35 
36 if __name__ == '__main__':
37  visualize()
visualize_dataset.visualize
def visualize()
Definition: visualize_dataset.py:16


sound_classification
Author(s):
autogenerated on Fri May 16 2025 03:12:55