标签:learnopencv Jupyter 16 cv2 im IMREAD earth bit 图片
本系列主要参考github 记录是督促自己学习 运行在 Jupyter 上
github https://github.com/spmallick/learnopencv.git
原始的 cv.imshow 在Jupyter上不能显示图片 这里采用 matplotlib 曲线绘图
首先创建 pltcvshow.py 文件
import cv2
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
import matplotlib.animation as animation
def cv_show(img, name="plt_cv_show", type="nogray", animate=False): # 利用plt显示图片
# cv2.imshow(name,img)
plt.figure(figsize=(10,10))
plt.title(name)
if type == 'gray' :
img = plt.imshow(img, cmap='gray', animated=animate)
return img
else :
img2 = img[:, :, ::-1]
img = plt.imshow(img2, animated=animate)
return img
在文件 imread_examples.ipynb 调用处使用
import cv2
import sys
sys.path.append("..")
import pltcvshow
# Read 8-bit grayscale image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_GRAYSCALE)
print ("flags : cv2.IMREAD_GRAYSCALE")
print ("Size %s, type %s\n" % (im.shape,im.dtype))
pltcvshow.cv_show(im, "earth-16-bit-per-channel", "gray")
# Read 8-bit color image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_COLOR)
print ("flags : cv2.IMREAD_COLOR")
print ("Size %s, type %s\n" % (im.shape,im.dtype))
pltcvshow.cv_show(im, "earth-16-bit-per-channel")
# Read 16-bit color image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH )
print ("flags : cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH")
print ("Size %s, type %s\n" % (im.shape,im.dtype))
pltcvshow.cv_show(im, "earth-16-bit-per-channel")
# Read transparent PNG / TIFF image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_UNCHANGED)
print ("flags : cv2.IMREAD_UNCHANGED")
print ("Size %s, type %s\n" % (im.shape,im.dtype))
pltcvshow.cv_show(im, "earth-16-bit-per-channel")
目录结构如下图:
运行结果 各位自己运行了看结果吧 ^-^
标签:learnopencv,Jupyter,16,cv2,im,IMREAD,earth,bit,图片 来源: https://blog.csdn.net/shopping988/article/details/115081762
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。