viz.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import numpy as np
  2. import cv2 as cv
  3. import argparse
  4. import os
  5. def main():
  6. argparser = argparse.ArgumentParser(description='Vizualization of the LSBP/GSOC background subtraction algorithm.')
  7. argparser.add_argument('-g', '--gt', help='Directory with ground-truth frames', required=True)
  8. argparser.add_argument('-f', '--frames', help='Directory with input frames', required=True)
  9. argparser.add_argument('-l', '--lsbp', help='Display LSBP instead of GSOC', default=False)
  10. args = argparser.parse_args()
  11. gt = map(lambda x: os.path.join(args.gt, x), os.listdir(args.gt))
  12. gt.sort()
  13. f = map(lambda x: os.path.join(args.frames, x), os.listdir(args.frames))
  14. f.sort()
  15. gt = np.uint8(map(lambda x: cv.imread(x, cv.IMREAD_GRAYSCALE), gt))
  16. f = np.uint8(map(lambda x: cv.imread(x, cv.IMREAD_COLOR), f))
  17. if not args.lsbp:
  18. bgs = cv.bgsegm.createBackgroundSubtractorGSOC()
  19. else:
  20. bgs = cv.bgsegm.createBackgroundSubtractorLSBP()
  21. for i in xrange(f.shape[0]):
  22. cv.imshow('Frame', f[i])
  23. cv.imshow('Ground-truth', gt[i])
  24. mask = bgs.apply(f[i])
  25. bg = bgs.getBackgroundImage()
  26. cv.imshow('BG', bg)
  27. cv.imshow('Output mask', mask)
  28. k = cv.waitKey(0)
  29. if k == 27:
  30. break
  31. if __name__ == '__main__':
  32. main()