sample_gdc 使用说明
功能概述
sample_gdc 目录下是用于演示如何使用 GDC 的示例程序,主要功能介绍如下:
generate_custom_config.py: 生成 GDC 的矫正标定配置参数。generate_bin: 读取本地 json 配置文件,生成对应的gdc.bin文件。gdc_static_valid: 读取本地gdc.bin文件和原始 YUV 文件送入 GDC 做变化处理后保存为 YUV 文件。gdc_stress_test: 读取本地gdc.bin文件并将原始 YUV 文件循环送入 GDC 做 GDC 性能测试。gdc_equisolid: 读取本地 NV12 的 YUV 图,把图片送入 GDC 做(全景 panoramic)校正处理。gdc_transformation: 读取本地 的 json 配置文件,把图片送入 GDC 做180线性变换、圆柱形变换、等距变换和梯形校正+去畸变处理。
1-custom_config
功能概述
本示例旨在展示如何通过 custom 变换的方式,预先准备输入图像,并生成用于指导 GDC 矫正的标定参数文件。
代码位置及目录结构
-
代码位置
/app/multimedia_samples/sample_gdc/1-custom_config -
目录结构
sample_gdc/
├── 1-custom_config
│ ├── Makefile
│ ├── chessboard
│ ├── chessboard.png
│ ├── custom_config.txt
│ └── generate_custom_config.py
开发和使用流程
在 PC 上使用 generate_custom_config.py 程序生成 GDC 的矫正标定配置参数。
-
准备棋盘格图片(chessboard.png), 可以打印出来,或者用显示器预览。
-
使用目标 Camera Sensor 在不同角度下拍摄棋盘格图片,拍摄15张左右,建议多拍一些。
-
以上面的棋盘格图片作为输入,执行以下 python 程序(确保系统支持 Python 3,和安装了
opencv-python库),生成 GDC 的矫正标定参数文件(custom_config.txt):# Enter /app/multimedia_samples/sample_gdc/1-custom_config directory
python3 ./generate_custom_config.py注意注意事项:拍摄棋盘格的时候尽量距离远一点,棋盘格占画面较大时容易导致 python 程序识别失败
在字符终端运行时的日志:
No graphical environment detected. Skipping display of images.
Input images directory: ./chessboard
Test image file: ./chessboard/vlcsnap-2024-05-06-09h53m19s733.jpg
Output file: custom_config.txt
i: 0
i: 1
... 省略 ...
i: 15
Intrinsic matrix (mtx):
[[784.57179685 0. 939.01168998]
[ 0. 784.35388599 554.71639175]
[ 0. 0. 1. ]]
Distortion coefficients (dist):
[[-3.16520533e-01 1.02422375e-01 -2.60692201e-04 7.23624256e-04
-1.44726239e-02]]
Rotation vectors (rvecs):
(array([[-0.07424795],
[ 0.17820099],
[-0.04684888]]), array([[0.44453246],
[0.01540531],
[0.03596364]]), array([[-0.38217217],
[-0.4097845 ],
[ 0.16419408]]), array([[-0.0713388 ],
[-0.04356189],
[ 0.00918689]]), array([[ 0.40326625],
[-0.65705694],
[ 0.07152059]]), array([[-0.28933582],
[ 0.07433653],
[ 0.09031559]]), array([[-0.1353966 ],
[-0.61689018],
[-0.06274773]]), array([[ 0.02193021],
[-0.52159079],
[ 0.08910704]]), array([[-0.10002557],
[-0.25580186],
[-0.08683701]]), array([[-0.37827059],
[-0.98115358],
[ 0.175653 ]]), array([[0.33652166],
[0.12869965],
[0.03961734]]), array([[ 0.40214666],
[-0.38128926],
[-0.0051477 ]]), array([[-0.04168182],
[ 0.0922567 ],
[-0.03109347]]))
Translation vectors (tvecs):
(array([[ -71.275847 ],
[-106.35748096],
[ 224.27593215]]), array([[ 3.80981104],
[-81.7694762 ],
[183.44645072]]), array([[ -81.59651772],
[-122.67796656],
[ 240.51602851]]), array([[ -86.84292041],
[-114.12437351],
[ 203.11264832]]), array([[-51.05204629],
[-57.97011932],
[168.23228488]]), array([[ -25.79903668],
[-139.06100345],
[ 248.06228137]]), array([[-193.45812779],
[-116.55450795],
[ 135.39187735]]), array([[ -91.12813213],
[-111.74470892],
[ 150.61397733]]), array([[ -89.4296275 ],
[-117.79736921],
[ 196.30732053]]), array([[-156.41212161],
[-146.02467216],
[ 191.13039641]]), array([[ -60.65720996],
[-111.66378957],
[ 191.3402483 ]]), array([[-56.56159122],
[-72.97166982],
[149.97470497]]), array([[ -60.28586566],
[-111.66429463],
[ 196.1187917 ]]))
New camera matrix (newcameramtx):
[[784.57179685 0. 939.01168998]
[ 0. 784.35388599 554.71639175]
[ 0. 0. 1. ]]
Validation of distortion correction
Saving mapx and mapy to 'custom_config.txt'
No graphical environment detected. The output image has been saved to 'custom_config.txt'.如果在图形化桌面的终端运行,会显示执行过程中的标定和矫正效果:
generate_custom_config.py 的选项参数:
usage: generate_custom_config.py [-h] [-i INPUT_IMAGES_DIR] [-t TEST_IMAGE]
[-o OUTPUT_FILE]
Gdc calibration and image undistortion.
optional arguments:
-h, --help show this help message and exit
-i INPUT_IMAGES_DIR, --input_images_dir INPUT_IMAGES_DIR
Directory containing the chessboard images.
-t TEST_IMAGE, --test_image TEST_IMAGE
File path of the image to be undistorted.
-o OUTPUT_FILE, --output_file OUTPUT_FILE
File path for the output configuration.
2-generate_bin
功能概述
本程序通过读取本地 gdc_bin_custom_config.json 配置文件,生成对应的 gdc.bin 文件。
代码位置及目录结构
-
代码位置
/app/multimedia_samples/sample_gdc/2-generate_bin -
目录结构
sample_gdc/
├── 2-generate_bin
│ ├── Makefile
│ ├── gdc_bin_custom_config.json
│ └── generate_bin.c