我在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"基本上其他一切。
你们有解决方案吗? 感谢。
答案 0 :(得分:0)
尝试使用Scale即tkinter中提供的滑块小部件