# white-block detection tool
**Repository Path**: kosyakovmikhail/white-block-detection-tool
## Basic Information
- **Project Name**: white-block detection tool
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master_gitee
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-05-14
- **Last Updated**: 2024-06-11
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# WB-Analyzer
---
## Installation
1. Prepare environment:
* Install `Python 3.11` from official website.
* Create the virtualenv and switch to it:
```bash
PATH_TO_PYTHON -m venv PATH_TO_VENV
# for cmd
PATH_TO_VENV\Scripts\activate
# for powershell
PATH_TO_VENV\Scripts\Activate.ps1
```
2. Clone repository:
```bash
cd projects_dir
git clone https://rnd-gitlab-msc.huawei.com/rus-os-team/osalgorithms/network/network-api/wb-analyzer.git
```
3. Install WB-analyzer:
```bash
pip install -e wb-analyzer
```
---
## Usage
There are three different ways to use a project:
- Terminal usage (main)
- Webapp usage
- Jupyter-notebook usage
### Terminal usage
1. Replace **config.yml** with your desired configuration file.
2. Run analyzer:
```bash
wb-analyzer -c config.yaml
```
#### Configuration
The *wb-analyzer* support configuration through YAML files. An example configuration file is provided in the repository:
**examples/using_examples/params_example.yaml**.
You can customize this file according to you requirements.
### Web-application usage
1. Open terminal in project directory
2. Start voila local server:
```bash
voila wb-analyzer/src/webapp/web_app_analyzer.ipynb
```
3. Work in browser
### Jupyter-notebook usage
1. Create your_notebook.ipynb *wb-analyzer* dir
2. Run jupyter notebook with open your_notebook.ipynb:
```
jupyter notebook your_notebook.ipynb
```
3. Import modules `ScreenAnalyzer` and `define_scenario_analyzer` **from src/analyzer/processing** in first cell:
```jupyter
from src.analyzer.processing import AnalyzerConf, define_scenario_analyzer
from src.analyzer.utils import plot_stats
```
4. Create configuration, iniatialize analyzer and start calculation:
```jupyter
config = AnalyzerConf(...)
analyzer = define_scenario_analyzer(config)
wb_count, stats = analyzer.calculate_white_blocks()
```
5. If necessary plot statistics
```jupyter
plot_stats(stats)
```
An example notebook.ipynb file is provided in the repository:
**wb-analyzer/examples/weibo/weibo_analyzer_example.ipynb**.
You can customize this file according to you requirements.
---
## Screen analyzer configuration
There is *AnalyzerConf* class for configuration main *ScreenAnalyzer* class.
Use .yml (or .yaml) file for terminal usage. In web-application usage all parameters will be on browser screen.
For Jupyter-notebook you can import and define class *AnalyzerConf*.
### Parameters description
There are all available parameters for screen analyzer. Remember that the settings are different for different scenarios. See the next section below to determine the necessary parameters for your scenario.
| Parameter | Type | Description | Example |
|------------------------------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| **input_video_path** | *str* | path to the screen record video | 'path/to/input/video/file.mp4' |
| **output_video_path** | *str* | path for saving output video | 'path/to/output/video/file.mp4' |
| **stats_path** | *str* | path were statistics will be saved | 'path/to/output/stats/file.csv' |
| **stats_plot_path** | *str* | path where statistic plot will be saved | 'path/to/output/plot/file.html' |
| **wb_rgb_values** | *tuple[tuple[int]]* | values of white block's colour in ((R, G, B)) (can be more than one value) | [[239, 239, 239], [198, 198, 198]] |
| **wb_rgb_range_delta** | *int* | range value for each channel ((R, G, B)) wb_rgb_values. For ex.: if delta = 5, wb_rgb_values = [[239, 239, 239]] -> wb'search will be between [234, 234, 234] and [244, 244, 244] | 5 |
| **wb_area_threshold** | *int* | min area of white block in pixels | 10000 |
| **wb_is_empty** | *bool* | property of white block - is wb empty (consist of only **wb_rgb_values** color) | True |
| **wb_is_simple** | *bool* | property of white block - is wb simple (contour shape is simple, when contour_area / (w * h of boundary rectangle > 80%) | True |
| **screen_vertical_borders** | *dict[str, int]* | border in pixel count for crop frame[vertical_border['top']:-vertical_border[bottom], :, :] | {'top': 135, 'bottom': 125} |
| **vertical_separator_width** | *int* | vertical separator width in pixels | 10 |
| **show_progressbar** | *bool* | show progress bar | True |
| **scenario** | *str* | scenario name = 'default', 'sohu', 'gallery' or None (which mean default scenario) | 'default' |
| **wb_square_size** | *int* | square size of white block | 145 |
| **grid_params** | *dict[str, int]* | grid size with specified width | {'horizontal_line_width': 3, 'vertical_line_width': 2} |
| **screen_scrollbar_width** | *int* | screen scrollbar width | 50 |
| **line_rgb_values** | *tuple[tuple[int]]* | values of horizontal line in ((R, G, B)) (can be more than one value) | [[210, 210, 210], [220, 220, 220]] |
| **line_rgb_range_delta** | *int* | horizontal line range delta for search channel ((R, G, B)) line_rgb_values. For ex.: if delta = 10, line_rgb_values = [[210, 210, 210]] -> line's search will be between [200, 200, 200] and [220, 220, 220] | 10 |
| **line_step** | *int* | horizontal step between two lines in pixels | 150 |
| **horizontal_search_border** | *dict[str, int]* | horizontal search border with keys 'left', 'right' | {'left': 30, 'right': 195} |
| **input_pattern_path** | *str* or *tuple[str]* | path to image(s) of white block's pattern(s) | ['path/to/pattern_1.png', 'path/to/pattern_2.png'] |
| **pattern_corr_threshold** | *float* | threshold for pattern recognition: if correlation coefficient bigger than threshold -> object contour marked as white block | 0.5 |
| **use_clahe** | *bool* | use CLAHE algorithm for increasing image contrast | True |
### Scenarios
Define *scenario* parameter for correct work of screen analyzer and nescesary parameters for each scenario.
There are 4 scenario usage of screen analyzer: *default*, *gallery*, *sohu* and *pattern*.
Below is a list of scenarios with the necessary parameters:
- default: classic usage for most apps:
- input_video_path
- wb_rgb_values
- wb_rgb_range_delta
- wb_area_threshold
- sohu: special usage for Sohu News app:
- input_video_path
- wb_rgb_values
- wb_rgb_range_delta
- wb_area_threshold
- line_rgb_values
- line_rgb_range_delta
- line_step
- vertical_search_border
- scenario = 'sohu'
- gallery: special usage for Huawei Gallery
- input_video_path
- wb_square_size
- grid_params
- screen_scrollbar_width
- scenario = 'gallery'
- pattern: special usage based on pattern recognition:
- input_video_path
- input_pattern_path
- pattern_corr_threshold
- scenario = 'pattern'
## Restrictions
In specific cases of using the analyzer there are conditions and limitations of detection of white blocks on video from screen recordings:
| App name | Restrictions |
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Huawei Gallery | 1. Recording only in gallery (without app opening and list of albums).
2. Don't add gray/grayscale images in testing grid (recommend use standard-color test images like red/blue/etc. with definition borders).
3. Don't make only-background cases - tools can't define shift between frames and calculate as static frame without scroll.
4. Don't use image sort by date, album and etc. (don't noise grid with numbers or letters). |
| Huawei Themes | 1. Don't use only-whiteblocks cases.
2. Use dark app theme. |
| Huawei Music | Use light app theme |
| Huawei AppGallery | Analyzer doesn't detect non-gray whiteblocks (green, red and etc, ~3/4 on explore page). |
| Huawei Books | Analyzer doesn't detect non-gray whiteblocks (white, green, red, wbs without borders with layout). |