Ask Your Question
0

floodFill missing in opencv.js

asked 2018-07-11 01:16:03 -0600

lgryan gravatar image

I've been trying to utilize opencv in a web-based application, and I need to use the floodFill function. However, it seems this isn't included as part of opencv.js. Does anyone know why this is the case, and how I might fix this issue?

I understand that the js bindings were developed as a separate project, but the evidence I can find seems to suggest that the imgproc library is fully supported... seems odd that this one function is missing.

edit retag flag offensive close merge delete

Comments

It would seem that the latest version includes and supports this.

let src = cv.imread('canvasInput');
let size = src.size();
let pt = new cv.Point(size.width/2,size.height/2);
let range = [64,64,64,0];

cv.cvtColor(src,src,cv.COLOR_RGBA2RGB);
let mask = new cv.Mat.zeros(size.height+2, size.width+2, cv.CV_8U);
cv.floodFill(src, mask, pt, new cv.Scalar(), new cv.Rect(), range, range, (8 + (255 << 16) + cv.FLOODFILL_MASK_ONLY));
cv.threshold(mask,mask,0,255,cv.THRESH_BINARY);

cv.imshow('canvasOutput', mask);
src.delete();mask.delete();
kpachinger gravatar imagekpachinger ( 2020-04-16 06:43:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-11 01:35:45 -0600

berak gravatar image

it was put onto the blacklist (along with some other functions) , most probably, because the c++ signature contains a raw pointer Rect *

edit flag offensive delete link more

Comments

Thanks for the quick reply! Apologies as I am a pretty novice c++ and javascript user, but would it be possible for me to remove the Rect * pointer from the function? I see that its an optional return parameter, and I don't actually need it for my application. Or would I just be better off finding a floodfill implementation written in javascript?

lgryan gravatar imagelgryan ( 2018-07-11 10:41:55 -0600 )edit

are you able to BUILD opencv.js, locally ? (then sure, the src code can be hacked) you'd add:

// special overload for js:
CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
                            Point seedPoint, Scalar newVal) {
    return floodFill(image, mask, seePoint, newVal, 0);
}

to the c++ header , remove the blacklist entry in the generator script, and add it to the whitelist there.

berak gravatar imageberak ( 2018-07-11 10:45:30 -0600 )edit

Did you try this yourself? I attempted the modifications you suggested and compilation fails due to "error: call to 'floodFill' is ambiguous"

Makogan gravatar imageMakogan ( 2019-05-09 11:23:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-11 01:16:03 -0600

Seen: 1,339 times

Last updated: Jul 11 '18