my-lord
my-lord

Reputation: 2923

How to create a mask in OpenCV.js?

I can create a mask in OPENCV C++ using cv::Mat::zeros and Rect.But i cannot find these features on OPENCV.js.How can i create a mask on OPENCV.js?

cv::Mat mask = cv::Mat::zeros(8, 8, CV_8U); // all 0
mask(Rect(2,2,4,4)) = 1;

Upvotes: 3

Views: 4038

Answers (1)

GPPK
GPPK

Reputation: 6666

let src = cv.imread('canvasInput');
let dst = new cv.Mat();
// You can try more different parameters
let rect = new cv.Rect(100, 100, 200, 200);
dst = src.roi(rect);
cv.imshow('canvasOutput', dst);
src.delete();
dst.delete();

Taken from here, specifically the Image ROI section

Upvotes: 4

Related Questions