gen_aicity_mtmct_data.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import sys
  16. import cv2
  17. import glob
  18. def video2frames(sourceVdo, dstDir):
  19. videoData = cv2.VideoCapture(sourceVdo)
  20. count = 0
  21. while (videoData.isOpened()):
  22. count += 1
  23. ret, frame = videoData.read()
  24. if ret:
  25. cv2.imwrite(f"{dstDir}/{count:07d}.jpg", frame)
  26. if count % 20 == 0:
  27. print(f"{dstDir}/{count:07d}.jpg")
  28. else:
  29. break
  30. videoData.release()
  31. def transSeq(seqs_path, new_root):
  32. sonCameras = glob.glob(seqs_path + "/*")
  33. sonCameras.sort()
  34. for vdoList in sonCameras:
  35. Seq = vdoList.split('/')[-2]
  36. Camera = vdoList.split('/')[-1]
  37. os.system(f"mkdir -p {new_root}/{Seq}/images/{Camera}/img1")
  38. roi_path = vdoList + '/roi.jpg'
  39. new_roi_path = f"{new_root}/{Seq}/images/{Camera}"
  40. os.system(f"cp {roi_path} {new_roi_path}")
  41. video2frames(f"{vdoList}/vdo.avi",
  42. f"{new_root}/{Scd eq}/images/{Camera}/img1")
  43. if __name__ == "__main__":
  44. seq_path = sys.argv[1]
  45. new_root = 'aic21mtmct_vehicle'
  46. seq_name = seq_path.split('/')[-1]
  47. data_path = seq_path.split('/')[-3]
  48. os.system(f"mkdir -p {new_root}/{seq_name}/gt")
  49. os.system(f"cp {data_path}/eval/ground*.txt {new_root}/{seq_name}/gt")
  50. # extract video frames
  51. transSeq(seq_path, new_root)