示例#1
0
文件: batch.py 项目: chxzh/shadyn
def vanilla():
    from PIL import Image
    target_path = "..\\img\\target_diamond.png"
    target_path = "..\\img\\target_spade.png"
#     target_path = "..\\img\\target_mickey.png"
#     target_path = "..\\img\\target_heart.png"
#     target_path = "..\\img\\target_forward.png"
#     target_path = "..\\img\\target_recycle.png"
    
#     target_img = Image.open(target_path).convert('L')
    penalties = [Optimizer.penalty_name]
#     energies = ["first moments (normalized)", "XOR comparison", "secondary moments (normalized)"]
#     energies = ["XOR comparison"]
    energies = ["uncovered pixels", "distance field"]
#     energies = ["first moments (normalized)"]
#     energies = ["secondary moments (normalized)"]
#     energy_pairs = [energies, [1e-4,1,1e-4]]
    weights = [1,1]
    energy_pairs = [energies, weights]
    rendis = Renderer_dispatcher()
    rendis.target_image = Image.open(target_path)
    rendis.start()
    init_X_Y(640, 480)
    plotter = plotting.Plotter(*get_fname("..\\res"))
    optimizer = Optimizer(rendis)
    plotting.attach_plotter(optimizer, plotter)
    optimizer.set_target(target_path)
    optimizer.set_method("CMA")
#     optimizer.set_energy(["first moments (normalized)"], [1])
    optimizer.set_energy(*energy_pairs)
#     optimizer.set_energy(["XOR comparison"], [1])
    gui = Minimalistic_GUI(optimizer)
    gui.run()
示例#2
0
文件: batch.py 项目: chxzh/shadyn
def all_single_energy_combos():
    renderer = Renderer()
    renderer.start()
    renderer.wait_till_init()
    x_0 = renderer.get_param()
    for method_name, energy_name in product(Optimizer.method_dic, Optimizer.energy_dic):
        print method_name, energy_name
        renderer.set_param(x_0)
        optimizer = Optimizer(None)
        plotting.attach_plotter(optimizer, plotting.Plotter(*get_fname("..\\res")))
        optimizer.set_target("C:\\Users\\cxz\\Pictures\\target.png")
        optimizer.set_method(method_name)
        optimizer.set_energy([energy_name], [1])
        optimizer.run()
示例#3
0
 def _on_play_pause(self):
     # not started
     if self._optimizer == None or not self._optimizer.is_alive():
         self._optimizer = Optimizer(self.rendis)
         plotter = plotting.Plotter(*get_fname("..\\res"))
         plotting.attach_plotter(self._optimizer, plotter)
         # configuring the optimizer by feeding in optimizing-method and energy function
         if self.target_path != None:
             self._optimizer.set_target(self.target_path)
         else:
             msg_box = QMessageBox()
             msg_box.setText("no target image is selected")
             msg_box.exec_()
             return
         self._optimizer.set_method(self.optim_combo.currentText())
         try:
             self._optimizer.set_energy(*self._get_energy_pairs())
         except RuntimeWarning as rtwng:
             msg_box = QMessageBox()
             msg_box.setText("no energy function is selected")
             msg_box.exec_()
             return
         self._optimizer.set_finished_callback(self._on_optim_done)
         param_lock = Lock()
         self._optimizer.set_iter_callback(self._on_iter_callback, param_lock)
         param_updater = Lock_listener(param_lock, self._on_param_updated)
         if self.armijo_check.isEnabled():
             self._optimizer.line_search_first = self.armijo_check.checkState()
         self._optimizer.start()
         self.play_pause_button.setText("PAUSE")
         self.stop_button.setEnabled(True)
         self.is_on_going = True
     else:
         # started already
         self.is_on_going = not self.is_on_going
         self._optimizer.switch()
         if self.is_on_going:  # optimizing, to pause
             self.play_pause_button.setText("PLAY")
         else:  # pausing, to continue
             self.play_pause_button.setText("PAUSE")
示例#4
0
文件: batch.py 项目: chxzh/shadyn
def get_default_plotted_optimizer(renderer):    
    optimizer = Optimizer(renderer)
    plotting.attach_plotter(optimizer, plotting.Plotter(*get_fname("..\\res")))
    return optimizer