在 Flutter 方面,我使用 4x5 矩阵将滤色器应用于图像(用于预览)。然后通过 FFI,我使用 OpenCV 应用过滤器并对图像进行变换并保存新的图像结果。
但是,结果总是与预览不同。
所以我想知道,如何使用 OpenCV 使用相同的矩阵(4x5)实现相同的结果?
Flutter - ColorFiltered Widget 的 ColorFilter Matrix (RGBA):
const ColorFilter _FILTER_2 = ColorFilter.matrix(<double>[
0.9, 0.11, 0.11, 0.0, 0.0, //
0.11, 0.7, 0.44, 0.0, 0.0, //
0.22, 0.22, 0.9, 0.0, 0.0, //
0.0, 0.0, 0.0, 1.0, 0.0
]);
C++ - 矩阵变换函数(BGRA):
__attribute__((visibility("default"))) __attribute__((used)) void filter_2(char *inputImagePath, char *outputImagePath)
{
Mat input = imread(inputImagePath);
Mat output = input.clone();
Mat filter = (Mat_<float>(4, 4) <<
0.22, 0.22, 0.9, 0.0,
0.11, 0.7, 0.44, 0.0,
0.9, 0.11, 0.11, 0.0,
0.0, 0.0, 0.0, 1.0);
transform(output, input, filter);
imwrite(outputImagePath, input);
}
