opencv_python图像金字塔
程序员文章站
2022-03-25 20:45:01
...
最近在看opencv_python,顺便做一下笔记,因为总是“拿来主义”不太好,要有点原创。图像金字塔原理不赘述了,网上太多了,直接上代码,做此笔记的主要目的一是备忘,二是看到好多图像金字塔在一张图上显示,感觉很酷,自己就搞了一下与大家分享。
import cv2
import numpy as np
img = cv2.imread('D:/SoftwareLearning/python practice/images/roi.jpg',0)
lower_reso1 = cv2.pyrDown(img)
lower_reso2 = cv2.pyrDown(lower_reso1)
lower_reso3 = cv2.pyrDown(lower_reso2)
rows,colums = img.shape
row1s,colum1s = lower_reso1.shape
row2s,colum2s = lower_reso2.shape
row3s,colum3s = lower_reso3.shape
tmp = np.zeros((rows//2,colums),dtype=np.uint8)
tmp[:,0:colum1s] = tmp[:,0:colum1s] + lower_reso1
tmp[row2s:row1s,colum1s:colum1s+colum2s] = tmp[row2s:row1s,colum1s:colum1s+colum2s] + lower_reso2
tmp[row2s+row3s:row1s,colums-colum2s:colums-colum3s] = tmp[row2s+row3s:row1s,\
colums-colum2s:colums-colum3s] + lower_reso3
merge = np.vstack((img,tmp))
cv2.imshow('Merge',merge)
cv2.waitKey(0)
此处应该有图
有效果图怎么可以没有原图呢,自己想玩的时候可以换成其他图玩^-^
哦,貌似忘了一件事情,上面第18行的那个“\”是因为单行太长的,在python里换行用的。
觉得灰度图不好看,可以上彩图。
import cv2
import numpy as np
img = cv2.imread('D:/SoftwareLearning/python practice/images/roi.jpg',1)
lower_reso1 = cv2.pyrDown(img)
lower_reso2 = cv2.pyrDown(lower_reso1)
lower_reso3 = cv2.pyrDown(lower_reso2)
rows,colums,channels = img.shape
row1s,colum1s,channel1s = lower_reso1.shape
row2s,colum2s,channel2s = lower_reso2.shape
row3s,colum3s,channel3s = lower_reso3.shape
#
tmp = np.zeros((rows//2,colums,3),dtype=np.uint8)
tmp[:,0:colum1s,:] = tmp[:,0:colum1s,:] + lower_reso1
tmp[row2s:row1s,colum1s:colum1s+colum2s,:] = tmp[row2s:row1s,colum1s:colum1s+colum2s,:] + lower_reso2
tmp[row2s+row3s:row1s,colums-colum2s:colums-colum3s,:] = tmp[row2s+row3s:row1s,\
colums-colum2s:colums-colum3s,:] + lower_reso3
#
merge = np.vstack((img,tmp))
cv2.imshow('Merge',merge)
cv2.waitKey(0)
上一篇: 变量&常量
下一篇: NoSQL会取代SQL数据库吗?