简体   繁体   English

如何使用 opencv.js 屏蔽图像的一部分

[英]how to mask part of an image using opencv.js

What seems to be a simple step in OpenCV in python turns out a hurdle in opencv.js.在 python 中,OpenCV 中看似简单的一步在 opencv.js 中却是一个障碍。 I am trying to mask a section on image with white color, reference image below.我正在尝试用白色掩盖图像上的一部分,参考下面的图像。 In Python it is super simple.在 Python 中,它非常简单。 在此处输入图像描述

below is the line of code in python:以下是python中的代码行:

image = cv.imread('imagefile')
x = 180
y = 180
w = 70
h = 35
image[(y+h):y, x:(x+w)] = [255, 255, 255]

Here image[(y+h):y, x:(x+w)] = [255, 255, 255] is doing the trick of masking the part of the image with white color这里image[(y+h):y, x:(x+w)] = [255, 255, 255]正在做用白色掩盖图像部分的技巧

Could someone help me how to achieve this in opencv.js有人可以帮助我如何在 opencv.js 中实现这一点
below is code in java script.下面是java脚本中的代码。

let img = cv.imread('imagefile')
let x = 180
let y = 180
let w = 70
let h = 35
let image_width = 511
let image_height = 511
---
what should be the code here to achieve the desired result

You can used cv.rectangle to draw the filled white rectangle to achieve this result:您可以使用 cv.rectangle 绘制填充的白色矩形以实现此结果:

let mat = cv.imread(imgElement);
let point1 = new cv.Point(240, 240);
let point2 = new cv.Point(360, 290);
cv.rectangle(mat, point1, point2, [255, 255, 255, 255], -1);
cv.imshow('canvasOutput', mat);
mat.delete();

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM