-
Notifications
You must be signed in to change notification settings - Fork 5
/
finger.py
65 lines (52 loc) · 1.32 KB
/
finger.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# coding: utf-8
from __future__ import print_function
import cv2
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import os
def identity(filename):
"""
:param filename:
:return:
"""
is_figure = False
img = cv2.imread(filename)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if not (abs(int(img[i, j, 2]) - int(img[i, j, 1])) > 20 and img[i, j, 2] > 235 and (
int(img[i, j, 0]) - int(img[i, j, 1])) > 0):
# if (img[i, j, 2] - img[i, j, 1]) < 70:
img[i, j, :] = [255, 255, 255]
# elif img[i, j, 1] < 210:
# img[i, j, :] = [255, 255, 255]
cv2.imshow("image", img)
cv2.waitKey()
# 灰度化
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 二值化
img = cv2.adaptiveThreshold(img_gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 5)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if img[i][j] != 255:
# print(img[i][j])
is_figure = True
return is_figure
def test_identity(image_dir):
"""
测试
"""
filenames = os.listdir(image_dir)
try:
for i in filenames:
print(i, ": ", identity(os.path.join(testDir, i)))
except Exception as e:
print("not open")
raise
def main(argv=None):
filename = ""
identity(filename)
if __name__ == "__main__":
test_dir = ""
test_identity(test_dir)
# print(identity(filename))