Restructured
This commit is contained in:
parent
420c2f8dcc
commit
ae61544630
|
@ -1,12 +0,0 @@
|
|||
from FingerCode_final import *
|
||||
from fingercode import *
|
||||
|
||||
imaage = "2/106_5.tif"
|
||||
imaage2 = "2/101_1.tif"
|
||||
|
||||
i1 = FingerCode(imaage).result
|
||||
i2 = FingerCode(imaage2).result
|
||||
|
||||
if i1 and i2:
|
||||
res = cal_euler_distance(i1, i2)
|
||||
print(res)
|
|
@ -2,12 +2,16 @@ import cv2
|
|||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import math
|
||||
from Sector import *
|
||||
from Gabor import *
|
||||
|
||||
from .sector import cal_mean, divide_sector, normalize_img
|
||||
from .gabor import get_gabor
|
||||
|
||||
|
||||
class FingerCode:
|
||||
def Get_central_point(self, img):
|
||||
def __init__(self, image):
|
||||
self.result = self.extract_fingercode(image)
|
||||
|
||||
def get_central_point(self, img):
|
||||
img1 = img.copy()
|
||||
img = cv2.GaussianBlur(img, (3, 3), 0)
|
||||
img = cv2.blur(img, (5, 5))
|
||||
|
@ -15,7 +19,6 @@ class FingerCode:
|
|||
|
||||
sobelx1 = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3)
|
||||
|
||||
|
||||
A = sobelx.copy()
|
||||
B = sobelx1 + A
|
||||
gh = cv2.Sobel(B, cv2.CV_16S, 1, 1, ksize=3)
|
||||
|
@ -56,12 +59,13 @@ class FingerCode:
|
|||
|
||||
return col, row
|
||||
|
||||
def Get_core_img(self, img, core_x, core_y):
|
||||
def get_core_img(self, img, core_x, core_y):
|
||||
radius = 75
|
||||
core_img = img[core_y-radius:core_y+radius, core_x-radius:core_x+radius]
|
||||
core_img = img[
|
||||
core_y - radius : core_y + radius, core_x - radius : core_x + radius
|
||||
]
|
||||
return core_img
|
||||
|
||||
|
||||
def cal_standar(self, points, mean):
|
||||
total = 0
|
||||
for i in range(len(points)):
|
||||
|
@ -73,7 +77,7 @@ class FingerCode:
|
|||
return 0
|
||||
|
||||
def fingercode(self, img):
|
||||
sectors = Divide_sector(img)
|
||||
sectors = divide_sector(img)
|
||||
result = []
|
||||
Mean = []
|
||||
for i in range(len(sectors)):
|
||||
|
@ -93,20 +97,19 @@ class FingerCode:
|
|||
img = cv2.imread(image)
|
||||
rows, cols = img.shape[:2]
|
||||
# get the reference point
|
||||
core_x, core_y = self.Get_central_point(img)
|
||||
core_x, core_y = self.get_central_point(img)
|
||||
|
||||
if core_x != 0:
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
core_img = self.Get_core_img(img, core_x, core_y)
|
||||
|
||||
core_img = self.get_core_img(img, core_x, core_y)
|
||||
|
||||
# divide the img sector
|
||||
sectors = Divide_sector(core_img)
|
||||
sectors = divide_sector(core_img)
|
||||
|
||||
core_img = Normalize_img(core_img, sectors)
|
||||
core_img = normalize_img(core_img, sectors)
|
||||
|
||||
result = getGabor(core_img) # 8
|
||||
result = get_gabor(core_img) # 8
|
||||
|
||||
ADD = []
|
||||
for i in result:
|
||||
|
@ -114,7 +117,3 @@ class FingerCode:
|
|||
ADD.extend(fingercodetemp)
|
||||
|
||||
return ADD
|
||||
|
||||
|
||||
def __init__(self,image):
|
||||
self.result = self.extract_fingercode(image)
|
|
@ -10,6 +10,8 @@ import numpy as np
|
|||
# so from the Gabor source code sigma_y = sigma_x / gamma
|
||||
# the gamma should be 1.0
|
||||
# lamba = 0.1
|
||||
|
||||
|
||||
def build_filters():
|
||||
filters = []
|
||||
sigma = 4
|
||||
|
@ -32,12 +34,12 @@ def process(img, kernel):
|
|||
return dest
|
||||
|
||||
|
||||
# get the image's result after the Gabor filtering - returns 8 filters most likely based on rotatiom
|
||||
def getGabor(img):
|
||||
# get the image's result after the Gabor filtering - returns 8 filters most likely
|
||||
# based on rotatiom
|
||||
def get_gabor(img):
|
||||
filters = build_filters()
|
||||
res = []
|
||||
for i in filters:
|
||||
res1 = process(img, i)
|
||||
res.append(res1)
|
||||
return res
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
# _*_ coding:utf-8 _*_
|
||||
|
||||
# description: the Sector Class
|
||||
|
||||
import math
|
||||
|
@ -30,7 +28,6 @@ def cal_mean(points):
|
|||
return total / num
|
||||
|
||||
|
||||
|
||||
# calculate the variance of the sector's points
|
||||
def cal_variance(points, mean):
|
||||
total = 0
|
||||
|
@ -39,8 +36,9 @@ def cal_variance(points, mean):
|
|||
total += math.pow(point.Gray - mean, 2)
|
||||
return total / (len(points) - 1)
|
||||
|
||||
|
||||
# divide the core image into 80 sectors - returns 80
|
||||
def Divide_sector(img):
|
||||
def divide_sector(img):
|
||||
k = 16
|
||||
b = 10
|
||||
T = []
|
||||
|
@ -90,10 +88,22 @@ def Divide_sector(img):
|
|||
point_angle = abs(math.degrees(math.atan(x0 / y0))) + 270.0
|
||||
# point_angle = math.degrees(math.atan((y - core_y) / (x - core_x)))
|
||||
# print point_angle, r
|
||||
if (point_angle <= 337.5)&(b * (T[i] + 1) <= r)&(b * (T[i] + 2) > r)&(angle[i] <= point_angle)&(angle[i+1] > point_angle):
|
||||
if (
|
||||
(point_angle <= 337.5)
|
||||
& (b * (T[i] + 1) <= r)
|
||||
& (b * (T[i] + 2) > r)
|
||||
& (angle[i] <= point_angle)
|
||||
& (angle[i + 1] > point_angle)
|
||||
):
|
||||
point = Point(y, x, img[y][x])
|
||||
sector.append(point)
|
||||
if (point_angle > 337.5)&(b * (T[i] + 1) <= r)&(b * (T[i] + 2) > r)&(angle[i] <= point_angle)&(360.0 > point_angle):
|
||||
if (
|
||||
(point_angle > 337.5)
|
||||
& (b * (T[i] + 1) <= r)
|
||||
& (b * (T[i] + 2) > r)
|
||||
& (angle[i] <= point_angle)
|
||||
& (360.0 > point_angle)
|
||||
):
|
||||
point = Point(y, x, img[y][x])
|
||||
sector.append(point)
|
||||
# print len(sector)
|
||||
|
@ -103,7 +113,7 @@ def Divide_sector(img):
|
|||
|
||||
|
||||
# normalize the image after divide into sectors
|
||||
def Normalize_img(img, sectors):
|
||||
def normalize_img(img, sectors):
|
||||
M0 = 100
|
||||
V0 = 100
|
||||
Mean = []
|
|
@ -0,0 +1,24 @@
|
|||
from .fingercode import FingerCode
|
||||
import math
|
||||
|
||||
imaage = "/mnt/D/Linux/Works/secure-fp-auth/dataset/106_5.tif"
|
||||
imaage2 = "/mnt/D/Linux/Works/secure-fp-auth/dataset/106_6.tif"
|
||||
|
||||
i1 = FingerCode(imaage).result
|
||||
i2 = FingerCode(imaage2).result
|
||||
|
||||
|
||||
print(i1, i2)
|
||||
|
||||
|
||||
def cal_euler_distance(result1, result2):
|
||||
distance = 0
|
||||
for i in range(len(result1)):
|
||||
distance += math.pow(result1[i] - result2[i], 2)
|
||||
|
||||
return distance
|
||||
|
||||
|
||||
if i1 and i2:
|
||||
res = cal_euler_distance(i1, i2)
|
||||
print(res)
|
|
@ -1,2 +1,4 @@
|
|||
phe==1.4.0
|
||||
python-dotenv==0.15.0
|
||||
numpy
|
||||
matplotlib
|
9
run.py
9
run.py
|
@ -15,6 +15,8 @@ random_fp = "wct4rywzkxdpca1ktds46i8izwgneauujtqk9o2jhlz101pcbr5935vgnw1hfuby84h
|
|||
print(random_fp, len(random_fp))
|
||||
random_fp_ascii = [ord(ele) for ele in random_fp]
|
||||
|
||||
print(random_fp_ascii)
|
||||
|
||||
print(random_fp)
|
||||
random_regno = "B170003CS"
|
||||
|
||||
|
@ -56,7 +58,7 @@ def enroll():
|
|||
print(resp)
|
||||
|
||||
|
||||
def validate():
|
||||
def validate(new_fp):
|
||||
data = {"encr_regno": sha256(random_regno)}
|
||||
|
||||
s = requests.Session()
|
||||
|
@ -79,7 +81,7 @@ def validate():
|
|||
# print(encr_fp_orig)
|
||||
# print(encr_fp_sqr)
|
||||
|
||||
print(paillier.get_alt_euclidean_dist(encr_fp_orig, encr_fp_sqr, random_fp_ascii))
|
||||
print(paillier.get_alt_euclidean_dist(encr_fp_orig, encr_fp_sqr, new_fp))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -93,4 +95,5 @@ if __name__ == "__main__":
|
|||
print("Paillier working!")
|
||||
|
||||
# enroll()
|
||||
# validate()
|
||||
random_fp_ascii[0] = 247
|
||||
validate(random_fp_ascii)
|
||||
|
|
|
@ -23,3 +23,11 @@ def decode_regno(ascii_regno_undiv):
|
|||
|
||||
def sha256(plaintext):
|
||||
return hashlib.sha256(plaintext.encode()).hexdigest()
|
||||
|
||||
|
||||
def cal_euler_distance(result1, result2):
|
||||
distance = 0
|
||||
for i in range(len(result1)):
|
||||
distance += math.pow(result1[i] - result2[i], 2)
|
||||
|
||||
return distance
|
Loading…
Reference in New Issue