Skip to content

TypeError: RotatedRect.points is not a function #46

@Npscholar

Description

@Npscholar

Working on implementing the camshift example listed in the 4.8.0-dev turtorial.

Can someone explain to me what I am doing wrong? Or what gap there is between this library and the opencv docs? I am using "@techstark/opencv-js": "^4.8.0-release.9"

Small excerpt from the example

        // start processing.
        cap.read(frame);
        cv.cvtColor(frame, hsv, cv.COLOR_RGBA2RGB);
        cv.cvtColor(hsv, hsv, cv.COLOR_RGB2HSV);
        cv.calcBackProject(hsvVec, [0], roiHist, dst, [0, 180], 1);

        // apply camshift to get the new location
        [trackBox, trackWindow] = cv.CamShift(dst, trackWindow, termCrit);

        // Draw it on image
        let pts = cv.rotatedRectPoints(trackBox);
        cv.line(frame, pts[0], pts[1], [255, 0, 0, 255], 3);
        cv.line(frame, pts[1], pts[2], [255, 0, 0, 255], 3);
        cv.line(frame, pts[2], pts[3], [255, 0, 0, 255], 3);
        cv.line(frame, pts[3], pts[0], [255, 0, 0, 255], 3);
        cv.imshow('canvasOutput', frame);

However, there are several modifications I have to make.

  1. cv.Camshift() returns a RotatedRect which cannot be destructured into [trackBox, trackWindow] as the example suggests
  2. cv.rotatedRectPoints() causes Property 'rotatedRectPoints' does not exist on type 'typeof import("<omitted>node_modules/@techstark/opencv-js/dist/src/index")' so in response I try to use RotatedRect.points which is a valid property in the module/ opencv docs but receive the error titled in this issue. TypeError: newLocationForRect.points is not a function

My code experiencing the issue

        // start processing.
        cap.read(frame);
        cv.cvtColor(frame, hsv, cv.COLOR_RGBA2RGB);
        cv.cvtColor(hsv, hsv, cv.COLOR_RGB2HSV);
        cv.calcBackProject(hsvVec, [0], roiHist, dst, [0, 180], 1);        
        
        // apply camshift to get the new location
        // actually returns an array of rectangle and points
        const newLocationForRect = cv.CamShift(dst, trackWindow, termCrit);
        console.log("trackBox", newLocationForRect);
       
        // Draw it on image
        let pts: any = [];
        // pass a point array to put the 4 vertices in types are bad so using as any
        const returnPts = newLocationForRect.points(pts as any); 
        console.log("after", returnPts);
       
        cv.line(frame, pts[0], pts[1], [255, 0, 0, 255], 3);
        cv.line(frame, pts[1], pts[2], [255, 0, 0, 255], 3);
        cv.line(frame, pts[2], pts[3], [255, 0, 0, 255], 3);
        cv.line(frame, pts[3], pts[0], [255, 0, 0, 255], 3);
        cv.imshow("canvasOutput", frame);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions