Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	setup.cfg
  • Loading branch information
kamikaze committed Jul 20, 2023
2 parents f239ddd + 0dabfbf commit 1cded67
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 3,696 deletions.
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[metadata]
name = dataset-image-annotator
version = 0.0.25
version = 0.0.26
description = Image annotation tool
author = Oleg Korsak
author_email = kamikaze.is.waiting.you@gmail.com
Expand Down Expand Up @@ -39,7 +39,7 @@ install_requires =
# The usage of test_requires is discouraged, see `Dependency Management` docs
# tests_require = pytest; pytest-cov
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
python_requires = >=3.10
python_requires = >=3.11

[options.packages.find]
where = src
Expand All @@ -66,7 +66,6 @@ web =
passlib[argon2]==1.7.4
PyJWT==2.7.0
python-dateutil==2.8.2
opencv-python==4.8.0.74
python3-commons==0.0.25
SQLAlchemy==1.4.46
uvicorn[standard]==0.23.1
Expand Down
39 changes: 0 additions & 39 deletions src/dataset_image_annotator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from typing import Sequence, Mapping

import cv2
import numpy as np
import rawpy
from PySide6.QtCore import QFile, QIODevice, QDir, QFileInfo, QModelIndex, Qt, QStringListModel
Expand Down Expand Up @@ -87,46 +86,8 @@ def get_raw_thumbnail(path: Path):
return thumb


def anonymize_image(image):
# Convert the image to grayscale
decoded_image = cv2.imdecode(np.frombuffer(image.data, np.uint8), -1)
gray = cv2.cvtColor(decoded_image, cv2.COLOR_BGR2GRAY)

# Load the cascade classifier for detecting cars
cascades = (
str(Path(Path(__file__).parent, 'cars.xml')),
str(Path(cv2.data.haarcascades, 'haarcascade_russian_plate_number.xml'))
)

for cascade in cascades:
car_cascade = cv2.CascadeClassifier(cascade)

# Detect cars in the image
cars = car_cascade.detectMultiScale(gray, 1.1, 1)

# Iterate over the detected cars
for (x, y, w, h) in cars:
# Blur the license plate
decoded_image[y + h - 20:y + h, x:x + w] = cv2.GaussianBlur(
decoded_image[y + h - 20:y + h, x:x + w], (23, 23), 30)

# Load the cascade classifier for detecting faces
face_cascade = cv2.CascadeClassifier(str(Path(cv2.data.haarcascades, 'haarcascade_frontalface_default.xml')))

# Detect faces in the image
faces = face_cascade.detectMultiScale(gray, 1.3, 5)

# Iterate over the detected faces
for (x, y, w, h) in faces:
# Blur the face
decoded_image[y:y + h, x:x + w] = cv2.GaussianBlur(decoded_image[y:y + h, x:x + w], (23, 23), 30)

return cv2.imencode('.jpg', decoded_image)[1].tobytes()


def generate_thumbnail(thumbnail_dir_path: Path, path: Path) -> QPixmap:
thumbnail = get_raw_thumbnail(path)
thumbnail = anonymize_image(thumbnail)

thumb_pixmap = QPixmap()
thumb_pixmap.loadFromData(thumbnail)
Expand Down
Loading

0 comments on commit 1cded67

Please sign in to comment.