JavaScript 写法类似于 C++ 写法。
相关内容详细介绍请移步官网:【https://docs.opencv.org/3.3.1/dd/d4d/tutorial_js_image_arithmetics.html】
两图相加
let src1 = cv.imread("canvasInput1");
let src2 = cv.imread("canvasInput2");
let dst = new cv.Mat();
let mask = new cv.Mat();
let dtype = -1;
cv.add(src1, src2, dst, mask, dtype);
src1.delete();
src2.delete();
dst.delete();
mask.delete();
两图相减
let src1 = cv.imread("canvasInput1");
let src2 = cv.imread("canvasInput2");
let dst = new cv.Mat();
let mask = new cv.Mat();
let dtype = -1;
cv.subtract(src1, src2, dst, mask, dtype);
src1.delete(); src2.delete(); dst.delete(); mask.delete();
与、或、非、异或操作
let src1 = cv.imread("canvasInput1");
let src2 = cv.imread("canvasInput2");
let gray1=new cv.Mat();
let gray2=new cv.Mat();
cv.cvtColor(src1, gray1, cv.COLOR_RGBA2GRAY, 0);
cv.threshold(gray1, gray1, 100, 255, cv.THRESH_BINARY);
cv.cvtColor(src2, gray2, cv.COLOR_RGBA2GRAY, 0);
cv.threshold(gray2, gray2, 100, 255, cv.THRESH_BINARY);
<!-- 取反操作 -->
cv.bitwise_not(gray2, gray2);
<!-- 与操作 -->
let dst=new cv.Mat();
let mask=new cv.Mat();
cv.bitwise_and(gray1, gray2, dst, mask);
//cv.bitwise_or(gray1, gray2, dst, mask);
//cv.bitwise_not(gray1, gray2, dst, mask);
//cv.bitwise_xor(gray1, gray2, dst, mask);