Giter Club home page Giter Club logo

polyroiselector's Introduction

This tool was made from my need for a better ROI selector, while also specifying the rotation of the object at the same time.

polyROISelector

A better ROI selector for OpenCV. Allows specifying a polygon for the ROI and returns metrics, in addition to calculating the rotation of the ROI based on a rotation guide.

Returns a list of dictionaries, where each of the list elements corresponds to a ROI. Access the list by accessing the ROIs class variable. Each ROI contains the following (The dictionary keys are as labelled here):

Polygon: A numpy array of points defining the ROI polygon. Can be directly used with opencv polygon functions without the need to convert.

Centroid: A tuple with the coordinate of the centroids of the polygon. 

Center: A tuple with the coordinate of the center of the bounding box of the polygon.

BoundingBox: The bounding box of the polygon.

ROIRotation: The rotation of the polygon. Only updated when the user explicitly sets the rotation by using the rotation guide enabled by the alternative right and left click. Default is upright, that is zero degrees for the model used.

Usage

Left click: If a ROI is open, that is, it is not enclosed, it adds another point, where the mouse clicked to the polygon.

Right click: If the ROI is open, then it closes the ROI polygon. This was done to make sure that the ROI is closed, since even a pixel of open ROI, while invisible to the human eye, might wreak havoc for algorithms like flood-fill and would need further prepocessing (Trust me, I faced it and this solves a bit of the headaches). Updates the ROI list automatically when the polygon is closed. If the ROI list is empty, then you probably didn't close the polygon. Try right clicking next time.

Alternative Right click: This is triggered only when the polygon is closed. This starts the orientation mode, recognizable by a line following the mouse from the centroid of the ROI. This mode is used to specify a guide from which the orientation of the ROI is to be calculated.

Alternative Left click: This is triggered only when the polygon is closed and the orientation mode has started. This finalizes the orientation to face in the direction where the user clicks. So you get a line from which the orientation of the ROI is estimated. The model assumes an upright, right handed, 360 degrees rotational frame.

Usage Scenario

Import the class and call it's constructor while passing in the image to be displayed. Alternatively you can also pass along the windowName, after you have already displayed the image, which allows you finer control over the selection by giving you access to query the ROI list at your leisure as well as reset the canvas with the same picture or with different picture.

TODO

The current code works with OpenCV3, since opencv changed the signature of functions between OpenCV3 and OpenCV2, but that is easily fixable and I will do it once I find a bit of time. (Although it would be nice if you just upgraded to OpenCV3 :) )

Features like allow the user to specify callbacks for more events and keyboard keys.

Port to C++ version of OpenCV too (Won't be as pretty, but would be a valuable insight)

Lastly

The code might not be pretty and I might be missing something or doing something wrong, but you are more than welcome to comment and point me to the right direction. Ideas, fixes and general prettying up are all welcome! :)

polyroiselector's People

Contributors

morpheus3000 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

apachesep

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.