Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenHuang2020 committed Aug 11, 2020
1 parent 39b3b16 commit 4a73859
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
6 changes: 4 additions & 2 deletions commonModule/ImageBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def writeImg(img,filePath):
cv2.imwrite(filePath,img)

def infoImg(img,str='image:'):
return(str,'shape:',img.shape,'size:',img.size,'dims=',img.ndim,'dtype:',img.dtype)
return print(str,'shape:',img.shape,'size:',img.size,'dims=',img.ndim,'dtype:',img.dtype)

def grayImg(img):
return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Expand Down Expand Up @@ -56,6 +56,8 @@ def plotImg(img):
def getImgHW(img):
return img.shape[0],img.shape[1]

def distanceImg(img1,img2):
return np.sqrt(np.sum(np.square(img1 - img2)))

"""-----------------------operation start-------"""
def calcAndDrawHist(img,color=[255,255,255]): #color histgram
Expand Down Expand Up @@ -157,7 +159,7 @@ def loadImg(self,filename,mode=cv2.IMREAD_COLOR):


def infoImg(self,str='image:'):
return(str,'shape:',self.image.shape,'size:',self.image.size,'dtype:','dims=',self.image.ndim,self.image.dtype)
return print(str,'shape:',self.image.shape,'size:',self.image.size,'dtype:','dims=',self.image.ndim,self.image.dtype)

def getImagChannel(self):
if self.image.ndim == 3: #color r g b channel
Expand Down
41 changes: 18 additions & 23 deletions commonModule/imageHist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cv2.cv2 as cv2 #pip install opencv-python
import matplotlib.pyplot as plt

from imageBase import ImageBase
from ImageBase import *
from matplotHist import plotHistImg, getImgHist, getImgHist256Img

def plotImagHistListImgHist256(imgList):
Expand Down Expand Up @@ -56,8 +56,6 @@ def plotImgHist256Img(img):
break

def plotImagAndHist4(img): #must color img
b,g,r = cv2.split(img) # get b,g,r
img = cv2.merge([r,g,b]) # switch it to rgb
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

imgList=[]
Expand All @@ -66,9 +64,6 @@ def plotImagAndHist4(img): #must color img
return plotImagHistListImg(imgList)

def plotImagAndHist(img):
b,g,r = cv2.split(img) # get b,g,r
img = cv2.merge([r,g,b]) # switch it to rgb

plt.subplot(1, 2, 1)
plt.imshow(img)

Expand All @@ -91,26 +86,26 @@ def showimage(img,str='image',autoSize=False):
cv2.destroyAllWindows()

def main():
file = r'./res/obama.jpg'#'./res/Lenna.png' #
img = ImageBase(file,mode=cv2.IMREAD_COLOR) # IMREAD_GRAYSCALE IMREAD_COLOR
print(img.infoImg())
#img.showimage(autoSize=False)
#img.plotImg()
#showimage(img.calcAndDrawHist())
#showimage(img.thresHoldImage())
#img.showimage()

#plotHistImg(img.image)
#plotImagAndHist(img.image)
#plotImagAndHist4(img.image)
file = './res/Lenna.png' #r'./res/obama.jpg'#
img = loadImg(file,mode=cv2.IMREAD_COLOR) # IMREAD_GRAYSCALE IMREAD_COLOR
infoImg(img)
#showimage(img,autoSize=False)
#plotImg(img)

#showimage(calcAndDrawHist(img))
#showimage(thresHoldImage(img))
#plotHistImg(img)
#plotImagAndHist(img)
#plotImagAndHist4(img)

imgList=[]
imgGray = cv2.cvtColor(img.image, cv2.COLOR_BGR2GRAY)
imgList.append(img.image)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgList.append(img)
imgList.append(imgGray)
imgList.append(img.equalizedHist(imgGray))
imgList.append(equalizedHist(imgGray))

#plotImagHistListImg(imgList)
plotImagHistListImg(imgList)
plotImagHistListImgHist256(imgList)

if __name__=='__main__':
Expand Down
7 changes: 3 additions & 4 deletions commonModule/imagePlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def plotImagList2(imgList,nameList,gray=False,showTitle=True,showticks=True):
ax.margins(0, 0)
#ax.xaxis.set_major_locator(plt.NullLocator())
#ax.yaxis.set_major_locator(plt.NullLocator())


#plt.grid(True)
plt.tight_layout(pad=0)
Expand Down Expand Up @@ -74,9 +73,9 @@ def plotImagList(imgList,nameList,gray=False,showTitle=True,showticks=True):

def main():
#file = r'./res/obama.jpg'#'./res/Lenna.png' #
#img = ImageBase(file,mode=cv2.IMREAD_GRAYSCALE) # IMREAD_GRAYSCALE IMREAD_COLOR
#print(img.infoImg())
#showimage(img.binaryImage(thresHMin=50,thresHMax=150))
#img = loadImg(file,mode=cv2.IMREAD_GRAYSCALE) # IMREAD_GRAYSCALE IMREAD_COLOR
#infoImg(img)
#showimage(binaryImage2(img,thresHMin=50,thresHMax=150))
pass

if __name__=='__main__':
Expand Down
2 changes: 1 addition & 1 deletion commonModule/imageThres.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def showimage(img,str='image',autoSize=False):
def main():
file = './res/Lenna.png' #r'./res/obama.jpg'#
img = loadImg(file,mode=cv2.IMREAD_GRAYSCALE) # IMREAD_GRAYSCALE IMREAD_COLOR
#print(infoImg())
#infoImg()
img1 = binaryImage2(img,thresHMin=50,thresHMax=150)
img2 = binaryImage2(img,thresHMin=50,thresHMax=100)
img3 = thresHoldImage(img,mode = cv2.THRESH_BINARY)
Expand Down
2 changes: 1 addition & 1 deletion loadImages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Steven load facial images
#Steven
import os
import cv2
import numpy as np
Expand Down
16 changes: 8 additions & 8 deletions makeDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def calculateFeature(pts,H,W,file=r'./res/test.pts'):
F_EyeFissure = calculateRatio(pts,28,30,27,29)
F_VermilionHeight = calculateRatio(pts,51,66,66,57)
F_MouthFaceWidth = calculateRatio(pts,48,54,0,14)
F_Noise1 = calculateRatio(pts,39,46,39,41)
F_Noise2 = calculateRatio(pts,39,40,39,41)
F_Noise3 = calculateRatio(pts,39,38,39,41)
F_Noise4 = calculateRatio(pts,39,38,67,41)
F_Noise5 = calculateRatio(pts,39,41,67,41)
#print('name:',name,'Features=',F_Facial_Index,F_Mandibular_Index,F_Intercanthal,F_OrbitalWidth,F_EyeFissure,F_VermilionHeight,F_MouthFaceWidth,F_Noise1,F_Noise2,F_Noise3,F_Noise4,F_Noise5)
F_Nose1 = calculateRatio(pts,39,46,39,41)
F_Nose2 = calculateRatio(pts,39,40,39,41)
F_Nose3 = calculateRatio(pts,39,38,39,41)
F_Nose4 = calculateRatio(pts,39,38,67,41)
F_Nose5 = calculateRatio(pts,39,41,67,41)
#print('name:',name,'Features=',F_Facial_Index,F_Mandibular_Index,F_Intercanthal,F_OrbitalWidth,F_EyeFissure,F_VermilionHeight,F_MouthFaceWidth,F_Nose1,F_Nose2,F_Nose3,F_Nose4,F_Nose5)

return [F_Facial_Index,F_Mandibular_Index,F_Intercanthal,F_OrbitalWidth,F_EyeFissure,F_VermilionHeight,F_MouthFaceWidth,F_Noise1,F_Noise2,F_Noise3,F_Noise4,F_Noise5]
return [F_Facial_Index,F_Mandibular_Index,F_Intercanthal,F_OrbitalWidth,F_EyeFissure,F_VermilionHeight,F_MouthFaceWidth,F_Nose1,F_Nose2,F_Nose3,F_Nose4,F_Nose5]


dbFile = r'.\db\facial.csv'
Expand All @@ -71,7 +71,7 @@ def makeDb():

imgPath = r'E:\opencv\project\facialRecognition\db\recognitionDb'
df = pd.DataFrame()
#columns = ['F_Facial_Index', 'F_Mandibular_Index', 'F_Intercanthal','F_OrbitalWidth', 'F_EyeFissure', 'F_VermilionHeight','F_MouthFaceWidth', 'F_Noise1', 'F_Noise2', 'F_Noise3', 'F_Noise4','F_Noise5']
#columns = ['F_Facial_Index', 'F_Mandibular_Index', 'F_Intercanthal','F_OrbitalWidth', 'F_EyeFissure', 'F_VermilionHeight','F_MouthFaceWidth', 'F_Nose1', 'F_Nose2', 'F_Nose3', 'F_Nose4','F_Nose5']
columns = ['F_Facial_Index', 'F_Mandibular_Index', 'F_Intercanthal','F_OrbitalWidth', 'F_EyeFissure', 'F_VermilionHeight','F_MouthFaceWidth']

for i in pathsFiles(imgPath,'jpg'):
Expand Down

0 comments on commit 4a73859

Please sign in to comment.