# sample_osd 使用说明
## 功能概述
sample_osd 完成 VSE 模块的初始化，配置输入和输出通道的参数，通过配置操作区域 Region，并将 Region 在图像上进行叠加操作 , 实现 OSD 填色、绘制线条、绘制文字和马赛克功能。
### 软件架构说明

![image-20241225-160821](./_static/_images/sample_osd/image-20241225-160821.png)

### 代码位置及目录结构

- 代码位置 `app/samples/platform_samples/sample_osd`
- 目录结构
```
sample_osd/
├── Makefile
└── sample_osd.c
```
### API 流程说明

![image-20250728-163105](./_static/_images/sample_osd/image-20250728-163105.png)


## 编译部署

### 编译

- 进入 sample_osd 目录，执行 `make` 编译
- 输出成果物是 sample_osd 源码目录下的 `sample_osd`
- 详细程序编译方式请查阅 [ 编译方法 ](overview.html#span-id-sample-build) 章节

### 程序部署

刷写系统软件镜像后 , 本 sample 的可执行文件位于板端 : /app/platform_samples/sample_osd。

需要使用的配置文件位于板端 : /app/platform_samples/sample_codec。

## 运行

### 程序运行方法

直接执行程序 `./sample_osd` 可以获得帮助信息：

### 程序参数选项说明

```bash
./sample_osd
Usage: sample_osd [OPTIONS]
Options:
-i, --input_file FILE           Specify the input file
-w, --input_width WIDTH         Specify the input width
-h, --input_height HEIGHT       Specify the input height
-m, --work_mode                 1.cover_test 2.draw_word_test 3.draw_line_test 4.mosaic_test
-f, --feedback                  Specify feedback mode
```

**选项：**

- `-i, --input_file FILE`：指定输入文件，仅支持 NV12 格式的图像

- `-w, --input_width WIDTH` ：指定输入宽度

- `-h, --input_height HEIGHT`：指定输入高度

- `-m, --work_mode`：指定工作模式 (1 ：填色测试  2 ：绘制文字测试 3 ：绘制线条测试 )

  - `-m 1`： OSD 填色功能测试

  - `-m 2`： OSD 写字功能测试

  - `	-m 3`： OSD 画线功能测试

  - `	-m 4`： OSD 马赛克功能测试

- `-f, --feedback`：使用 feedback 的方式去创建数据流

### 运行效果

## 运行效果说明

### 填色功能

在一张 NV12 格式的 YUV 图像上的指定区域填充指定颜色的色块。

执行命令：

```bash
./sample_osd -i 1280x720_NV12.yuv  -w 1280 -h 720 -m 1
```

日志输出：

```bash
Using input file:1280x720_NV12.yuv, input:1280x720
(read_yuvv_nv12_file):file read(1280x720_NV12.yuv), y-size(921600)
ichn input width = 1280
ichn input input_height = 720
hbn_vnode_set_ochn_attr: 0, 1280x720
hbn_vnode_set_ochn_attr: 1, 1280x720
hbn_vnode_set_ochn_attr: 2, 1280x720
hbn_vnode_set_ochn_attr: 3, 1280x720
hbn_vnode_set_ochn_attr: 4, 672x672
hbn_vnode_set_ochn_attr: 5, 2560x1440
... ( 省略 ) ...
Dump image to file(./vse_output_nv12_chn0_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn1_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn2_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn3_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn4_672x672_stride_672.yuv), size(451584) + size1(225792) succeeded
Dump image to file(./vse_output_nv12_chn5_2560x1440_stride_2560.yuv), size(11796480) + size1(5898240) succeeded
```

分别对 VSE 的 6 个通道执行色块填色功能，执行后，输出 6 张处理后的 NV12 格式的 YUV 图像，效果如下图所示：

![image-20240624221729659](./_static/_images/sample_osd/image-20240624221729659.png)

### 绘制文字

在一张 NV12 格式的 YUV 图像上的指定区域绘制文字。

执行命令：

```bash
./sample_osd -i 1280x720_NV12.yuv  -w 1280 -h 720 -m 2
```

日志输出：

```bash
Using input file:1280x720_NV12.yuv, input:1280x720
(read_yuvv_nv12_file):file read(1280x720_NV12.yuv), y-size(921600)
ichn input width = 1280
ichn input input_height = 720
hbn_vnode_set_ochn_attr: 0, 1280x720
hbn_vnode_set_ochn_attr: 1, 1280x720
hbn_vnode_set_ochn_attr: 2, 1280x720
hbn_vnode_set_ochn_attr: 3, 1280x720
hbn_vnode_set_ochn_attr: 4, 672x672
hbn_vnode_set_ochn_attr: 5, 2560x1440
... ( 省略 ) ...
Dump image to file(./vse_output_nv12_chn0_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn1_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn2_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn3_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn4_672x672_stride_672.yuv), size(451584) + size1(225792) succeeded
Dump image to file(./vse_output_nv12_chn5_2560x1440_stride_2560.yuv), size(11796480) + size1(5898240) succeeded
```

分别对 VSE 的 6 个通道的图像上添加当前系统的日期和时间，执行后，输出 6 张处理后的 NV12 格式的 YUV 图像，效果如下图所示：

![image-20240624221519048](./_static/_images/sample_osd/image-20240624221519048.png)

### 绘制线条

在一张 NV12 格式的 YUV 图像上的指定区域绘制线条。

执行命令：

```bash
./sample_osd -i 1280x720_NV12.yuv  -w 1280 -h 720 -m 3
```

日志输出：

```bash
Using input file:1280x720_NV12.yuv, input:1280x720
(read_yuvv_nv12_file):file read(1280x720_NV12.yuv), y-size(921600)
ichn input width = 1280
ichn input input_height = 720
hbn_vnode_set_ochn_attr: 0, 1280x720
hbn_vnode_set_ochn_attr: 1, 1280x720
hbn_vnode_set_ochn_attr: 2, 1280x720
hbn_vnode_set_ochn_attr: 3, 1280x720
hbn_vnode_set_ochn_attr: 4, 672x672
hbn_vnode_set_ochn_attr: 5, 2560x1440
... ( 省略 ) ...
Dump image to file(./vse_output_nv12_chn0_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn1_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn2_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn3_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn4_672x672_stride_672.yuv), size(451584) + size1(225792) succeeded
Dump image to file(./vse_output_nv12_chn5_2560x1440_stride_2560.yuv), size(11796480) + size1(5898240) succeeded
```

分别对 VSE 的 6 个通道的图像上绘制 4 条线条， 4 条线连接成一个多边形，执行后，输出 6 张处理后的 NV12 格式的 YUV 图像，效果如下图所示：

![image-20240624221619939](./_static/_images/sample_osd/image-20240624221619939.png)

### 绘制马赛克

在一张 NV12 格式的 YUV 图像上的指定区域设置马赛克。

执行命令：

```bash
./sample_osd -i 1280x720_NV12.yuv  -w 1280 -h 720 -m 4
```

日志输出：

```bash
VSE vnode work mode: vflow
Using input file:1280x720_NV12.yuv, input:1280x720
(read_yuvv_nv12_file):file read(1280x720_NV12.yuv), y-size(921600)
ichn input width = 1280
ichn input input_height = 720
hbn_vnode_set_ochn_attr: 0, 1280x720
hbn_vnode_set_ochn_attr: 1, 1280x720
hbn_vnode_set_ochn_attr: 2, 1280x720
hbn_vnode_set_ochn_attr: 3, 1280x720
hbn_vnode_set_ochn_attr: 4, 672x672
hbn_vnode_set_ochn_attr: 5, 2560x1440
... ( 省略 ) ...
Dump image to file(./vse_output_nv12_chn0_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn1_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn2_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn3_1280x720_stride_1280.yuv), size(921600) + size1(460800) succeeded
Dump image to file(./vse_output_nv12_chn4_672x672_stride_672.yuv), size(451584) + size1(225792) succeeded
Dump image to file(./vse_output_nv12_chn5_2560x1440_stride_2560.yuv), size(3686400) + size1(1843200) succeeded
```

分别对 VSE 的 6 个通道的图像上绘制 400 * 200 的长方向马赛克区域，执行后，输出 6 张处理后的 NV12 格式的 YUV 图像，效果如下图所示：

![image-20250728-162049](./_static/_images/sample_osd/image-20250728-162049.png)
