some cleanup
This commit is contained in:
parent
9e1c5fbccd
commit
c79888bc0d
47
ocr.py
47
ocr.py
|
@ -81,34 +81,7 @@ def set_sub_diff(n, f):
|
|||
return fout
|
||||
|
||||
|
||||
def fill_text(clip):
|
||||
out_clip = core.std.BlankClip(clip)
|
||||
fill_val = 255
|
||||
|
||||
for n, frame in enumerate(clip.frames()):
|
||||
fcopy = frame.copy()
|
||||
print(n, dir(fcopy[0]), file=sys.stderr)
|
||||
plane = fcopy[0]
|
||||
w, h = plane.shape
|
||||
|
||||
for x in range(w):
|
||||
fill_next = False
|
||||
last_v = 0
|
||||
for y in range(h):
|
||||
v = plane[x, y]
|
||||
if v and v != last_v:
|
||||
fill_next = not fill_next
|
||||
else:
|
||||
plane[x, y] = fill_val if fill_next else 0
|
||||
|
||||
last_v = v
|
||||
|
||||
out_clip[n][0] = plane
|
||||
|
||||
return out_clip
|
||||
|
||||
|
||||
def dump(n, f):
|
||||
def dump(n, f, ocr):
|
||||
if (f.props.get('OCRString') or f.props['_SceneChangePrev'] == 1
|
||||
or f.props['_SceneChangeNext'] == 1):
|
||||
with open("ocr_dump.json", mode="a") as j:
|
||||
|
@ -141,7 +114,7 @@ def apply_ocr(clip):
|
|||
options=["enable_noise_removal", "false",
|
||||
"tessedit_char_whitelist", alphabet,
|
||||
"user_defined_dpi", "70"])
|
||||
# ocr_clip = core.std.FrameEval(clip, functools.partial(run_ocr, clip=clip, ocr=ocr_clip), clip)
|
||||
# ocr_clip = core.std.FrameEval(clip, functools.partial(run_ocr, clip=clip, ocr=ocr_clip), clip) # noqa
|
||||
ocr_clip = ocr_clip.text.FrameProps()
|
||||
return ocr_clip
|
||||
|
||||
|
@ -175,12 +148,16 @@ def main(hardsub_file, raw_file, comparison=False):
|
|||
|
||||
if comparison:
|
||||
final = lvf.comparison.stack_vertical(
|
||||
lvf.comparison.stack_horizontal(sub_diff.resize.Point(format=src1.format),
|
||||
brightness_ocr.resize.Point(format=src1.format),
|
||||
src2.text.FrameProps()),
|
||||
lvf.comparison.stack_horizontal(ocr.resize.Point(format=src1.format),
|
||||
vsutil.get_y(src1).std.Binarize(whitethr).resize.Point(format=src1.format),
|
||||
src1.text.FrameProps())
|
||||
lvf.comparison.stack_horizontal(
|
||||
sub_diff.resize.Point(format=src1.format),
|
||||
brightness_ocr.resize.Point(format=src1.format),
|
||||
src2.text.FrameProps()
|
||||
),
|
||||
lvf.comparison.stack_horizontal(
|
||||
ocr.resize.Point(format=src1.format),
|
||||
vsutil.get_y(src1).std.Binarize(whitethr).resize.Point(format=src1.format),
|
||||
src1.text.FrameProps()
|
||||
)
|
||||
)
|
||||
final = final.text.FrameNum(9)
|
||||
final = final.text.FrameProps()
|
||||
|
|
Loading…
Reference in New Issue