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
35
36
37
| # -*- coding: utf-8 -*-
|
| #命令
| __author__ = '上海色宁'
|
| import sys
| import cv2
| import matplotlib.pyplot as plt
| import numpy as np
|
| import cv2
| if __name__ == "__main__":
| img = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2GRAY);
| # 二值化
| cv2.imshow('gray',img)
| ret, binary = cv2.threshold(img,0,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)
| print("threshold value: %s"%ret)
| cv2.imshow("binary",binary)
| cv2.waitKey(0)
|
|
| t,dst1 = cv2.threshold(img,110,255,cv2.THRESH_BINARY)
| cv2.imshow('threshold127',dst1)
| HSV = cv2.cvtColor(dst1, cv2.COLOR_BGR2HSV)
| H, S, V = cv2.split(HSV)
| LowerBlue = np.array([20, 20, 20])
| UpperBlue = np.array([30, 255, 255])
| mask = cv2.inRange(HSV, LowerBlue, UpperBlue)
| BlueThings = cv2.bitwise_and(dst1, dst1, mask=mask)
| cv2.imshow('BlueThings',BlueThings)
|
| # 显示图像
| #cv2.imshow("origin image", img)
| #cv2.imshow("THRESH_BINARY", dst1)
|
| if cv2.waitKey(10000) == 27:
| cv2.destroyAllWindows()
|
|