Last active
March 22, 2021 10:05
-
-
Save ivan-krukov/5215ae912da29e59c4091863588eccac to your computer and use it in GitHub Desktop.
Show opencv image in ipython notebook
This file contains 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 cv2 | |
import urllib.request | |
# Will use matplotlib for showing the image | |
from matplotlib import pyplot as plt | |
# Plot inline | |
%matplotlib inline | |
# For local images, read as usual | |
# img = cv2.imread("opencv-logo2.png") | |
# For remote, use urllib, as per "http://stackoverflow.com/questions/21061814" | |
req = urllib.request.urlopen("http://cloudcv.org/static/img/opencv.jpg") | |
arr = np.asarray(bytearray(req.read()), dtype=np.uint8) | |
img = cv2.imdecode(arr,-1) | |
# The important part - Correct BGR to RGB channel | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
# Plot | |
plt.imshow(img) |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
helps.
thank you!
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
missing "import numpy as np"