Implementation:Datajuicer Data juicer VideoOcrAreaRatioFilter
| Knowledge Sources | |
|---|---|
| Domains | Data_Quality, Filtering |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Concrete tool for filtering data samples based on video OCR text area ratio provided by Data-Juicer.
Description
VideoOcrAreaRatioFilter is a filter operator that keeps samples where the ratio of detected text (OCR) area to total frame area falls within a specified range. It extends Filter and uses the two-phase compute_stats/process pattern. It samples frames uniformly from the video, uses EasyOCR to detect text regions in configurable languages (default: Chinese simplified and English), computes the area of detected text bounding boxes using the triangle_area() helper, and calculates the ratio of total text area to frame area. The mean ratio across sampled frames is cached under video_ocr_area_ratio. Supports 'any'/'all' strategy and CUDA acceleration. Marked as UNFORKABLE. Useful for filtering videos with excessive on-screen text or ensuring minimum text presence.
Usage
Import when filtering based on video OCR text area ratio. Configure in YAML or Python.
Code Reference
Source Location
- Repository: Datajuicer_Data_juicer
- File: data_juicer/ops/filter/video_ocr_area_ratio_filter.py
Signature
@OPERATORS.register_module("video_ocr_area_ratio_filter")
class VideoOcrAreaRatioFilter(Filter):
def __init__(self, min_area_ratio: float = 0, max_area_ratio: float = 1.0, frame_sample_num: PositiveInt = 3, languages_to_detect: Union[str, List[str]] = ["ch_sim", "en"], any_or_all: str = "any", *args, **kwargs):
Import
from data_juicer.ops.filter.video_ocr_area_ratio_filter import VideoOcrAreaRatioFilter
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| min_area_ratio | float | No | Minimum OCR area ratio (default: 0) |
| max_area_ratio | float | No | Maximum OCR area ratio (default: 1.0) |
| frame_sample_num | PositiveInt | No | Number of frames to sample (default: 3) |
| languages_to_detect | Union[str, List[str]] | No | Languages for OCR detection (default: ["ch_sim", "en"]) |
| any_or_all | str | No | Keep strategy: "any" or "all" (default: "any") |
Outputs
| Name | Type | Description |
|---|---|---|
| samples | Dict | Filtered samples with video_ocr_area_ratio stat computed |
Usage Examples
YAML Configuration
process:
- video_ocr_area_ratio_filter:
min_area_ratio: 0
max_area_ratio: 0.5
frame_sample_num: 3
Python API
from data_juicer.ops.filter.video_ocr_area_ratio_filter import VideoOcrAreaRatioFilter
op = VideoOcrAreaRatioFilter(max_area_ratio=0.5, frame_sample_num=3)