some cleanup

This commit is contained in:
odrling 2022-12-28 18:39:17 +01:00
parent 9e1c5fbccd
commit c79888bc0d
No known key found for this signature in database
GPG Key ID: A0145F975F9F8B75
1 changed files with 12 additions and 35 deletions

47
ocr.py
View File

@ -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()