gpt4 book ai didi

python - 有视频的opencv trackbar显示时间

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:04 26 4
gpt4 key购买 nike

我在 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)

归根结底,返回的是格式为小时:分钟:秒的字符串。

所以...我意识到使用轨迹栏来执行此操作可能是不可能的,因为定义...

 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”以及其他所有内容。

你们有解决办法吗?谢谢。

最佳答案

尝试使用 Scale,即 tkinter 中提供的 slider 小部件

关于python - 有视频的opencv trackbar显示时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com