Ask Your Question

floodFill missing in opencv.js

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

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


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];

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.imshow('canvasOutput', mask);
kpachinger gravatar imagekpachinger ( 2020-04-16 06:43:58 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

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

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


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 -0500 )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 -0500 )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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 286 times

Last updated: Jul 11 '18