Skip to content

Commit

Permalink
Fix some open bugs (tfaehse#58)
Browse files Browse the repository at this point in the history
- Add missing dependencies
- Replace all uses of os.path with pathlib
  • Loading branch information
tfaehse authored Dec 29, 2022
1 parent b7e78c4 commit ab39a9c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
14 changes: 8 additions & 6 deletions dashcamcleaner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
from glob import glob
from pathlib import Path

from PySide6.QtCore import QSettings
from PySide6.QtWidgets import (
Expand All @@ -19,8 +20,8 @@ def __init__(self):
Constructor
"""
self.receive_attempts = 0
save_path = os.path.join(os.path.dirname(__file__), "gui.ini")
self.settings = QSettings(save_path, QSettings.IniFormat)
save_path = Path(__file__).parent / "gui.ini"
self.settings = QSettings(str(save_path), QSettings.IniFormat)
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
Expand All @@ -35,10 +36,11 @@ def __init__(self):

def load_weights_options(self):
self.ui.combo_box_weights.clear()
source_folder = os.path.join(os.path.dirname(__file__))
for net_path in glob(source_folder + "/weights/*.pt"):
clean_name = os.path.splitext(os.path.basename(net_path))[0]
self.ui.combo_box_weights.addItem(clean_name)
source_folder = Path(__file__).parent / "weights"
available_weights_files = list(source_folder.rglob("*.pt"))
assert len(available_weights_files) > 0, "There has to be at least one .pt file in dashcamcleaner/weights"
for net_path in available_weights_files:
self.ui.combo_box_weights.addItem(net_path.stem)

def setup_blurrer(self):
"""
Expand Down
11 changes: 4 additions & 7 deletions dashcamcleaner/src/blurrer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from pathlib import Path
from shutil import which
from typing import Dict, List, Union

Expand All @@ -25,11 +26,7 @@ def __init__(self: 'VideoBlurrer', weights_name: str, parameters: Dict[str, Unio
"""
self.parameters = parameters
self.detections = []
weights_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"weights",
f"{weights_name}.pt".replace(".pt.pt", ".pt"),
)
weights_path = Path(__file__).resolve().parents[1] / "weights" / f"{weights_name}.pt".replace(".pt.pt", ".pt")
self.detector = setup_detector(weights_path)
print("Worker created")

Expand Down Expand Up @@ -166,8 +163,8 @@ def blur_video(self):
"""
# gather inputs from self.parameters
input_path = self.parameters["input_path"]
_temp_path, _temp_ext = os.path.splitext(self.parameters['output_path'])
temp_output = f"{_temp_path}_copy{_temp_ext}"
output_file = Path(self.parameters["output_path"])
temp_output = output_file.parent / f"{output_file.stem}_copy.{output_file.suffix}"
output_path = self.parameters["output_path"]
threshold = self.parameters["threshold"]
quality = self.parameters["quality"]
Expand Down
4 changes: 3 additions & 1 deletion dashcamcleaner/src/qt_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from pathlib import Path
from shutil import which
from timeit import default_timer as timer

Expand Down Expand Up @@ -37,7 +38,8 @@ def run(self):

# gather inputs from self.parameters
input_path = self.parameters["input_path"]
temp_output = f"{os.path.splitext(self.parameters['output_path'])[0]}_copy{os.path.splitext(self.parameters['output_path'])[1]}"
output_file = Path(self.parameters["output_path"])
temp_output = output_file.parent / f"{output_file.stem}_copy.{output_file.suffix}"
output_path = self.parameters["output_path"]
threshold = self.parameters["threshold"]
quality = self.parameters["quality"]
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
imageio>=2.9.0
imageio-ffmpeg>=0.4.5
ipython>=8.4.0
matplotlib>=3.2.2
more_itertools>=8.7.0
numpy>=1.18.5
opencv-python>=4.1.2
pandas>=1.2.3
Pillow
psutil>=5.9.1
pyside6>=6.2.2.1
PyYAML>=5.3.1
requests>=2.25.1
Expand Down
2 changes: 2 additions & 0 deletions requirements_gpu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
--find-links https://download.pytorch.org/whl/torch_stable.html
imageio>=2.9.0
imageio-ffmpeg>=0.4.5
ipython>=8.4.0
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
pandas>=1.2.3
Pillow
psutil>=5.9.1
pyside6>=6.2.2.1
PyYAML>=5.3.1
requests>=2.25.1
Expand Down

0 comments on commit ab39a9c

Please sign in to comment.