opencv.jsの作法 その10
概要
opencv.jsの作法を調べてみた。
間違い探し、やってみた。
参考にしたページ
写真
サンプルコード
var cvs0 = document.getElementById('canvasInput0');
var cvs1 = document.getElementById('canvasInput1');
var ctx0 = cvs0.getContext('2d');
var ctx1 = cvs1.getContext('2d');
var img1 = new Image();
img1.src = data1;
img1.onload = function() {
ctx1.drawImage(img1, 0, 0);
}
var img0 = new Image();
img0.src = data0;
img0.onload = function() {
ctx0.drawImage(img0, 0, 0);
var src0 = cv.imread('canvasInput0');
var src1 = cv.imread('canvasInput1');
var dst = new cv.Mat();
var imgDiff = new cv.Mat();
var i;
var j = 12;
for (i = 0; i < src0.rows * src0.cols * 3 - j; i += 3)
{
src0.data[i] = src0.data[i + j];
}
var kernel = cv.matFromArray(3, 3, cv.CV_32FC1, [0.1111, 0.1111, 0.1111, 0.1111, 0.1112, 0.1111, 0.1111, 0.1111, 0.1111]);
var anchor = new cv.Point(-1, -1);
cv.filter2D(src0, src0, cv.CV_8U, kernel, anchor, 0, cv.BORDER_DEFAULT);
cv.filter2D(src1, src1, cv.CV_8U, kernel, anchor, 0, cv.BORDER_DEFAULT);
cv.absdiff(src0, src1, imgDiff);
cv.bitwise_not(imgDiff, dst);
cv.imshow('canvasOutput', dst);
src0.delete();
src1.delete();
dst.delete();
}
成果物
var cvs0 = document.getElementById('canvasInput0');
var cvs1 = document.getElementById('canvasInput1');
var ctx0 = cvs0.getContext('2d');
var ctx1 = cvs1.getContext('2d');
var img1 = new Image();
img1.src = data1;
img1.onload = function() {
ctx1.drawImage(img1, 0, 0);
}
var img0 = new Image();
img0.src = data0;
img0.onload = function() {
ctx0.drawImage(img0, 0, 0);
var src0 = cv.imread('canvasInput0');
var src1 = cv.imread('canvasInput1');
var dst = new cv.Mat();
var imgDiff = new cv.Mat();
var i;
var j = 12;
for (i = 0; i < src0.rows * src0.cols * 3 - j; i += 3)
{
src0.data[i] = src0.data[i + j];
}
var kernel = cv.matFromArray(3, 3, cv.CV_32FC1, [0.1111, 0.1111, 0.1111, 0.1111, 0.1112, 0.1111, 0.1111, 0.1111, 0.1111]);
var anchor = new cv.Point(-1, -1);
cv.filter2D(src0, src0, cv.CV_8U, kernel, anchor, 0, cv.BORDER_DEFAULT);
cv.filter2D(src1, src1, cv.CV_8U, kernel, anchor, 0, cv.BORDER_DEFAULT);
cv.absdiff(src0, src1, imgDiff);
cv.bitwise_not(imgDiff, dst);
cv.imshow('canvasOutput', dst);
src0.delete();
src1.delete();
dst.delete();
}
以上。
Author And Source
この問題について(opencv.jsの作法 その10), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/5b8af5400f965f058fc5著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .