Exemplo n.º 1
0
def displayFaceCompareResult(sourceFaceId):
  faceDB = FaceData.getFaceData()
  compareFace = FaceUtils.compareFaceByOthers(sourceFaceId)
  faceData = faceDB.findFaceById(sourceFaceId)
  faceFilePath = faceData['imagePath']
  faceId = faceData['faceId']
  faceImage = cv.imread(faceFilePath)

  namedWindowName = 'test_' + str(faceId)
  cv.namedWindow(namedWindowName)
  cv.imshow(namedWindowName, faceImage)


  for valueObj in compareFace:
    faceId = valueObj[0]
    similarValue = valueObj[1]
    if (similarValue <= 0.42):
      faceData = faceDB.findFaceById(faceId)
      faceFilePath = faceData['imagePath']
      faceId = faceData['faceId']
      faceImage = cv.imread(faceFilePath)

      namedWindowName = 'test_' + str(faceId)
      cv.namedWindow(namedWindowName)
      cv.imshow(namedWindowName, faceImage)
    else:
      break

  cv.waitKey(0)
  cv.destroyAllWindows()
Exemplo n.º 2
0
def loadAllFaceFeatures():
    faceDB = FaceData.getNewFaceData()
    faceDataList = faceDB.getAllFaces()
    allFaceList = {}
    for faceData in faceDataList:
        featurePath = faceData['featurePath']
        faceId = faceData['faceId']
        if (len(featurePath) > 0):
            face_array = np.load(featurePath)
            allFaceList[faceId] = face_array
    return allFaceList
Exemplo n.º 3
0
def compareFaceByOthers(faceId):
    faceDB = FaceData.getNewFaceData()
    faceData = faceDB.findFaceById(faceId)
    if (faceData != None):
        featureFilePath = faceData['featurePath']
        print("开始load feature:" + featureFilePath)
        currentFeature = np.load(featureFilePath)

        faceCompareResult = {}
        allFaceFeature = loadAllFaceFeatures()
        for key, otherFaceFeature in allFaceFeature.items():
            if (key != faceId):
                distance = (np.linalg.norm(currentFeature - otherFaceFeature))
                faceCompareResult[key] = distance
        sortedFaces = sorted(faceCompareResult.items(), key=lambda d: d[1])
        print(sortedFaces)
        return sortedFaces
Exemplo n.º 4
0
def updateMostSimilarPerson(faceId):
  faceDB = FaceData.getFaceData()
  compareFace = FaceUtils.compareFaceByOthers(faceId)


  for valueObj in compareFace:
    compareFaceId = valueObj[0]
    similarValue = valueObj[1]
    compareFaceObj = faceDB.findFaceById(compareFaceId)
    compareFaceAssignStatus = compareFaceObj['assignedStatus']
    if (compareFaceAssignStatus == 'U' or compareFaceAssignStatus == 'A'):
      if (similarValue <= 0.4):
        compareFaceData = faceDB.findFaceById(compareFaceId)
        comparePersonId = compareFaceData['personId']
        faceDB.changeFacePerson(faceId, comparePersonId, 'A')
        print('找到相似的脸' + str(comparePersonId))
      else:
        faceDB.changeFacePerson(faceId, Constants.PERSON_ID_UNNAMED, 'U')
        print('没有相似的脸, 更新为 匿名')
    else:
      print('这张脸手动改过')
    break
Exemplo n.º 5
0
def getFaceInDBByRawImage(rawImageName):
    faceDB = FaceData.getFaceData()
    return faceDB.searchFaceByRawImageFileName(rawImageName)
Exemplo n.º 6
0
def updateFaceFeatureFile(faceId, featurePath):
    faceDB = FaceData.getFaceData()
    return faceDB.updateFaceFeature(faceId, featurePath)
Exemplo n.º 7
0
def createNewFaceForPerson(facePath, rawImagePath, personId):
    faceDB = FaceData.getFaceData()
    return faceDB.newFace(rawImagePath, facePath, personId)
Exemplo n.º 8
0
def createNewPersonFace(facePath, rawImagePath):
    faceDB = FaceData.getFaceData()
    personId = faceDB.newPerson(None)
    return faceDB.newFace(rawImagePath, facePath, personId)