Skip to content

Commit

Permalink
Fix the result when frame is missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Jul 8, 2023
1 parent d4e1957 commit 0c70a91
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 199 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ flowchart LR
- [RapidVideOCR高级教程(有python基础的小伙伴)](https://github.com/SWHL/RapidVideOCR/wiki/RapidVideOCR%E9%AB%98%E7%BA%A7%E6%95%99%E7%A8%8B%EF%BC%88%E6%9C%89python%E5%9F%BA%E7%A1%80%E7%9A%84%E5%B0%8F%E4%BC%99%E4%BC%B4%EF%BC%89)

### 更新日志([more](https://github.com/SWHL/RapidVideOCR/wiki/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97)
- 🤓2023-07-08 v2.2.2 update:
- 修复批量识别时,不能读取中文路径的问题
- 修复漏轴时,SRT中跳过问题。目前当出现某一轴未能识别,则会空出位置,便于校对。
- 🐲2023-06-22 Desktop v0.0.3 update:
- 整合VideoSubFinder界面,增加视频批处理
- 优化多次选取之后,路径保存问题
Expand All @@ -64,8 +67,6 @@ flowchart LR
- 将VSF的CLI整合到库中,只需指定`VideoSubFinderWXW.exe`的全路径即可。
- 增加批量识别功能,指定视频目录,即可自动提取目录下所有视频字幕
- 使用示例, 参见:[demo.py](https://github.com/SWHL/RapidVideOCR/blob/main/demo.py)
- ♠2023-06-04 Desktop v0.0.2 update:
- 修复issue #30: 保留上次选择的目录

### 写在最后
- 微信扫描以下二维码,关注**RapidAI公众号**,回复video即可加入RapidVideOCR微信交流群:
Expand Down
5 changes: 3 additions & 2 deletions docs/README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ flowchart LR
- [☆☆☆ RapidVideOCR Advanced Tutorial (Partners with python foundation)](https://github.com/SWHL/RapidVideOCR/wiki/RapidVideOCR%E9%AB%98%E7%BA%A7%E6%95%99%E7%A8%8B%EF%BC%88%E6%9C%89python%E5%9F%BA%E7%A1%80%E7%9A%84%E5%B0%8F%E4%BC%99%E4%BC%B4%EF%BC%89)

### Change log ([more](https://github.com/SWHL/RapidVideOCR/wiki/Changelog))
- 🤓2023-07-08 v2.2.2 update:
- Fixed the problem that the Chinese path could not be read during batch recognition
- Skip issue in SRT when fixing missing axes. At present, when a certain axis fails to be recognized, the position will be vacated, which is convenient for proofreading.
- 🐲2023-06-22 Desktop v0.0.3 update:
- Integrate VideoSubFinder interface, increase video batch processing.
- Optimize the problem of path preservation after multiple selections.
Expand All @@ -61,8 +64,6 @@ flowchart LR
- To integrate VSF's CLI into the library, just specify the full path of `VideoSubFinderWXW.exe`.
- Add batch recognition function, specify the video directory, and then automatically extract all video subtitles in the directory
- Use example, see: [demo.py](https://github.com/SWHL/RapidVideOCR/blob/main/demo.py)
- ♠ 2023-06-04 Desktop v0.0.2 update:
- Fix issue #30: Keep the last selected directory.


### Announce
Expand Down
4 changes: 2 additions & 2 deletions docs/doc_whl.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pip install rapid_videocr
from rapid_videocr import RapidVideOCR

extractor = RapidVideOCR(is_concat_rec=True,
concat_batch=10,
out_format='srt')
concat_batch=10,
out_format='srt')

rgb_dir = 'RGBImages'
save_dir = 'outputs'
Expand Down
78 changes: 39 additions & 39 deletions rapid_videocr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@
class RapidVideoSubFinderOCR:
def __init__(self, vsf_exe_path: str = None, **ocr_params) -> None:
if vsf_exe_path is None:
raise ValueError('vsf_exe_path must not be None.')
raise ValueError("vsf_exe_path must not be None.")

self.vsf = VideoSubFinder(vsf_exe_path)
self.video_ocr = RapidVideOCR(**ocr_params)
self.video_formats = ['.mp4', '.avi', '.mov', '.mkv']
self.video_formats = [".mp4", ".avi", ".mov", ".mkv"]
self.logger = get_logger()

def __call__(self, video_path: str, output_dir: str = 'outputs'):
def __call__(self, video_path: str, output_dir: str = "outputs"):
if Path(video_path).is_dir():
video_list = Path(video_path).rglob('*.*')
video_list = Path(video_path).rglob("*.*")
video_list = [
v for v in video_list if v.suffix.lower() in self.video_formats
]
else:
video_list = [video_path]

self.logger.info(
'Extracting subtitle images with VideoSubFinder (takes quite a long time) ...'
"Extracting subtitle images with VideoSubFinder (takes quite a long time) ..."
)
video_num = len(video_list)
for i, one_video in enumerate(video_list):
self.logger.info(
f'[{i+1}/{video_num}] Starting to extract {one_video} key frame'
f"[{i+1}/{video_num}] Starting to extract {one_video} key frame"
)
with tempfile.TemporaryDirectory() as tmp_dir:
try:
self.vsf(str(one_video), tmp_dir)
except Exception as e:
self.logger.error(f'Extract {one_video} error, {e}, skip')
self.logger.error(f"Extract {one_video} error, {e}, skip")
continue

self.logger.info(f'[{i+1}/{video_num}] Starting to run {one_video} ocr')
self.logger.info(f"[{i+1}/{video_num}] Starting to run {one_video} ocr")

rgb_dir = Path(tmp_dir) / 'RGBImages'
rgb_dir = Path(tmp_dir) / "RGBImages"
if not list(rgb_dir.iterdir()):
self.logger.warning(
f'Extracting frames from {one_video} is 0, skip'
f"Extracting frames from {one_video} is 0, skip"
)
continue

Expand All @@ -61,71 +61,71 @@ def __call__(self, video_path: str, output_dir: str = 'outputs'):
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
'-vsf',
'--vsf_exe_path',
"-vsf",
"--vsf_exe_path",
type=str,
default=None,
help='The full path of VideoSubFinderWXW.exe.',
help="The full path of VideoSubFinderWXW.exe.",
)
parser.add_argument(
'-video_dir',
'--video_dir',
"-video_dir",
"--video_dir",
type=str,
default=None,
help='The full path of video or the path of video directory.',
help="The full path of video or the path of video directory.",
)
parser.add_argument(
'-i',
'--img_dir',
"-i",
"--img_dir",
type=str,
default=None,
help='The full path of RGBImages or TXTImages.',
help="The full path of RGBImages or TXTImages.",
)
parser.add_argument(
'-s',
'--save_dir',
"-s",
"--save_dir",
type=str,
default='outputs',
default="outputs",
help='The path of saving the recognition result. Default is "outputs" under the current directory.',
)
parser.add_argument(
'-o',
'--out_format',
"-o",
"--out_format",
type=str,
default='all',
choices=['srt', 'txt', 'all'],
default="all",
choices=["srt", "txt", "all"],
help='Output file format. Default is "all".',
)
parser.add_argument(
'-m',
'--mode',
"-m",
"--mode",
type=str,
default='single',
choices=['single', 'concat'],
default="single",
choices=["single", "concat"],
help='Which mode to run (concat recognition or single recognition). Default is "single".',
)
parser.add_argument(
'-b',
'--concat_batch',
"-b",
"--concat_batch",
type=int,
default=10,
help='The batch of concating image nums in concat recognition mode. Default is 10.',
help="The batch of concating image nums in concat recognition mode. Default is 10.",
)
parser.add_argument(
'-p',
'--print_console',
"-p",
"--print_console",
type=bool,
default=0,
choices=[0, 1],
help='Whether to print the subtitle results to console. 1 means to print results to console. Default is 0.',
help="Whether to print the subtitle results to console. 1 means to print results to console. Default is 0.",
)
args = parser.parse_args()

is_concat_rec = 'concat' in args.mode
is_concat_rec = "concat" in args.mode

if not (args.vsf_exe_path is None and args.video_dir is None):
raise ValueError(
'--vsf_exe_path or --video_dir must not be None at the same time.'
"--vsf_exe_path or --video_dir must not be None at the same time."
)

if args.vsf_exe_path and args.video_dir:
Expand All @@ -148,5 +148,5 @@ def main() -> None:
extractor(args.img_dir, args.save_dir)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit 0c70a91

Please sign in to comment.