Select ROI within Jupyter Notebook

prateek khandelwal
2 min readJul 14, 2019

--

Introduction

Jupyter Notebook is one of the best editor while working on remote servers. Especially for a data science its very fruitful as same platform can be use for model development, preprocessing , visualization etc. Along with that it also provide support for using multiple kernels, magics and other utilities.

In most of computer vision solution selecting Region of interest is an important step, as this could be region where alerts are generated(for Intrusion detection, zone monitoring, loitering detection), or this could be object which is monitored( for theft detection, object tracking etc.).

In case of Python, opencv is the famous library which provide which provide lot of utilities for computer vision application, including selection of ROI.

opencv bbox selection ( from Satya Mallick blog)

More details about opencv bbox selection can be found here

But opencv bbox selection become kind of impossible when using remote server, reason is network. Most of cloud services like aws, azure or gcp are quite remote, and x11 port forwarding is very slow, as such creating region of interest will be very slow. It would be great if the same can be done on Jupyter Notebook directly.

Implementation in Jupyter

Working in notebook

Region of interest can easily be developed using matplotlib library.
Matplotlib provides Event handling, Its an API for interacting with the figure via key presses and mouse movements. More details can be found here.

I used same along with some jupyter widgets to create mouse selection. One just need to load the image and call the bbox_select class once done, click on disconnect mpl and turnoff notebook.

Code

Embed from gist

--

--

prateek khandelwal

I am a Data Science Consultant and practitioner.I have worked in domain of Predictive Analytics, Statistical modelling, Deep learning.