java - OpenCV改变矩形中的RGB参数

标签 java android opencv rgb

我有4分。例如...

A(1;1)
B(2;5)
C(4;4)
D(3;2)

如何更改此矩形中的 RGB 参数(对于所有像素)?

像这样:

double[] data = mat.get(x, y);
data[0] = data[0]+30;
data[1] = data[1]+20;
data[2] = data[2]+10;
mat.put(x, y, data);

最佳答案

尝试类似的方法来实现 Dan Mašek 中描述的方法评论:

...
Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.<your_image>);
Mat sourceMat = new Mat(sourceBitmap.getWidth(), sourceBitmap.getHeight(), CvType.CV_8UC3);
Utils.bitmapToMat(sourceBitmap, sourceMat);

Mat maskMat = new Mat(sourceBitmap.getWidth(), sourceBitmap.getHeight(), CvType.CV_8UC4);
Mat resultMat = new Mat(sourceBitmap.getWidth(), sourceBitmap.getHeight(), CvType.CV_8UC4);

// create color, which added to sourceMat region (+100 - for red channel)
Scalar color = new Scalar(100, 0, 0, 255);

// or you can try Scalar color = new Scalar(10, 20, 30);  as in your question

Point[] region = new Point[4];

// your coords multiplied by 50 for visualization convenience
region[0] = new Point(50, 50);
region[1] = new Point(100, 250);
region[2] = new Point(200, 200);
region[3] = new Point(150, 100);

List<MatOfPoint> contours = new ArrayList();
MatOfPoint regionMat = new MatOfPoint(region);
contours.add(regionMat);

// create mask    
Imgproc.drawContours(maskMat, contours, 0, color, -1);

// apply mask to source
Core.add(maskMat, sourceMat, resultMat);

// just for visualisation
Bitmap bitmap = Bitmap.createBitmap(sourceMat.cols(), sourceMat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(resultMat, bitmap);

<your_ImageView>.setImageBitmap(bitmap);
...
注意!这只是屏蔽的示例,并未优化。

关于java - OpenCV改变矩形中的RGB参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46099478/

相关文章:

java - 如何解决我的 try-catch 异常处理?

java - 从 karaf 4 pax-jetty 中删除 JSESSIONID httponly 漏洞

android - 在android中通过它的 "tag"找到一个按钮

c++ - Makefile 不适用于 mac os x Mavericks

java - Spark Sql,无法查询数组中的多个可能值

java - minify-maven-plugin cssFinalFile 在哪里?

安卓工作室 : Unable to start the daemon process

java - Android 应用程序无法运行、崩溃

Python OpenCV 添加的文本质量不佳

object - 如何使用 OpenCV BackgroundSubtractorMOG2 获取移动物体的掩码