First time here? Check out the FAQ!

Ask Your Question
0

floodFill missing in opencv.js

asked Jul 11 '18

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.

Preview: (hide)

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 (Apr 16 '0)edit

1 answer

Sort by » oldest newest most voted
0

answered Jul 11 '18

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 *

Preview: (hide)

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 (Jul 11 '18)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 (Jul 11 '18)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 (May 9 '19)edit

Question Tools

1 follower

Stats

Asked: Jul 11 '18

Seen: 1,443 times

Last updated: Jul 11 '18