def calc_final_match(modelFoto, inputFoto): primary = readOpenPoseJson.readJsonFile('json_data/' + modelFoto + '.json') secondary = readOpenPoseJson.readJsonFile('json_data/' + inputFoto + '.json') #parameters van functie zijn slecht gekozen => secondary = input && primary = model result = calcEucldError.norm_cte_decide_match_or_not(secondary, primary) print("Match or not: ", result) return result
def calc_match(modelFoto, inputFoto): # 2D array. Elke entry is een coordinatenkoppel(joint-point) in 3D , z-coordinaat wordt nul gekozen want we werken in 2D # Bevat 18 coordinatenkoppels want openpose returnt 18 joint-points primary = readOpenPoseJson.readJsonFile('json_data/' + modelFoto + '.json') secondary = readOpenPoseJson.readJsonFile('json_data/' + inputFoto + '.json') #parameters van functie zijn slecht gekozen => secondary = input && primary = model result = calcEucldError.norm_cte(secondary, primary) return result
resolutieX = 1440 resolutieY = 1920 modelFoto = "foto2" inputFoto = "foto1_rendered" #2D array. Elke entry is een coordinatenkoppel(joint-point) in 3D , z-coordinaat wordt nul gekozen want we werken in 2D #Voorbeeld; # primary = np.array([[11,4,0], # [18,7,0], # [3,11,0], # [11, 11, 0], # [12, 19, 0], # [17, 26, 0], # [5, 26, 0]]) #Bevat 18 coordinatenkoppels want openpose returnt 18 joint-points primary = readOpenPoseJson.readJsonFile(modelFoto + '.json') secondary = readOpenPoseJson.readJsonFile(inputFoto + '.json') # secondary = np.array([[35,3,0], # [46,20,0], # [22,13,0], # [35, 13, 0], # [35, 24, 0], # [43,34, 0], # [26, 35, 0]]) #Zoek 2D affine transformatie matrix om scaling, rotatatie en translatie te beschrijven tussen model en input #2x2 matrix werkt niet voor translaties # Pad the data with ones, so that our transformation can do translations too n = primary.shape[0] pad = lambda x: np.hstack([x, np.ones((x.shape[0], 1))]) #horizontaal stacken
def doCalc(modelFoto, inputFoto): # plot vars markersize = 3 im_model = plt.imread('Pictures/' + modelFoto + '.jpg') # print("res: ", im_model.shape[0]) # portrait foto, gsm jochen resolutieX_model = im_model.shape[1] # 1440 resolutieY_model = im_model.shape[0] # 1920 im_input = plt.imread('Pictures/' + inputFoto + '.jpg') # rendered foto resolutieX = im_input.shape[1] # 1440 #1280 resolutieY = im_input.shape[0] # 1920 #720 # 2D array. Elke entry is een coordinatenkoppel(joint-point) in 3D , z-coordinaat wordt nul gekozen want we werken in 2D # Bevat 18 coordinatenkoppels want openpose returnt 18 joint-points primary = readOpenPoseJson.readJsonFile('json_data/' + modelFoto + '.json') secondary = readOpenPoseJson.readJsonFile('json_data/' + inputFoto + '.json') primary_fixed_points = np.vstack( [primary[0:3], primary[5], primary[8], primary[11]]) secondary_fixed_points = np.vstack( [secondary[0:3], secondary[5], secondary[8], secondary[11]]) (modelTransform_fixed_points, A_fixed_points ) = calcTransformationMatrix.calcTransformationMatrix_fixed_points( secondary_fixed_points, primary_fixed_points, secondary) plot = False if plot: f, (ax1, ax2, ax4) = plt.subplots(1, 3, sharey=True, figsize=(14, 6)) implot = ax1.imshow(im_model) ax1.set_title(modelFoto + '(model)') ax1.plot(*zip(*primary), marker='o', color='r', ls='', label='model', ms=markersize) # ms = markersize ax1.plot(*zip(*primary_fixed_points), marker='o', color='g', ls='', label='model', ms=markersize) # ms = markersize red_patch = mpatches.Patch(color='red', label='model') ax1.legend(handles=[red_patch]) ax2.set_title(inputFoto) ax2.imshow(im_input) ax2.plot(*zip(*secondary), marker='o', color='b', ls='', ms=markersize) ax2.legend(handles=[mpatches.Patch(color='blue', label='input')]) ax4.set_title('Transformatie + model') ax4.imshow(im_model) ax4.plot(*zip(*primary), marker='o', color='b', ls='', ms=markersize) ax4.plot(*zip(*modelTransform_fixed_points), marker='o', color='cyan', ls='', ms=markersize) plt.draw() plt.show() # Gewoon MAX[ xi-x'i en yi-y'i ] maxError = np.abs(primary - modelTransform_fixed_points) # np.sqrt(np.sum((maxError[:,0] - maxError[:,1]) ** 2)) euclDis = ((maxError[:, 0])**2 + maxError[:, 1]**2)**0.5 euclDisNorm = ((maxError[:, 0] / resolutieX_model)**2 + (maxError[:, 1] / resolutieY_model)**2)**0.5 max_euclDis = max(euclDis) sum_max_euclDis = np.sum(euclDis) return [max_euclDis, sum_max_euclDis]
markersize = 3 im_model = plt.imread('Pictures/' + modelFoto + '.jpg') # print("res: ", im_model.shape[0]) # portrait foto, gsm jochen resolutieX_model = im_model.shape[1] # 1440 resolutieY_model = im_model.shape[0] # 1920 im_input = plt.imread('Pictures/' + inputFoto + '.jpg') # rendered foto resolutieX = im_input.shape[1] # 1440 #1280 resolutieY = im_input.shape[0] # 1920 #720 # 2D array. Elke entry is een coordinatenkoppel(joint-point) in 3D , z-coordinaat wordt nul gekozen want we werken in 2D # Bevat 18 coordinatenkoppels want openpose returnt 18 joint-points primary = readOpenPoseJson.readJsonFile('json_data/' + modelFoto + '.json') secondary = readOpenPoseJson.readJsonFile('json_data/' + inputFoto + '.json') # enkel subarrays # NEK WORDT MOMENTEEL NIET GEBRUIKT, geeft minder nauwkeurige resultaten ?? primary_torso = primary[2:8] secondary_torso = secondary[2:8] primary_legs = primary[8:14] secondary_legs = secondary[8:14] primary_face = np.vstack([primary[0], primary[14:18]]) secondary_face = np.vstack([secondary[0], secondary[14:18]]) (modelTransform_torso, A_torso) = calcTransformationMatrix.calcTransformationMatrix(primary_torso, secondary_torso) (modelTransform_legs, A_legs) = calcTransformationMatrix.calcTransformationMatrix(primary_legs, secondary_legs)
def matchPose(modelP, inputP): modelFoto = modelP #"foto3" inputFoto = inputP #"foto1" # plot vars markersize = 3 im_model = plt.imread('Pictures/' + modelFoto + '.jpg') print("res: " , im_model.shape[0]) # portrait foto, gsm jochen resolutieX_model = im_model.shape[1] # 1440 resolutieY_model = im_model.shape[0] # 1920 im_input = plt.imread('Pictures/' + inputFoto + '.jpg') # rendered foto resolutieX = im_input.shape[1] # 1440 #1280 resolutieY = im_input.shape[0] # 1920 #720 # 2D array. Elke entry is een coordinatenkoppel(joint-point) in 3D , z-coordinaat wordt nul gekozen want we werken in 2D # Voorbeeld; # primary = np.array([[11,4,0], # [18,7,0], # [3,11,0], # [11, 11, 0], # [12, 19, 0], # [17, 26, 0], # [5, 26, 0]]) # Bevat 18 coordinatenkoppels want openpose returnt 18 joint-points primary = readOpenPoseJson.readJsonFile('json_data/' + modelFoto + '.json') secondary = readOpenPoseJson.readJsonFile('json_data/' + inputFoto + '.json') # secondary = np.array([[35,3,0], # [46,20,0], # [22,13,0], # [35, 13, 0], # [35, 24, 0], # [43,34, 0], # [26, 35, 0]]) #FILTERING & STRIPPING OF UNDETECTED JOINTS #Check if all joints are detected. Undetected joints are undefinded (0,0) #Remove undetected joints from matrix for i in range(0,17): if i < secondary.shape[0]: if(secondary[i][0] == 0 and secondary[i][1] ==0): print("no_joint! ") secondary = np.delete(secondary, (i), axis=0) primary = np.delete(primary, (i), axis=0) i = i-1 #enkel subarrays #primary = primary[8:14] #secondary = secondary[8:14] (modelTransform, A) = calcTransformationMatrix.calcTransformationMatrix(primary, secondary) print("A- transformatie matrix:") print(A) print("Input:") print(secondary) print("Result- transformatie van model:") print(modelTransform) #print("eerste kolom:") #print(modelTransform[:,0]) #bereken correlatie tussen 2 matrixen print("###correlation: ") print(np.corrcoef(modelTransform[:,0]/resolutieX, secondary[:,0]/resolutieY)) print(np.corrcoef(modelTransform[:, 1]/resolutieX, secondary[:, 1]/resolutieY)) print("matric correlation: " ) print(util.corr2_coeff(modelTransform, secondary).min()) # Gewoon MAX[ xi-x'i en yi-y'i ] maxError = np.abs(secondary - modelTransform) print("Max error:", maxError.max()) # print(maxError) # np.sqrt(np.sum((maxError[:,0] - maxError[:,1]) ** 2)) euclDis = ((maxError[:, 0]) ** 2 + maxError[:, 1] ** 2) ** 0.5 euclDisNorm = ((maxError[:, 0] / resolutieX) ** 2 + (maxError[:, 1] / resolutieY) ** 2) ** 0.5 # Euclidean distance boven gwn coordinaten verschil want eucl dis is ne cirkel # print("euclidean dis: ", euclDis) max_euclDis = max(euclDis) print("\n-------- Euclidean dis -------") print("Max euclidean dis: ", max_euclDis) print("Body part: ", util.getBodyPartByIndex(np.argmax(euclDis, axis=None))) max_euclDis_norm = max(euclDisNorm) sum_max_euclDis_norm = np.sum(euclDisNorm) print("\n----- Euclidean dis genormaliseeerd -----") print("euclid dis NORM; ", euclDisNorm) print("Max euclidean dis norm resolutie: ", max_euclDis_norm) print("Sum euclidean dis: ", sum_max_euclDis_norm) print("Body part: ", util.getBodyPartByIndex(np.argmax(euclDisNorm, axis=None))) # plot img f, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4, sharey=True, figsize=(14, 6)) implot = ax1.imshow(im_model) ax1.set_title(modelFoto + '(model)') ax1.plot(*zip(*primary), marker='o', color='r', ls='', label='model', ms=markersize) # ms = markersize red_patch = mpatches.Patch(color='red', label='model') ax1.legend(handles=[red_patch]) ax2.set_title(inputFoto) ax2.imshow(im_input) ax2.plot(*zip(*secondary), marker='o', color='b', ls='', ms=markersize) ax2.legend(handles=[mpatches.Patch(color='blue', label='input')]) ax3.set_title('Transformation of model') ax3.imshow(im_input) ax3.plot(*zip(*modelTransform), marker='o', color='y', ls='', ms=markersize) ax3.legend(handles=[mpatches.Patch(color='yellow', label='Transformation of model')]) ax4.set_title('Transformatie + input') ax4.imshow(im_input) ax4.plot(*zip(*secondary), marker='o', color='b', ls='', ms=markersize) ax4.plot(*zip(*modelTransform), marker='o', color='y', ls='', ms=markersize) print("Evaluation poses: ", evaluateError(max_euclDis_norm, sum_max_euclDis_norm)) plt.show() return (max_euclDis, max_euclDis_norm, sum_max_euclDis_norm);