//读取图像像素,设置图像像素
int height = src.rows();
int width = src.cols();
int ch = src.channels();
for (int c = 0; c < ch; c++) {
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
if (ch == 3) {
double[] bgr = src.get(row, col);
bgr[0] = 255 - bgr[0];
bgr[1] = 255 - bgr[1];
bgr[2] = 255 - bgr[2];
src.put(row, col, bgr);
} else if(ch == 1) {
double gray = src.get(row, col)[0];
src.put(row, col, 255 - gray);
}
}
}
}
//图像加减乘除
Mat src1 = Mat.zeros(new Size(400, 400), CvType.CV_8UC3);
//绘制红色矩形
Imgproc.rectangle(src1, new Point(100, 100), new Point(200, 200), new Scalar(0, 0, 255), -1);
// create image two
Mat src2 = Mat.zeros(new Size(400, 400), CvType.CV_8UC3);
//绘制蓝色矩形
Imgproc.rectangle(src2, new Point(100, 100), new Point(250, 250), new Scalar(255, 0, 0), -1);
//加
Mat add_result = Mat.zeros(src1.size(), src1.type());
Core.add(src1, src2, add_result);
//减
Mat sub_result = Mat.zeros(src1.size(), src1.type());
Core.subtract(src1, src2, sub_result);
//乘
Mat mul_result = Mat.zeros(src1.size(), src1.type());
Core.multiply(src1, src2, mul_result);
//除
Mat div_result = Mat.zeros(src1.size(), src1.type());
Core.divide(src1, src2, div_result);
java opencv 基本操作2
最新推荐文章于 2024-07-08 23:03:25 发布