ROI Picker is a simple tool to visualize region-of-interests (ROIs) and edit them. It is common for many computer vision tasks to define or select ROIs on an image. ROI picker can provide simple GUI to add, modify, and remove ROIs without complex packages or libraries. ROI Picker is written with Python and OpenCV, and it works with a single Python file, roi_picker.py
.
ROI Picker now supports the following ROI shapes. Of course, users can extend more through class inheritance or modification.
- A set of points
- A set of line segments
- A polygon
The above shapes are all represented as [(x1, y1), (x2, y2), ..., (xn, yn)]
.
- Prerequisite
- If you don't install OpenCV, please install OpenCV:
pip install opencv-python
.
- If you don't install OpenCV, please install OpenCV:
- Command-line usage
python roi_picker.py image_file [-r roi_file.json] [-c config_file.json]
-r
(or--roi_file
): Specify a ROI file which contains ROI data (default:image_file.json
)-c
(or--config_file
): Specify a configuration file which can change visualization and GUI interface (default:roi_picker.json
)- 📝 Note) If a default file does not exist, ROI Picker just starts with empty ROI or with its initial configuration.
- Demo examples
python roi_picker.py demo/miraehall_satellite.png
- Start ROI Picker with the default ROI file (
demo/miraehall_satellite.json
) and default configuration file (roi_picker.json
)
- Start ROI Picker with the default ROI file (
python roi_picker.py demo/miraehall_220722.png -r demo/miraehall_camera.json
- Start ROI Picker with the specific ROI file (
demo/miraehall_image.json
)
- Start ROI Picker with the specific ROI file (
python roi_picker.py demo/miraehall_satellite.png -c demo/bold_style.json
- Start ROI Picker with its default ROI file with specific configuration file (
demo/bold_style.json
) - 📝 Note) You can customize visualization and keyboard shortcuts by changing a configuration file. Please refer
ROIPicker::get_default_config()
inroi_picker.py
file.
- Start ROI Picker with its default ROI file with specific configuration file (
- Extension examples
📝 Note) ROI Picker provides minimal GUI without any menu or button for simplicity. Its GUI inputs are totally based on mouse and keyboard.
-
Mouse actions
- Click: Select a ROI
- If you click at an existing point, the ROI which contains the point is selected.
- Double Click: Add or delete a point
- If you double click at an existing point, the point will be removed.
- If you double click on an existing line (for line segment or polygon), a new point will be inserted on the line.
- If you double click on an image, a new point will be added.
Ctrl
+Drag: Move the clicked point
- Click: Select a ROI
-
Keyboard shortcuts
ESC
: Terminate ROI PickerTab
: Select the next ROICtrl
+P
: Add a new set of pointsCtrl
+L
: Add a new set of line segmentCtrl
+G
: Add a new polygonCtrl
+R
: Renew ROI Picker (Clear all ROIs)Ctrl
+D
: Delete the selected ROICtrl
+M
: Import ROI data from the ROI fileCtrl
+E
: Export ROI data to the ROI fileCtrl
+F
: Export configuration to a JSON fileCtrl
+Z
: Show and hide the image zoomCtrl
+T
: Show and hide the status of the selected ROI+
: Zoom up the image-
: Zoom down the image
You can see the following demo if you run the above three usage examples, respectively.
📝 Note) Please remember that you can customize visualization and keyboard shortcuts when you apply your own configuration file (e.g. demo/bold_style.json
). The following example is same data only with a different configuration file.