I am getting an image from the mobile phone device camera and want to use OpenCV to apply color filters to the images. (Software/System is a Flutter App that uses Foreign Function Interface (FFI) to interact with the OpenCV Library in C++)
I followed below question and tried to implement the solution, but so far I get only totally white images.
- StackOverflow: OpenCV help me with Sepia kernel
I ended up with the following code trying to achieve it:
transform function (not working)
void filter_1(char* inputImagePath, char* outputImagePath) {
Mat input = imread(inputImagePath);
Mat output = input.clone();
Mat filter = (Mat_<float>(4,4) << 0.272, 0.534, 0.131, 0.0,
0.349, 0.686, 0.168, 0.0,
0.393, 0.769, 0.189, 0.0,
0.0, 0.0, 0.0, 1.0);
transform(output, input, filter);
imwrite(outputImagePath, input);
}
filter with 0~255 values instead of 0.0~1.0 (also not working)
Mat filter = (Mat_<int>(4,4) <<69, 136, 33, 0,
88, 174, 42, 0,
99, 196, 48, 0,
0, 0, 0, 255);
So my question would be how to apply the filter and save the result successfully for further use? The sample filter here should result in a Sepia effect on the image.
UPDATE (2021.07.21)
- Removed filter2d function and related text to avoid confusion.
- Removed link to filter2d related question in SO
- (Just for notice: StackOverflow: OpenCV apply my own filter to a color image )
- Added sample for 0~255 values matrix