android - 在使用OpenCV的Android中,如何调整图像亮度?

  显示原文与译文双语对照的内容
0 0

我创建了一个在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);

我尝试添加代码 [Update],但它错误


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);

[ERROR]


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)

请看我在这里尝试做的例子。

时间: 原作者:

0 0

检查图像增加/降低亮度的例子

请看这个


 int brightness;
 SeekBar seekBarBrightness=(SeekBar)findViewById(R.id.seekBar1);
 seekBarBrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

 @Override
 public void onStopTrackingTouch(SeekBar arg0) {


 }

 @Override
 public void onStartTrackingTouch(SeekBar arg0) {


 }

 @Override
 public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {

 Bitmap newBitMap = doBrightness(bitMap,progress);

 imageView.setImageBitmap(newBitMap);

 }
 });




 public static Bitmap doBrightness(Bitmap src, int value)
 {
//image size
 int width = src.getWidth();
 int height = src.getHeight();
//create output bitmap
 Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
//color information
 int A, R, G, B;
 int pixel;

//scan through all pixels
 for (int x = 0; x <width; ++x)
 {
 for (int y = 0; y <height; ++y)
 {
//get pixel color
 pixel = src.getPixel(x, y);
 A = Color.alpha(pixel);
 R = Color.red(pixel);
 G = Color.green(pixel);
 B = Color.blue(pixel);

//increase/decrease each channel
 R += value;
 if (R> 255)
 {
 R = 255;
 } else if (R <0)
 {
 R = 0;
 }

 G += value;
 if (G> 255)
 {
 G = 255;
 } else if (G <0)
 {
 G = 0;
 }

 B += value;
 if (B> 255)
 {
 B = 255;
 } else if (B <0)
 {
 B = 0;
 }

//apply new pixel color to output bitmap
 bmOut.setPixel(x, y, Color.argb(A, R, G, B));
 }
 }

//return final image
 return bmOut;
 }

原作者:
...