diff --git a/360monodepth b/360monodepth index 29e4bf230b0a2994d44c0673f497743e1a60df3c..ae9bee5325ffcdce9d9b8659017177c35d561564 160000 --- a/360monodepth +++ b/360monodepth @@ -1 +1 @@ -Subproject commit 29e4bf230b0a2994d44c0673f497743e1a60df3c +Subproject commit ae9bee5325ffcdce9d9b8659017177c35d561564 diff --git a/scripts/GUI2.py b/scripts/GUI2.py new file mode 100644 index 0000000000000000000000000000000000000000..de32d3b0002f21d472c0b3409cdacebc464bcee8 --- /dev/null +++ b/scripts/GUI2.py @@ -0,0 +1,254 @@ +import tkinter as tk +import tkinter.filedialog +import tkinter.font as tkfont +from tkinter import ttk +import subprocess +import sys +import time +from threading import Thread +import shutil +import os + +# Get the directory of the current script +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +# Get the root directory (AVVR-Pipeline-Internship) +ROOT_DIR = os.path.dirname(SCRIPT_DIR) + +file_path = None +createDepth = "0" + +def shift_image_selection(): + # This function can be used if you want to perform any action when the checkbox is clicked + pass + +def copy_intermediary_outputs(): + source_folder = os.path.join(ROOT_DIR, "edgenet-360", "Data", "Input") + destination_folder = os.path.join(ROOT_DIR, "edgenet-360", "Output") + files_to_copy = ["depth_e.png", "enhanced_depth_e.png", "material.png", "rgb.png"] + + for file_name in files_to_copy: + source_path = os.path.join(source_folder, file_name) + destination_path = os.path.join(destination_folder, file_name) + try: + shutil.copy(source_path, destination_path) + print(f"Copied {file_name} to {destination_folder}") + except FileNotFoundError: + print(f"Warning: {file_name} not found in {source_folder}") + +def select_Image(event): + global file_path + file_path = tkinter.filedialog.askopenfilename() + file_path = os.path.normpath(file_path) + select_button.configure(text="Selected", bg="red") + label.configure(text="Image is selected. Press run to create scene.") + +def depthmap_creation(): + print("Manually upload depth map: ", uploadDepthCheck.get()) + + if uploadDepthCheck.get() == 1: # if manually upload checked + check.set(0) # disable auto generation of depth map + upload_depth_path = tkinter.filedialog.askopenfilename(title="Select a depth map", filetypes=[("PNG files", "*.png")]) # dialog box to upload depth map + + if upload_depth_path: + print(f"Uploaded depth map: {upload_depth_path}") + # TODO: Implement Mona's monodepth upload + else: + print("No depth map selected") + check.set(1) # if no depth map selected, enable auto generation of depth map + depth_check.deselect() # uncheck the depth map check box + else: + check.set(1) # if manually upload unchecked, enable auto generation of depth map + upload_depth_path = None + print("Removed uploaded depth map") + +def stanfordRoom_selection(): + if checkStanford.get() == 1: + global stanford_frame + stanford_frame = tk.Frame(window) + stanford_frame.pack(fill=tk.X, padx=10, pady=10) + global labelRoomArea + labelRoomArea = tk.Label(stanford_frame, text="Please Input Room Area: ", font=custom_font) + labelRoomArea.pack(side="left") + global stanford_text + stanford_text = tk.Entry(stanford_frame, font=custom_font) + stanford_text.pack(side="left", fill=tk.X, expand=True) + else: + stanford_frame.pack_forget() + + select_button.pack(side="top", fill=tk.X, expand=True, padx=10, pady=10) + run_button.pack(side="top", fill=tk.X, expand=True, padx=10, pady=10) + +def run_Image(event): + if checkStanford.get() == 0: + label.configure(text="Pipeline is running. Creating scene...", height=15) + else: + label.configure(text="Pipeline is running for Stanford2D3D dataset. Creating scene...", height=15) + labelRoomArea.configure(text="Room Area Running : ") + stanford_text.configure(state="disabled") + + select_button.pack_forget() + run_button.pack_forget() + depth_check.pack_forget() + include_top_check.pack_forget() + stanford_check.pack_forget() + shift_image_check.pack_forget() + threading() + +def runProcess(): + global file_path + include_top_option = "y" if include_top.get() == 1 else "" + shift_image_option = "y" if shift_image.get() == 1 else "" + + try: + if checkStanford.get() == 0: + combined_bat = os.path.join(SCRIPT_DIR, "combined.bat") + print(f"Attempting to run: {combined_bat}") + print(f"With arguments: {file_path}, {str(check.get())}, {include_top_option}, {shift_image_option}") + + # depth map check + if check.get() == 1: + print("Auto depth map") + else: + print("Manual depth map") + + p = subprocess.Popen( + [combined_bat, file_path, str(check.get()), include_top_option, shift_image_option], + stdout=sys.stdout) + p.communicate() + + else: + temp = os.path.split(file_path) + suffices = temp[-1].split("_") + camera_pos = str(suffices[1]) + room_name = suffices[2] + "_" + suffices[3] + room_area = stanford_text.get() + + print(room_area, room_name, camera_pos) + combined_stanford_bat = os.path.join(SCRIPT_DIR, "combined_stanford.bat") + p = subprocess.Popen( + [combined_stanford_bat, file_path, camera_pos, str(room_area), room_name], + stdout=sys.stdout) + p.communicate() + + copy_intermediary_outputs() + label.configure(text="Pipeline execution complete, check output folder.") + + except Exception as e: + print(f"An error occurred: {e}") + label.configure(text=f"An error occurred: {e}") + + try: + labelRoomArea.pack_forget() + stanford_text.pack_forget() + except Exception as e: + print(e) + +def threading(): + thread1 = Thread(target=runProcess) + thread1.start() + +# Initialize the root window +window = tk.Tk() +window.title("Immersive VR Scene Creator") +window.configure(bg="#f4f4f4") + +# Initialize tkinter variables after creating the root window +check = tk.IntVar() +check.set(1) # automatically generate depth map as default +uploadDepthCheck = tk.IntVar() # added uploadDepthCheck variable: 0 = automatically upload depth map, 1 = manually upload depth map +checkStanford = tk.IntVar() +include_top = tk.IntVar() +shift_image = tk.IntVar() + +# Custom font +custom_font = tkfont.Font(family="Helvetica", size=12) + +# Main Label +label = tk.Label( + text="Please select an RGB image for scene creation", + font=custom_font, + fg="black", + bg="#f4f4f4", + width=50, + height=5, + anchor="center" +) +label.grid(row=0, column=0, padx=10, pady=10, columnspan=2) + +# Buttons Frame +buttons_frame = tk.Frame(window, bg="#f4f4f4") +buttons_frame.grid(row=1, column=0, columnspan=2, pady=10) + +select_button = tk.Button( + buttons_frame, + text="Select", + width=30, height=2, + bg="#4CAF50", fg="white", + font=custom_font, + activebackground="#45a049", activeforeground="white" +) +select_button.grid(row=0, column=0, padx=5, pady=5) + +run_button = tk.Button( + buttons_frame, + text="Run", + width=30, height=2, + bg="#008CBA", fg="white", + font=custom_font, + activebackground="#007B9E", activeforeground="white" +) +run_button.grid(row=0, column=1, padx=5, pady=5) + +# Checkboxes Frame +checkbox_frame = tk.Frame(window, bg="#f4f4f4") +checkbox_frame.grid(row=2, column=0, columnspan=2, pady=10) + +depth_check = tk.Checkbutton( + checkbox_frame, + text='Upload a depth map (360 MonoDepth)', + variable=uploadDepthCheck, + onvalue=1, offvalue=0, + command=depthmap_creation, + font=custom_font, + bg="#f4f4f4" +) +depth_check.grid(row=0, column=0, padx=5, pady=5) + +stanford_check = tk.Checkbutton( + checkbox_frame, + text='Run for Stanford2D3D dataset', + variable=checkStanford, + onvalue=1, offvalue=0, + command=stanfordRoom_selection, + font=custom_font, + bg="#f4f4f4" +) +stanford_check.grid(row=1, column=0, padx=5, pady=5) + +include_top_check = tk.Checkbutton( + checkbox_frame, + text='Include Top in Mesh', + variable=include_top, + onvalue=1, offvalue=0, + font=custom_font, + bg="#f4f4f4" +) +include_top_check.grid(row=2, column=0, padx=5, pady=5) + +shift_image_check = tk.Checkbutton( + checkbox_frame, + text='Shift Input Image', + variable=shift_image, + onvalue=1, offvalue=0, + command=shift_image_selection, + font=custom_font, + bg="#f4f4f4" +) +shift_image_check.grid(row=3, column=0, padx=5, pady=5) + +# Bind actions +select_button.bind('<Button-1>', select_Image) +run_button.bind('<Button-1>', run_Image) + +# Start the window loop +window.mainloop() diff --git a/setup/setup_part1.sh b/setup/setup_part1.sh new file mode 100644 index 0000000000000000000000000000000000000000..d5bb2dcf6c5ae59d585dbccedb4c08a2fcf14460 --- /dev/null +++ b/setup/setup_part1.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Initialize a flag to track if a restart is needed +restart_needed=false + +# Check for wget +if ! command_exists wget; then + echo "wget is not installed. Installing wget..." + sudo apt-get install wget -y +fi + +# Check for git +if ! command_exists git; then + echo "git is not installed. Installing git..." + sudo apt-get install git -y +fi + +# Install Docker if not already installed +if ! command_exists docker; then + echo "Docker is not installed. Installing Docker..." + # Install Docker + wget -qO- https://get.docker.com/ | sh + sudo usermod -aG docker $USER + echo "Docker installed successfully." + restart_needed=true +fi + +# Install WSL if not already installed +if ! command_exists wsl; then + echo "WSL is not installed. Installing WSL..." + wsl.exe --list --online + wsl.exe --install Ubuntu + echo "WSL installed successfully." + restart_needed=true +fi + +# Check if a restart is needed +if [ "$restart_needed" = true ]; then + echo "Creating a script to run setup_part2.sh after restart..." + echo "bash /path/to/setup_part2.sh" > /etc/rc.local + chmod +x /etc/rc.local + echo "Restarting the computer to apply changes..." + sudo shutdown -r now + exit 1 +fi + +# If no restart is needed, proceed to part 2 +./setup_part2.sh diff --git a/setup/setup_part2.sh b/setup/setup_part2.sh new file mode 100644 index 0000000000000000000000000000000000000000..13976eca89076129de45a5eef9fd2e50be38b968 --- /dev/null +++ b/setup/setup_part2.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Remove the entry from /etc/rc.local to ensure it runs only once +if grep -q "bash /path/to/setup_part2.sh" /etc/rc.local; then + sed -i '/bash \/path\/to\/setup_part2.sh/d' /etc/rc.local +fi + +# Install Anaconda in WSL if not already installed +if ! wsl conda --version >/dev/null 2>&1; then + echo "Installing Anaconda in WSL..." + wsl sudo apt update + wsl sudo apt upgrade -y + wsl wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh + wsl bash Anaconda3-2022.05-Linux-x86_64.sh -b + wsl ~/anaconda3/bin/conda init + echo "Anaconda installed successfully in WSL." +fi + +# Install Anaconda in cmd if not already installed +if ! command_exists conda; then + echo "Installing Anaconda in cmd..." + wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Windows-x86_64.exe -O Anaconda3-2022.05-Windows-x86_64.exe + start /wait "" Anaconda3-2022.05-Windows-x86_64.exe /InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\Anaconda3 + %UserProfile%\Anaconda3\Scripts\conda.exe init + echo "Anaconda installed successfully in cmd." +fi + +# Update submodules +git submodule update --init --recursive + +# Set up DBAT environment +cd Dynamic-Backward-Attention-Transformer +conda env create -f environment.yml + +# Download pre-trained checkpoints +mkdir -p checkpoints/dpglt_mode95/accuracy checkpoints/swin_pretrain +# Add commands to download the checkpoints here + +# Set up blenderFlip.py environment +cd ../scripts +conda env create -f unity_conda_env.yml + +# Set up edgenet360 environment +cd ../edgenet-360 +wsl bash -c "cd /mnt/$(pwd | sed 's/\/mnt\///'); conda env create -f tf2_new_env.yml" +# Add commands to download the weights here + +# Set up 360monodepth Docker container +cd ../360monodepth +docker build -t 360monodepth . +docker run -it --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=0 360monodepth sh -c "cd /monodepth/code/python/src; python3 main.py --expname test_experiment --blending_method all --grid_size 8x7" + +# Configure paths +cp ../scripts/config.example.ini ../scripts/config.ini +# Add commands to edit config.ini here + +echo "Setup completed successfully!"