cvat-ai / cvat

Annotate better with CVAT, the industry-leading data engine for machine learning. Used and trusted by teams at any scale, for data of any scale.
https://cvat.ai
MIT License
11.9k stars 2.9k forks source link

Using the filter to find counterclockwise directions #4033

Open mat48 opened 2 years ago

mat48 commented 2 years ago

My actions before raising this issue

Thanks for providing these tools for free. hope you succeed in your career :) I've been trying to validate some polygons in my dataset but I'm having a hard time finding polygons with wrong direction (which in our perspective are CounterClockWise directions). Is there a method to find them with the "Filter" tool? I've used possible keywords to see if I can find it by trying different things but couldn't figure it out.

If Filter can't perform direction searches , do you think It's possible to find the directions in dumped annotation files? I'm not a developer so things are a little hard to explain. thanks for the time you're putting in to answer me.

Server version: 1.3 Core version: 3.10.0 Canvas version: 2.3.1 UI version: 1.14.2

bsekachev commented 2 years ago

Hi, thank you for the feedback.

Is there a method to find them with the "Filter" tool?

There is not way to find "clockwise", "anticlockwise" polygons with filter, but I think it could be a nice feature to implement. Would be great if our community helped us with the implementation.

Dumped files also don't contain polygons direction. You can try this code snipped (works only for shapes, not for tracks) below to find orientation of all polygons.

Just open CVAT app, open Chrome dev tools (Console tab), paste the code, change JOB_ID to relevant job id, press enter and wait some time.

(() => {
    function windingNumber(points) {
        var vertices = points.reduce((acc, val, idx) => (idx % 2 ? acc[acc.length - 1].y = val : acc.push({x: val}), acc), [])
        var area = 0;

        for (var i = 0; i < (vertices.length); i++) {
            j = (i + 1) % vertices.length;

            area += vertices[i].x * vertices[j].y;
            area -= vertices[j].x * vertices[i].y;
        }

        return area;
    }

    const JOB_ID = 1;
    fetch(`/api/v1/jobs/${JOB_ID}/annotations`).then((data) => data.json()).then((annotations) => {
    const { shapes } = annotations;
    for (const shape of shapes) {
        if  (shape.type === 'polygon') {
            const area = windingNumber(shape.points);
            if (area < 0) console.log(`Is anticlockwise, frame: ${shape.frame}, serverID: ${shape.id}`);
            else if (area > 0) console.log(`Is clockwise, frame: ${shape.frame}, serverID: ${shape.id}`);
            else console.log(`Collinear, frame: ${shape.frame}, serverID: ${shape.id}`)
        }
    }
 })
})();

It shows me for example following result:

image

I believe you can modify the script output to console to satisfy your needs.

mat48 commented 2 years ago

Thanks that helped a lot. I'll try to modify it and If I got the code for tracks I'll post it here.

bsekachev commented 2 years ago

For tracks you need to iterate additionally each keyframe:

track.shapes.forEach((shape) => { // compute windingNumber, check it and show message. frame = shape.frame, serverID = track.id })
mat48 commented 2 years ago

it really helps us a lot, thank you so much for your time!

Shaburu commented 3 months ago

[GSOC] Hey Could i be assigned this issue? @nmanovic

nmanovic commented 3 months ago

@Shaburu , I will do that. It is a great issue to start. Have you installed the development env? Could you please follow my instructions in the public GSoC group and share with me a screenshot of debugging session in VS code?

Shaburu commented 3 months ago

Yes the Dev Env is installed and have sent the Screenshot of the CVAT Server debugger as well

Apologies for the delay, my exams ended today