Skip to content

Commit f508750

Browse files
authored
Add files via upload
1 parent ce9c50b commit f508750

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
import cv2
3+
import numpy as np
4+
from matplotlib import pyplot as plt
5+
import matplotlib
6+
7+
#读取图像
8+
img = cv2.imread('judge.png')
9+
10+
#灰度转换
11+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12+
13+
#转换为二值图像
14+
edges = cv2.Canny(gray, 50, 200)
15+
16+
#显示原始图像
17+
plt.subplot(121), plt.imshow(edges, 'gray'), plt.title(u'(a)原始图像')
18+
plt.axis('off')
19+
20+
#霍夫变换检测直线
21+
minLineLength = 60
22+
maxLineGap = 10
23+
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 30, minLineLength, maxLineGap)
24+
25+
#绘制直线
26+
lines1 = lines[:, 0, :]
27+
for x1,y1,x2,y2 in lines1[:]:
28+
cv2.line(img, (x1,y1), (x2,y2), (255,0,0), 2)
29+
30+
res = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
31+
32+
#设置字体
33+
matplotlib.rcParams['font.sans-serif']=['SimHei']
34+
35+
#显示处理图像
36+
plt.subplot(122), plt.imshow(res), plt.title(u'(b)结果图像')
37+
plt.axis('off')
38+
plt.show()

0 commit comments

Comments
 (0)