-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcv.py
More file actions
34 lines (24 loc) · 856 Bytes
/
cv.py
File metadata and controls
34 lines (24 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!python3
# -*- coding:utf8 -*-
import cv2
import numpy as np
img = cv2.imread("01.jpg", cv2.IMREAD_COLOR)
img_org = img.copy()
print("img shape", img.shape, cv2.IMREAD_COLOR, cv2.COLOR_GRAY2BGR)
# 得到图片的高和宽
img_height, img_width = img.shape[:2]
# 定义对应的点
points1 = np.float32([[75, 55], [340, 55], [33, 435], [400, 433]])
points2 = np.float32([[0, 0], [360, 0], [0, 420], [360, 420]])
# 计算得到转换矩阵
M = cv2.getPerspectiveTransform(points1, points2)
# 实现透视变换转换
processed = cv2.warpPerspective(img, M, (360, 420))
# 读取灰度图片,转彩色
img_gray = cv2.imread("01.jpg", 0)
img_gray_rgb = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2BGR)
# 显示原图和处理后的图像
cv2.imshow("org", img_org)
cv2.imshow("processed", processed)
cv2.imshow("img_gray_rgb", img_gray_rgb)
cv2.waitKey(0)