Categories
Uncategorized

OpenCV Workflow in Jupyter Notebook

OpenCV is great for classical computer vision, and Jupyter Notebooks are great for prototyping. It would make sense to use them both, but the “cv2.imshow” cannot work inside a Jupyter Notebook, since it requires handling an event loop. Okay, you can always convert back the image to a RGB Numpy array and show it using Matplotlib or maybe Pillow. I prefer to avoid the additional lines of code and mental context switch using a small neat package called “cv2-plt-imshow”.

pip install cv2-plt-imshow

Then, reading and showing image in the Notebook is as it should be!

import cv2
from cv2_plt_imshow import cv2_plt_imshow
img = cv2.imread("10000.jpg")
cv2_plt_imshow(img)

The documentation is here: https://pypi.org/project/cv2-plt-imshow/

Leave a Reply

Your email address will not be published. Required fields are marked *