【发布时间】:2019-05-30 15:03:51
【问题描述】:
我在 OpenCV (python) 中有一个简单的媒体播放器。我想使用轨迹栏显示视频的“时间”。首先,这是我用来将帧数转换为时间的函数:
def _seconds(value, framerate):
if isinstance(value, str): # value seems to be a timestamp
_zip_ft = zip((3600, 60, 1, 1/framerate), value.split(':'))
return sum(f * float(t) for f,t in _zip_ft)
elif isinstance(value, (int, float)): # frames
return value / framerate
else:
return 0
def _timecode(seconds, framerate):
return '{h:02}:{m:02}:{s:02}' \
.format(h=int(seconds/3600),
m=int(seconds/60%60),
s=int(seconds%60))
def _frames(seconds, framerate):
return seconds * framerate
def timecode_to_frames(timecode, framerate, start=None):
return _frames(_seconds(timecode, framerate) - _seconds(start, framerate), framerate)
def frames_to_timecode(frames, framerate, start=None):
return _timecode(_seconds(frames, framerate) + _seconds(start,framerate), framerate)
在一天结束时,返回的是格式为 Hours:Minutes:Seconds 的字符串。
所以...我意识到使用轨迹栏来执行此操作可能是不可能的,因为定义...
C++: int createTrackbar(const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onChange=0, void* userdata=0)
Python: cv.CreateTrackbar(trackbarName, windowName, value, count, onChange) → None
Parameters:
trackbarname – Name of the created trackbar.
winname – Name of the window that will be used as a parent of the created trackbar.
value – Optional pointer to an integer variable whose value reflects the position of the slider. Upon creation, the slider position is defined by this variable.
count – Maximal position of the slider. The minimal position is always 0.
onChange – Pointer to the function to be called every time the slider changes position. This function should be prototyped as void Foo(int,void*); , where the first parameter is the trackbar position and the second parameter is the user data (see the next parameter). If the callback is the NULL pointer, no callbacks are called, but only value is updated.
userdata – User data that is passed as is to the callback. It can be used to handle trackbar events without using global variables.
...和...
Python: cv2.setTrackbarPos(trackbarname, winname, pos) → None
C: void cvSetTrackbarPos(const char* trackbar_name, const char* window_name, int pos)
Python: cv.SetTrackbarPos(trackbarName, windowName, pos) → None
Parameters:
trackbarname – Name of the trackbar.
winname – Name of the window that is the parent of trackbar.
pos – New position.
...非常清楚必须将int 传递给“pos”以及其他所有内容。
你们有解决办法吗? 谢谢。
【问题讨论】:
-
OpenCV 的轨迹栏是超级基本的,带有 GUI 选项......并且只允许传递 int......我建议使用另一个 GUI 框架,如 Qt 或在你的情况下为 tkinter跨度>
-
你也可以把视频的时间写在图片中而不是轨迹栏...这可以用opencv来完成。如果只想显示时间。如果你还想操纵视频的时间,我之前的评论是站着的
标签: python opencv media-player