Skip to content

Commit 6497c9d

Browse files
authored
Add files via upload
1 parent fbf3722 commit 6497c9d

6 files changed

Lines changed: 114 additions & 0 deletions

File tree

blog06-resize/blog06-image02.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#encoding:utf-8
2+
import cv2
3+
import numpy as np
4+
5+
#读取图片
6+
src = cv2.imread('scenery.png')
7+
rows, cols = src.shape[:2]
8+
print rows, cols
9+
10+
#图像缩放 dsize(列,行)
11+
result = cv2.resize(src, (int(cols*0.6), int(rows*1.2)))
12+
13+
#显示图像
14+
cv2.imshow("src", src)
15+
cv2.imshow("result", result)
16+
17+
#等待显示
18+
cv2.waitKey(0)
19+
cv2.destroyAllWindows()

blog06-resize/blog06-image03.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#encoding:utf-8
2+
import cv2
3+
import numpy as np
4+
5+
#读取图片
6+
src = cv2.imread('scenery.png')
7+
rows, cols = src.shape[:2]
8+
print rows, cols
9+
10+
#图像缩放
11+
result = cv2.resize(src, None, fx=0.3, fy=0.3)
12+
13+
#显示图像
14+
cv2.imshow("src", src)
15+
cv2.imshow("result", result)
16+
17+
#等待显示
18+
cv2.waitKey(0)
19+
cv2.destroyAllWindows()

blog06-resize/blog06-image04.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#encoding:utf-8
2+
import cv2
3+
import numpy as np
4+
5+
#读取图片
6+
src = cv2.imread('scenery.png')
7+
8+
#原图的高、宽 以及通道数
9+
rows, cols, channel = src.shape
10+
11+
#绕图像的中心旋转
12+
#参数:旋转中心 旋转度数 scale
13+
M = cv2.getRotationMatrix2D((cols/2, rows/2), 30, 1)
14+
#参数:原始图像 旋转参数 元素图像宽高
15+
rotated = cv2.warpAffine(src, M, (cols, rows))
16+
17+
#显示图像
18+
cv2.imshow("src", src)
19+
cv2.imshow("rotated", rotated)
20+
21+
#等待显示
22+
cv2.waitKey(0)
23+
cv2.destroyAllWindows()

blog06-resize/blog06-image05.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#encoding:utf-8
2+
import cv2
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
6+
#读取图片
7+
img = cv2.imread('scenery.png')
8+
src = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
9+
10+
#图像翻转
11+
#0以X轴为对称轴翻转 >0以Y轴为对称轴翻转 <0X轴Y轴翻转
12+
img1 = cv2.flip(src, 0)
13+
img2 = cv2.flip(src, 1)
14+
img3 = cv2.flip(src, -1)
15+
16+
#显示图形
17+
titles = ['Source', 'Image1', 'Image2', 'Image3']
18+
images = [src, img1, img2, img3]
19+
for i in xrange(4):
20+
plt.subplot(2,2,i+1), plt.imshow(images[i], 'gray')
21+
plt.title(titles[i])
22+
plt.xticks([]),plt.yticks([])
23+
plt.show()

blog06-resize/blog06-image06.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#encoding:utf-8
2+
import cv2
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
6+
#读取图片
7+
img = cv2.imread('scenery.png')
8+
image = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
9+
10+
#图像平移 下、上、右、左平移
11+
M = np.float32([[1, 0, 0], [0, 1, 100]])
12+
img1 = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
13+
14+
M = np.float32([[1, 0, 0], [0, 1, -100]])
15+
img2 = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
16+
17+
M = np.float32([[1, 0, 100], [0, 1, 0]])
18+
img3 = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
19+
20+
M = np.float32([[1, 0, -100], [0, 1, 0]])
21+
img4 = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
22+
23+
#显示图形
24+
titles = [ 'Image1', 'Image2', 'Image3', 'Image4']
25+
images = [img1, img2, img3, img4]
26+
for i in xrange(4):
27+
plt.subplot(2,2,i+1), plt.imshow(images[i], 'gray')
28+
plt.title(titles[i])
29+
plt.xticks([]),plt.yticks([])
30+
plt.show()

blog06-resize/scenery.png

393 KB
Loading

0 commit comments

Comments
 (0)