1.【环境】
reactnative 0.62.0
react-native-opencv3 基础上做了修改,使用了4.3.0-contrib
com.quickbirdstudios:opencv:4.3.0-contrib
不要直接安装react-native-opencv3,因为只是在其基础上进行修改。从git上下载下代码
2.【遇到的相关问题】
1) 修改react-native-opencv3中的build.gradle,引用opencv4.3.0修改如下:
dependencies {
implementation 'com.quickbirdstudios:opencv:4.3.0-contrib'
implementation 'com.facebook.react:react-native:+'
}
2)针对react-native-opencv3中的各种bug的修复
a). react-native-opencv3中保存图像的错误修复
新增如下方法:
@ReactMethod
public void imwrite(String outPath, ReadableMap srcMat, final Promise promise) {
int matIndex = srcMat.getInt("matIndex");
Mat mat = (Mat) MatManager.getInstance().matAtIndex(matIndex);
FileUtils.getInstance().imwrite(outPath, mat, promise);
}
public static void imwrite(final String outpath, final Mat dst, final Promise promise) {
try {
if (outpath == null || outpath.length() == 0) {
// TODO: if no path sent in then auto-generate??!!!?
rejectInvalidParam(promise, outpath);
return;
}
Imgcodecs.imwrite(outpath, dst);
WritableNativeMap result = new WritableNativeMap();
result.putInt("width", new Double(dst.size().width).intValue());
result.p