Ask Your Question
0

Getting new cv.Point2fVector() is not a constructor error in opencvjs

asked 2019-09-17 13:15:59 -0600

vasanthahr gravatar image

Hello,

With help of opencv.js, I am tying to use below code in my front-end application but getting error as "new cv.Point2fVector() is not a constructor"

Please guide me how to get use of these below functions or types

var obj_corners = new cv.Point2fVector();
        obj_corners[0] = new cv.Point(0,0);
        obj_corners[1] = new cv.Point(img1Raw.cols,0);
        obj_corners[2] = new cv.Point(img1Raw.cols, img1Raw.rows);
        obj_corners[3] = new cv.Point(0, img1Raw.rows);
edit retag flag offensive close merge delete

Comments

Well most of the time I've got that issue it was due to improper opencv.js loading and initialization settings, please share you're whole code or at least include the parts where you load your opencv.js file and indicate if you're using the wasm or asm ones

Hellcho gravatar imageHellcho ( 2019-09-18 17:46:22 -0600 )edit

First of all, to create a new point you can simply use an object, like this

const newPoint = { x: 0, y:0 }

I don't think you need new cv.Point2fVector().Instead of using new cv.Point2fVector() need to use its equivalent in JS which might be an array I guess. So try this

var obj_corners = [];
    obj_corners[0] = {x:0, y: 0};
    obj_corners[1] = {x: img1Raw.cols, y: 0};
    obj_corners[2] = {x: img1Raw.cols, y: img1Raw.rows};
    obj_corners[3] = {x:0, y:img1Raw.rows};

If you tell me how you are going to use your obj_corners I might know the solution. For example, if you wanna create a rectangle you can use this

const rect = {x : x, y : y, width : width, height : height};
Lucy8 gravatar imageLucy8 ( 2019-09-23 09:53:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-09-27 22:31:22 -0600

vasanthahr gravatar image

Thanks Lucy8 and Hellcho. Lucy8 logic worked for me.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-09-17 13:14:50 -0600

Seen: 760 times

Last updated: Sep 17 '19