Skip to content
Snippets Groups Projects
Commit 58784ae2 authored by mhby1g21's avatar mhby1g21
Browse files

modified run_shifter to be thread safe and fixed the steps when image is shifted

parent b92a25e5
Branches
No related tags found
1 merge request!11modified run_shifter to be thread safe and fixed the steps when image is shifted
...@@ -104,18 +104,38 @@ class ShifterTab(QWidget): ...@@ -104,18 +104,38 @@ class ShifterTab(QWidget):
scrollbar.setValue(scrollbar.maximum()) scrollbar.setValue(scrollbar.maximum())
def run_shifter(self): def run_shifter(self):
"""GUI version of shifter - calls the thread-safe version"""
if not self.input_file_path: if not self.input_file_path:
QMessageBox.warning(self, "Warning", "Please select an input file first") QMessageBox.warning(self, "Warning", "Please select an input file first")
return return False
self.update_status("\nRunning image shifter...") self.update_status("\nRunning image shifter...")
success, _ = run_command( success, _ = self.run_shifter_process(self.update_status)
self,
self.cmd_text.toPlainText(),
self.update_status
)
if success and os.path.exists(self.shifted_image_path): if success and os.path.exists(self.shifted_image_path):
self.update_status(f"Shifted image saved to: {self.shifted_image_path}") self.update_status(f"Shifted image saved to: {self.shifted_image_path}")
update_preview(self.output_preview, self.shifted_image_path, update_preview(self.output_preview, self.shifted_image_path,
error_callback=self.update_status) error_callback=self.update_status)
\ No newline at end of file return success
def run_shifter_process(self, status_callback=None):
"""Thread-safe version of shifter that doesn't use GUI components"""
try:
if not self.input_file_path:
raise ValueError("No input file selected")
# Construct command without using GUI components
conda_dir = self.config_reader.config["condaDir"]
material_env = self.config_reader.config["materialEnv"]
shifter_script = os.path.join(self.config_reader.directories['scriptDir'], "shifter.py")
command = f'"{conda_dir}\\condabin\\activate.bat" {material_env} && ' \
f'python "{shifter_script}" "{self.input_file_path}" "{self.shifted_image_path}"'
# Run the command
return run_command(None, command, status_callback)
except Exception as e:
if status_callback:
status_callback(f"Error in shifter process: {str(e)}")
return False, str(e)
\ No newline at end of file
...@@ -45,17 +45,41 @@ class PipelineWorker(QThread): ...@@ -45,17 +45,41 @@ class PipelineWorker(QThread):
self.progress.emit("Cleaning EdgeNet output directory...") self.progress.emit("Cleaning EdgeNet output directory...")
def copy_file(self): def copy_file(self):
self.progress.emit("Copying input file to scripts/360monodepthexecution...") # Determine which file to use as input
self.tab.depth.depth_input_path = self.tab.shifter.shifted_image_path if self.tab.should_shift_image else self.tab.input_path
if self.tab.should_shift_image:
self.progress.emit("Copying shifted image to scripts/360monodepthexecution...")
else:
self.progress.emit("Copying input file to scripts/360monodepthexecution...")
self.tab.depth.copy_file() self.tab.depth.copy_file()
def shift_image(self): def shift_image(self):
print("Starting shift_image") # Debug print print("Starting shift_image") # Debug print
if not self.tab.shift_image_check.isChecked(): if not self.tab.should_shift_image:
self.progress.emit("Skipping image shift...") self.progress.emit("Skipping image shift...")
return return
self.progress.emit("Shifting input image...")
self.tab.shifter.run_shifter() try:
print("Completed shift_image") # Debug print self.progress.emit("Shifting input image...")
# Set input path for shifter
self.tab.shifter.input_file_path = self.tab.input_path
# Use the thread-safe version
success, output = self.tab.shifter.run_shifter_process(self.progress.emit)
if not success:
raise RuntimeError(f"Image shifting failed: {output}")
print("Completed shift_image")
# Change material recognition input file path to shifted image
self.tab.material.input_file_path = self.tab.shifter.shifted_image_path
return self.tab.shifter.shifted_image_path
except Exception as e:
print(f"Shift image failed: {str(e)}")
raise
def run_depth_estimation(self): def run_depth_estimation(self):
print("Starting depth_estimation") # Debug print print("Starting depth_estimation") # Debug print
...@@ -107,7 +131,7 @@ class PipelineWorker(QThread): ...@@ -107,7 +131,7 @@ class PipelineWorker(QThread):
self.progress.emit("Running EdgeNet enhance360.py and infer360.py...") self.progress.emit("Running EdgeNet enhance360.py and infer360.py...")
try: try:
self.tab.edge_net.include_top = self.tab.include_top_check.isChecked() self.tab.edge_net.include_top = self.tab.should_include_top # Use cached state
self.tab.edge_net._run_edge_net_process() self.tab.edge_net._run_edge_net_process()
print("Completed edge_net") print("Completed edge_net")
except Exception as e: except Exception as e:
...@@ -124,8 +148,8 @@ class PipelineWorker(QThread): ...@@ -124,8 +148,8 @@ class PipelineWorker(QThread):
def run_pipeline(self): def run_pipeline(self):
self.clean_temp_files() self.clean_temp_files()
self.copy_file()
self.shift_image() self.shift_image()
self.copy_file()
self.run_depth_estimation() self.run_depth_estimation()
self.run_material_recognition() self.run_material_recognition()
self.run_edge_net() self.run_edge_net()
...@@ -138,6 +162,10 @@ class SimpleTab(QWidget): ...@@ -138,6 +162,10 @@ class SimpleTab(QWidget):
self.config_reader = config_reader self.config_reader = config_reader
self.input_path = None self.input_path = None
self.pipeline_thread = None self.pipeline_thread = None
# Store states that will be used by worker thread
self.should_shift_image = False
self.should_include_top = False
# Initialize module instances # Initialize module instances
self.shifter = ShifterTab(self.config_reader) self.shifter = ShifterTab(self.config_reader)
...@@ -244,9 +272,6 @@ class SimpleTab(QWidget): ...@@ -244,9 +272,6 @@ class SimpleTab(QWidget):
self.shift_image_check.setStyleSheet("QCheckBox { margin: 5px; background-color: #3e3e3e;}") self.shift_image_check.setStyleSheet("QCheckBox { margin: 5px; background-color: #3e3e3e;}")
options_layout.addWidget(self.shift_image_check) options_layout.addWidget(self.shift_image_check)
#TODO: FIX THIS, BREAKS THE APP WHEN ENABLED AND PIPELINE IS RUN
self.shift_image_check.setEnabled(False)
# SSC Model selection # SSC Model selection
ssc_model_layout = QHBoxLayout() ssc_model_layout = QHBoxLayout()
ssc_model_label = QLabel("SSC Model:") ssc_model_label = QLabel("SSC Model:")
...@@ -577,6 +602,10 @@ class SimpleTab(QWidget): ...@@ -577,6 +602,10 @@ class SimpleTab(QWidget):
if self.pipeline_thread and self.pipeline_thread.isRunning(): if self.pipeline_thread and self.pipeline_thread.isRunning():
QMessageBox.warning(self, "Warning", "Pipeline is already running") QMessageBox.warning(self, "Warning", "Pipeline is already running")
return return
# Cache checkbox states before starting thread
self.should_shift_image = self.shift_image_check.isChecked()
self.should_include_top = self.include_top_check.isChecked()
# Show progress bar and update status # Show progress bar and update status
self.progress_bar.show() self.progress_bar.show()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment