generated from Hazel/python-project
Compare commits
3 Commits
208f818e18
...
bb6eafbc74
Author | SHA1 | Date | |
---|---|---|---|
bb6eafbc74 | |||
d7cf61ee2d | |||
3d9ecea560 |
@ -1,7 +1,7 @@
|
||||
from .detect_humans import detect_humans
|
||||
from .get_bounding_boxes import select_bounding_boxes
|
||||
|
||||
|
||||
def cli():
|
||||
print(f"Running secure_pixelation")
|
||||
|
||||
detect_humans("assets/human_detection/humans.png")
|
||||
select_bounding_boxes("assets/human_detection/test.png")
|
||||
|
39
secure_pixelation/data_classes.py
Normal file
39
secure_pixelation/data_classes.py
Normal file
@ -0,0 +1,39 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Union
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
class RawImage:
|
||||
def __init__(self, file: Union[Path, str]):
|
||||
self.file = Path(file)
|
||||
self.name = self.file.name
|
||||
|
||||
self.meta_file = self._get_path("boxes.json")
|
||||
self.meta_data = self.read_meta()
|
||||
self.image = self.get_image()
|
||||
|
||||
def _get_path(self, ending: str, original_suffix: bool = False) -> Path:
|
||||
if original_suffix:
|
||||
return self.file.with_name(self.file.stem + "_" + ending + self.file.suffix)
|
||||
else:
|
||||
return self.file.with_name(self.file.stem + "_" + ending)
|
||||
|
||||
def read_meta(self) -> dict:
|
||||
if not self.meta_file.exists():
|
||||
return {}
|
||||
|
||||
with self.meta_file.open("r") as f:
|
||||
self.meta_data = json.load(f)
|
||||
return self.meta_data
|
||||
|
||||
def write_meta(self):
|
||||
with self.meta_file.open("w") as f:
|
||||
json.dump(self.meta_data, f)
|
||||
|
||||
def get_image(self) -> np.ndarray:
|
||||
return cv2.imread(str(self.file))
|
@ -1 +1,21 @@
|
||||
# https://learnopencv.com/how-to-select-a-bounding-box-roi-in-opencv-cpp-python/
|
||||
from __future__ import annotations
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from .data_classes import RawImage
|
||||
|
||||
|
||||
# https://learnopencv.com/how-to-select-a-bounding-box-roi-in-opencv-cpp-python/
|
||||
|
||||
|
||||
def select_bounding_boxes(to_detect: str):
|
||||
raw_image = RawImage(to_detect)
|
||||
|
||||
bounding_boxes = cv2.selectROIs(
|
||||
windowName=raw_image.name,
|
||||
img=raw_image.image,
|
||||
fromCenter=False
|
||||
)
|
||||
|
||||
print(bounding_boxes)
|
||||
|
Loading…
x
Reference in New Issue
Block a user