Created
August 14, 2020 04:01
-
-
Save Kinjalrk2k/a1339e0eb089af7e7fb88fe5dc719f66 to your computer and use it in GitHub Desktop.
Display OpenCV Image(s) in Jupyter Notebook using Matplotlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import cv2 | |
import matplotlib.pyplot as plt | |
def displayImage(img, title=None, size=(10, 10)): | |
plt.figure(figsize=size) | |
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) | |
plt.title(title) | |
plt.axis('off') | |
plt.show() | |
def displayImages(imgs, titles=None, size=(15, 15)): | |
num = len(imgs) | |
subplotnum = math.floor(math.sqrt(num)) + 1 | |
plt.figure(figsize=size) | |
for idx, img in enumerate(imgs): | |
ax = plt.subplot(subplotnum, subplotnum, idx+1) | |
im = ax.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) | |
if titles is not None: | |
plt.title(titles[idx]) | |
plt.axis('off') | |
plt.tight_layout() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment