1
我创建了一个在Android中调整亮度的示例图像。我使用位图来调整亮度,但运行需要很长时间。相反,我想使用OpenCV在Android中设置图像亮度。如何使用OpenCV调整Android中的图像亮度?
这是我的示例代码,但它只是改变图像的颜色:
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.a001);
int width = bmp.getWidth();
int height = bmp.getHeight();
Mat mRgba = new Mat(width, height, CvType.CV_8UC1);
Utils.bitmapToMat(bmp, mRgba);
Mat mRay = new Mat();
Imgproc.cvtColor(mRgba, mRay, Imgproc.COLOR_BGRA2RGB, 4);
Utils.matToBitmap(mRay, bmp);
mImageview_01.setImageBitmap(bmp);
[更新] 我尝试添加代码,但它错误
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.a001);
int width = bmp.getWidth();
int height = bmp.getHeight();
Mat mRgba = new Mat(width, height, CvType.CV_8UC1);
Utils.bitmapToMat(bmp, mRgba);
Mat mRay = new Mat();
Imgproc.cvtColor(mRgba, mRay, Imgproc.COLOR_BGRA2RGB, 4);
/*
* Use Adaptive Thresholding on the grayscaled Mats crop -> threshed Mat
* src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType,
* int blockSize, double C
*/
Imgproc.adaptiveThreshold(threshed, threshed, 255,
Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV, 15, 8);
Utils.matToBitmap(mRay, bmp);
mImageview_01.setImageBitmap(bmp);
[错误]
CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/thresh.cpp:796: error: (-215) src.type() == CV_8UC1 in function void cv::adaptiveThreshold(cv::InputArray, cv::OutputArray, double, int, int, int, double)
请查看我想要做的事情的例子here。
Imgproc.cvtColor(mRgba,mRay,Imgproc.CV_MEDIAN,4); //这很可能是错误的。你应该在这里提供Imgproc.COLOR_ *值,纯粹的机会Imgproc.CV_MEDIAN是3,它被解释为COLOR_BGRA2RGB。不是你想要的,对吧? – berak
好的,这是我的错误,但这不是我的问题。我想设置亮度,我不需要改变颜色。请查看链接示例。 –