Restructured

This commit is contained in:
Afeedh Shaji 2021-03-16 01:32:01 +05:30
parent 420c2f8dcc
commit ae61544630
13 changed files with 99 additions and 63 deletions

View File

@ -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)

View File

View File

View File

@ -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,12 +19,11 @@ 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)
gh_blur = cv2.GaussianBlur(gh, (15, 15), 0)
gh_blur = cv2.convertScaleAbs(gh_blur,gh_blur)
gh_blur = cv2.convertScaleAbs(gh_blur, gh_blur)
gh_media = cv2.medianBlur(gh_blur, 5)
gh_media = cv2.medianBlur(gh_media, 5)
gh_media = cv2.medianBlur(gh_media, 3)
@ -56,11 +59,12 @@ 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
@ -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)):
@ -85,36 +89,31 @@ class FingerCode:
for i in range(len(sectors)):
temp = round(math.sqrt(Variance[i]), 0)
#print temp
# print temp
result.append(int(temp))
return result
def extract_fingercode(self, image):
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:
fingercodetemp = self.fingercode(i)
ADD.extend(fingercodetemp)
return ADD
def __init__(self,image):
self.result = self.extract_fingercode(image)

View File

@ -10,34 +10,36 @@ 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
gamma = 1.0
ksize = 33
lamba = 10
ps = (90-180)*np.pi/180.0
ps = (90 - 180) * np.pi / 180.0
for theta in np.arange(0, np.pi, np.pi / 8):
kernel = cv2.getGaborKernel((ksize, ksize), sigma, theta, lamba, gamma, ps)
#kern = kern/2 + 0.5
# kern = kern/2 + 0.5
filters.append(kernel)
return filters
# processing the img
def process(img, kernel):
#img = np.array(img, dtype=np.float32)
#img /= 255.
# img = np.array(img, dtype=np.float32)
# img /= 255.
dest = cv2.filter2D(img, -1, 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

View File

@ -1,5 +1,3 @@
# _*_ coding:utf-8 _*_
# description: the Sector Class
import math
@ -30,17 +28,17 @@ def cal_mean(points):
return total / num
# calculate the variance of the sector's points
def cal_variance(points, mean):
total = 0
for i in range(len(points)):
point = points[i]
total += math.pow(point.Gray - mean, 2)
return total / (len(points)-1)
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 = []
@ -59,12 +57,12 @@ def Divide_sector(img):
y = 1
sector = []
for x in range(cols):
#print x
# print x
for y in range(rows):
x0 = x - core_x
y0 = y - core_y
r = math.sqrt(pow(x0, 2) + pow(y0, 2))
#print r
# print r
if x0 == 0.0:
if y0 > 0:
point_angle = 270.0
@ -77,33 +75,45 @@ def Divide_sector(img):
else:
point_angle = 180.0
# in 1 district
if(y0 < 0.0)&(x0 > 0.0):
if (y0 < 0.0) & (x0 > 0.0):
point_angle = abs(math.degrees(math.atan(y0 / x0)))
# in 2 district
if(y0 < 0.0)&(x0 < 0.0):
if (y0 < 0.0) & (x0 < 0.0):
point_angle = abs(math.degrees(math.atan(x0 / y0))) + 90.0
# in 3 district
if(y0 > 0.0)&(x0 < 0.0):
if (y0 > 0.0) & (x0 < 0.0):
point_angle = abs(math.degrees(math.atan(y0 / x0))) + 180.0
# in 4 district
if (y0 > 0.0)&(x0 > 0.0):
if (y0 > 0.0) & (x0 > 0.0):
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):
# 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)
):
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)
# print len(sector)
sectors.append(sector)
return sectors
# normalize the image after divide into sectors
def Normalize_img(img, sectors):
def normalize_img(img, sectors):
M0 = 100
V0 = 100
Mean = []

24
fingercode/test.py Normal file
View File

@ -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)

View File

@ -1,2 +1,4 @@
phe==1.4.0
python-dotenv==0.15.0
python-dotenv==0.15.0
numpy
matplotlib

9
run.py
View File

@ -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)

View File

@ -22,4 +22,12 @@ def decode_regno(ascii_regno_undiv):
def sha256(plaintext):
return hashlib.sha256(plaintext.encode()).hexdigest()
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