duangsuse::Echo
可以先开源…… 完成了! https://github.com/duangsuse/extract-subtitles
./extract_subtitles.py -crop '(313,951)(1343,45)' --crop-debug SomethingNew.mp4
[Video Path] SomethingNew.mp4
[Crop] [[313, 951], [1343, 45]]
[Threshold] None
[Subtitle Language] chi_sim
[Frame Directory] frames
[Filter Window Size] 13
Extracting key frames...
[Video Props] (2837, 29, 1920, 1080)
100% |#############################################################################|
smooth [...x386], 13 hanning
q120 How can something be so nice? 面 本
177 How can sgomething be snicey
3
192 Yet so shocking, yet so mice,|
3
220 Yet so shocking, yet so mice,|
241 Yet so shocking, yet so iiice,|
261 [ee二和:和-TAR om
269 [ee二和iT:和-TAR 5owm
284 [ee二和[让:和-IT om
299 [wei二和:和 -TAN Dowm
306 [ee二和:和-IT 5owm
320 How can something bel sg new?
338 YetSoknown but yet,SsSomnew?
361 YetSoknown but yetSomnew?
duangsuse::Echo
./extract_subtitles.py -crop '(313,951)(1343,45)' --crop-debug SomethingNew.mp4 [Video Path] SomethingNew.mp4 [Crop] [[313, 951], [1343, 45]] [Threshold] None [Subtitle Language] chi_sim [Frame Directory] frames [Filter Window Size] 13 Extracting…
This media is not supported in your browser
VIEW IN TELEGRAM
duangsuse::Echo
🤔 Sticker
说实在话,其实原作者的算法也没有什么问题,不仅在于……关键还是在于没有 windowing,数据一下子都处理完,不能按照固定的大小一部分一部分处理
#Python #code 真可怜,无用的代码被丢掉了…… 看来纪念下吧
printedCall_fmt = lambda op, args: f"{getFuncName(op)} {' '.join(map(str, args))}"
printedCall_on_result = lambda r: print("" if r == None else f" -> {r}")
def printedCall(op, fmt = printedCall_fmt, on_result = printedCall_on_result):
def _invoke(*args, **kwargs):
print(fmt(op, args), end="")
res = op(*args, **kwargs)
on_result(res)
return res
return _invoke def getFuncName(func): return findall("^<.*function (\S+)", repr(func))[0]
duangsuse::Echo
说实在话,其实原作者的算法也没有什么问题,不仅在于……关键还是在于没有 windowing,数据一下子都处理完,不能按照固定的大小一部分一部分处理
🤔 原文件采用先保存在 list 里的方法,我利用 generator,换成数据流模式,然后倒着来…… 是不是就不用把所有
UMat 都保持下来了?先来分析一下:原项目的
后期
所以只要在这个函数里分块处理数据(关键是
solveFrameDifferences 会得出 frames 和 frame_diffs,其二等价 map(lambda it: it.value, frames) ,没啥意义后期
ocrWithLocalMaximal() 主要是按从 frame_diffs 计算出的东西,去 filter frame 并且实际 OCR所以只要在这个函数里分块处理数据(关键是
Frame.no 属性有顺序),就可以了from window_slider import Slider<window_slider.slider.Slider at 0x7fd25afc8e10>
s = Slider(3, 0)
s.fit(np.array(range(0, 100000)))
s.slide()array([0, 1, 2])
🤔
https://stackoverflow.com/questions/8991506/iterate-an-iterator-by-chunks-of-n-in-python
def chunked(n, xs):NumPy 的 array 对惰性计算的支持不好,我换了 generator 侧的方案
while True:
try: #< must return when inner gen finished
first = next(xs)
except StopIteration: return
chunk = islice(xs, n)
yield chain((first,) , chunk)
Stack Overflow
Iterate an iterator by chunks (of n) in Python?
Can you think of a nice way (maybe with itertools) to split an iterator into chunks of given size?
Therefore l=[1,2,3,4,5,6,7] with chunks(l,3) becomes an iterator [1,2,3], [4,5,6], [7]
I can thi...
Therefore l=[1,2,3,4,5,6,7] with chunks(l,3) becomes an iterator [1,2,3], [4,5,6], [7]
I can thi...
duangsuse::Echo
🤔我得好好考虑怎么分块运行,再把结果组装回来……
对了,好像很简单啊
最后它的结果,可以用
副作用也一样,有序执行,很正常……
solveFrameDifferences() 的任务拿 chunked(n, xs) 分配一下,然后交给 map(f, xs) 应用给 ocrWithLocalMaxima() 最后它的结果,可以用
reduce(join, xs) 拼接下 list,不就都取回来了🤔副作用也一样,有序执行,很正常……
不对啊…… 好像也有些东西是用 side effects 做 fs IO 来着……
两个依赖 frames 流的调用,我岂不是要求值两遍??!
两个依赖 frames 流的调用,我岂不是要求值两遍??!