0

我正在尝试在nodejs.

我设法在车牌周围画出轮廓,但现在我想掩盖它。

这就是我现在得到的(只是没有文字):

图片

我想像这样掩盖它(甚至在之后裁剪它):

图片

这是我现在的代码:

import cv from 'opencv4nodejs';

// read image, grayscale
const img = cv.imread('./images/img2.jpg');
const grayImg = img.bgrToGray();

const bfilter = grayImg.bilateralFilter(11, 17, 17);
const edged = bfilter.canny(30, 200);

const getContour = (handMask) => {
    const mode = cv.RETR_TREE;
    const method = cv.CHAIN_APPROX_SIMPLE;
    const contours = handMask.findContours(mode, method);

    return contours
        .sort((c0, c1) => c1.area - c0.area)
        .slice(0, 10)
        .find((contour) => {
            const x = contour.approxPolyDP(10, true);
            return x.length === 4;
        });
};
let edgeContour = getContour(edged);

let mask = new cv.Mat(grayImg.rows, grayImg.cols, 0, 0);

let x = img.drawContours([edgeContour.getPoints()], 0, new cv.Vec3(0, 255, 0), {
    thickness: 5,
});

x = img.bitwiseAnd(img);
cv.imshow('drawContours', x);

cv.waitKey();

4

0 回答 0