williamfzc / stagesepx

detect stages in video automatically
MIT License
434 stars 125 forks source link

使用pathlib.PosixPath类型路径时,cv2.VideoCapture()方法报错 #102

Closed ssfanli closed 4 years ago

ssfanli commented 4 years ago

现象

初始化VideoObject()时候,传入pathlib.PosixPath类型的路径报错,报错信息如下:

/Users/ssfanli/Myfolder/repository/YSPDataSets/no_track/video/iPhone/cold_start/with_ad/19.mp4 <class 'pathlib.PosixPath'>
Traceback (most recent call last):
  File "/Users/ssfanli/Myfolder/repository/work_with_stagesepx/dynamic/classify_with_model.py", line 16, in <module>
    video = VideoObject(video_path)
  File "/usr/local/lib/python3.7/site-packages/stagesepx/video.py", line 99, in __init__
    with toolbox.video_capture(path) as cap:
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.7/site-packages/stagesepx/toolbox.py", line 25, in video_capture
    video_cap = cv2.VideoCapture(video_path)
TypeError: an integer is required (got type PosixPath)

看了下video.py的源码好像是这块with toolbox.video_capture(path) as cap传入的path类型不对,应该传self.path,因为self.path已经转为str类型了

williamfzc commented 4 years ago

666 因为我们这边还是偏好老式的 os.path 所以一直没发现这个问题

ssfanli commented 4 years ago

666 因为我们这边还是偏好老式的 os.path 所以一直没发现这个问题

大佬神速[强]

yumath commented 1 year ago

@ssfanli .__str__()即可解决问题