在 OpenCV 中为 Android 添加两个 32FC4 类型的垫子
Adding Two Mat of type 32FC4 in OpenCV for Android
为了减少图像中的噪点,我尝试获取 10 张图像的平均值。
Mat imgMain = new Mat(n_height, n_width, CvType.CV_32FC4);
Mat imgFin = new Mat(n_height, n_width, CvType.CV_32FC4);
for(int i=1; i <= 10; i++) {
//Crop the image
image.recycle();
image = null;
image = BitmapFactory.decodeFile("/storage/sdcard0/DCIM/A" + String.valueOf(i) + ".jpg");
pimage = Bitmap.createBitmap(image, leftOff1, topOff1, n_width, n_height);
Utils.bitmapToMat(pimage, imgMain);
scaleAdd(imgMain, 0.1, imgFin, imgFin);
}
运行 应用程序,我收到以下消息:
Caused by: CvException [org.opencv.core.CvException: cv::Exception:
/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matmul.cpp:2079:
error: (-215) src1.type() == src2.type() in function void
cv::scaleAdd(cv::InputArray, double, cv::InputArray, cv::OutputArray)
]
at org.opencv.core.Core.scaleAdd_0(Native Method)
at org.opencv.core.Core.scaleAdd(Core.java:6690)
at MainActivity.imageAnalysis(MainActivity.java:123)
第 123 行是 scaleAdd(imgMaing, 0.1, imgFin, imgFin);
根据 reference,src1、src2 和 dst MAT 应具有相同的大小和类型。但是,当我将 imgFin 类型设置为 32FC4 时出现此错误,但当 imgFin 设置为 8UC4 时不会出现任何错误。有这种经历吗?我需要在 imgFin 中保留浮点数,这就是我不能使用 8UC4 的原因。
// this line will overwrite your imgMain,
// the type will be CV_8UC4, regardless, what you said before.
Utils.bitmapToMat(pimage, imgMain);
// so, convert to float:
imgMain.convertTo(imgMain, CvType.CV_32FC4);
// now add float images, to avoid precision loss:
scaleAdd(imgMain, 0.1, imgFin, imgFin);
为了减少图像中的噪点,我尝试获取 10 张图像的平均值。
Mat imgMain = new Mat(n_height, n_width, CvType.CV_32FC4);
Mat imgFin = new Mat(n_height, n_width, CvType.CV_32FC4);
for(int i=1; i <= 10; i++) {
//Crop the image
image.recycle();
image = null;
image = BitmapFactory.decodeFile("/storage/sdcard0/DCIM/A" + String.valueOf(i) + ".jpg");
pimage = Bitmap.createBitmap(image, leftOff1, topOff1, n_width, n_height);
Utils.bitmapToMat(pimage, imgMain);
scaleAdd(imgMain, 0.1, imgFin, imgFin);
}
运行 应用程序,我收到以下消息:
Caused by: CvException [org.opencv.core.CvException: cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matmul.cpp:2079: error: (-215) src1.type() == src2.type() in function void cv::scaleAdd(cv::InputArray, double, cv::InputArray, cv::OutputArray) ] at org.opencv.core.Core.scaleAdd_0(Native Method) at org.opencv.core.Core.scaleAdd(Core.java:6690) at MainActivity.imageAnalysis(MainActivity.java:123)
第 123 行是 scaleAdd(imgMaing, 0.1, imgFin, imgFin);
根据 reference,src1、src2 和 dst MAT 应具有相同的大小和类型。但是,当我将 imgFin 类型设置为 32FC4 时出现此错误,但当 imgFin 设置为 8UC4 时不会出现任何错误。有这种经历吗?我需要在 imgFin 中保留浮点数,这就是我不能使用 8UC4 的原因。
// this line will overwrite your imgMain,
// the type will be CV_8UC4, regardless, what you said before.
Utils.bitmapToMat(pimage, imgMain);
// so, convert to float:
imgMain.convertTo(imgMain, CvType.CV_32FC4);
// now add float images, to avoid precision loss:
scaleAdd(imgMain, 0.1, imgFin, imgFin);