简体   繁体   中英

OpenCv4Android: frame masking by an image

I want to mask each frame that I get from the camera and mask it by an image in Drawable folder. That is, I wan to find my region of interest in a MAT. How can I do that?

An image's (say mRgba as a landscape image from the camera) ROI is dictated by its dimensions, so:

Rect roi = new Rect(0,0,mRgba.width(), mRgba.height());

if you want to mask a particular part of the image then I'd suggest using submat, so if mRgba was the image from the camera you can set a ROI and then resize your drawable into that area. For example, to draw an image into the top left corner of your original image in a 100x100 square.

Rect subROI = new Rect(0,0,100,100);
Mat subimg = mRgba.submat(subROI);
Mat yourDrawable = ....
Imgproc.resize(yourDrawable, submig, submig.size());

As submig is a reference to the subROI the pixels in the top left area of mRgba will be updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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