I want to make a cartoon effect. But the bilateralFilter is not working. It only works when I open the cvtColor part in the code below. But this time it's gray in color. I want to make it colorful. How can I do it?
const newImagePath = RNFS.DocumentDirectoryPath + '/girl_wide_brim_hat.png';
const interMat = await new Mat().init();
const interMat2 = await new Mat().init();
const interMat3 = await new Mat().init();
const sourceFile = await downloadAssetSource(sourceuri);
const srcMat = await RNCv.imageToMat(sourceFile);
const srcMat2 = await RNCv.imageToMat(sourceFile);
RNCv.invokeMethod('cvtColor', {
p1: srcMat,
p2: interMat,
p3: ColorConv.COLOR_BGR2GRAY,
});
RNCv.invokeMethod('medianBlur', {
p1: interMat,
p2: interMat,
p3: 5,
});
RNCv.invokeMethod('adaptiveThreshold', {
p1: interMat,
p2: interMat,
p3: 255,
p4: Imgproc.ADAPTIVE_THRESH_MEAN_C,
p5: Imgproc.THRESH_BINARY,
p6: 9,
p7: 5,
});
// RNCv.invokeMethod('cvtColor', {
// p1: srcMat2,
// p2: interMat2,
// p3: ColorConv.COLOR_BGR2GRAY,
// });
RNCv.invokeMethod('bilateralFilter', {
p1: srcMat2,
p2: interMat2,
p3: 9,
p4: 200,
p5: 200,
});
RNCv.invokeMethod('bitwise_and', {
p1: interMat,
p2: interMat2,
p3: interMat3,
// p4: srcMat2,
});
const {uri, width, height} = await RNCv.matToImage(interMat3, newImagePath);
this.setState({...this.state, destImageUri: uri});