def set_target(self, img, rect, landmarks=None): # rect: [x0, y0, x1, y1] self.template = self.crop(img, rect) self.rect = list(rect) m, n, nchannel = self.template.shape if landmarks is not None: self.landmarks = landmarks.copy() else: self.landmarks = distortion_util.create_landmarks(m, n, self.nSide) self.landmarks_global = self.landmarks.copy() self.landmarks_global[0, :, :] += rect[0] self.landmarks_global[1, :, :] += rect[1] def_spec = distortion_util.get_def_spec(self.template, self.landmarks, "landmark") alg_spec = distortion_util.get_hddd_parameters_fixed_layer( self.template, self.sigma, self.landmarks, 7, 0.7) # alg_spec = distortion_util.get_hddd_parameters(self.template, self.sigma, self.landmarks); deformation_pylib.InitializeDeformation(def_spec.SerializeToString()) print "GenerateDDDSamples" deformation_pylib.GenerateDDDSamples(self.template, alg_spec.SerializeToString())
def set_target(self, img, rect, landmarks=None): # rect: [x0, y0, x1, y1] self.template = self.crop(img, rect); self.rect = list(rect); m, n, nchannel = self.template.shape; if landmarks is not None: self.landmarks = landmarks.copy(); else: self.landmarks = distortion_util.create_landmarks(m, n, self.nSide) self.landmarks_global = self.landmarks.copy(); self.landmarks_global[0,:,:] += rect[0] self.landmarks_global[1,:,:] += rect[1] def_spec = distortion_util.get_def_spec(self.template, self.landmarks, "landmark"); alg_spec = distortion_util.get_hddd_parameters_fixed_layer(self.template, self.sigma, self.landmarks, 7, 0.7) # alg_spec = distortion_util.get_hddd_parameters(self.template, self.sigma, self.landmarks); deformation_pylib.InitializeDeformation(def_spec.SerializeToString()); print "GenerateDDDSamples" deformation_pylib.GenerateDDDSamples(self.template, alg_spec.SerializeToString());
img = img[:, :, 0:3] img = cv2.resize(img, (img.shape[0] / scale, img.shape[1] / scale)).astype('f4') img = numpy.ascontiguousarray(img) print img.shape print img.dtype # cv2.imshow("Test2", img); # cv2.waitKey() # sys.exit(0); m, n, channel = img.shape print "Set Landmarks" nSide = 3 landmarks = distortion_util.create_landmarks(m, n, nSide) # deformation_pylib.SetLandmarks(m, n, landmarks.reshape((2, nSide*nSide))) #visualize_deformation_backward(img, landmarks, 6.0) #verify_deformation_prediction("../nn/deformation_backward_model_10-14-2014_22-47-04.bin"); #verify_deformation_prediction(img, landmarks, "./deformation_backward_model_deformation_backward-10-15-2014_21-20-24-deformation.bin"); #variance_verify_deformation(img, landmarks, "./deformation_backward_model_deformation_backward-10-15-2014_21-20-24-deformation.bin") distortion_sigma = 10.0 #distortion_sigma = 0.5; test_data_driven_descent(img, landmarks, distortion_sigma) # ps, deforms = dump_deformed_images(img, landmarks, "forward", 5000) # Save the training samples. # numpy.savez(open("deformation_data_" + deform_arg + ".bin", "w"), deforms=deforms, ps=ps)
img = cv2.imread("test2.png"); img = img[:,:,0:3] img = cv2.resize(img, (img.shape[0] / scale, img.shape[1] / scale)).astype('f4') img = numpy.ascontiguousarray(img) print img.shape print img.dtype # cv2.imshow("Test2", img); # cv2.waitKey() # sys.exit(0); m, n, channel = img.shape; print "Set Landmarks" nSide = 3; landmarks = distortion_util.create_landmarks(m, n, nSide) # deformation_pylib.SetLandmarks(m, n, landmarks.reshape((2, nSide*nSide))) #visualize_deformation_backward(img, landmarks, 6.0) #verify_deformation_prediction("../nn/deformation_backward_model_10-14-2014_22-47-04.bin"); #verify_deformation_prediction(img, landmarks, "./deformation_backward_model_deformation_backward-10-15-2014_21-20-24-deformation.bin"); #variance_verify_deformation(img, landmarks, "./deformation_backward_model_deformation_backward-10-15-2014_21-20-24-deformation.bin") distortion_sigma = 10.0; #distortion_sigma = 0.5; test_data_driven_descent(img, landmarks, distortion_sigma) # ps, deforms = dump_deformed_images(img, landmarks, "forward", 5000) # Save the training samples. # numpy.savez(open("deformation_data_" + deform_arg + ".bin", "w"), deforms=deforms, ps=ps)