homa 0.26__tar.gz → 2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of homa might be problematic. Click here for more details.
- homa-2.1/PKG-INFO +15 -0
- homa-2.1/README.md +5 -0
- homa-2.1/homa/__init__.py +2 -0
- homa-2.1/homa/datasets.py +71 -0
- homa-2.1/homa.egg-info/PKG-INFO +15 -0
- homa-2.1/homa.egg-info/SOURCES.txt +10 -0
- homa-2.1/homa.egg-info/requires.txt +2 -0
- homa-2.1/homa.egg-info/top_level.txt +1 -0
- {homa-0.26 → homa-2.1}/setup.py +1 -4
- homa-0.26/PKG-INFO +0 -129
- homa-0.26/README.md +0 -121
- homa-0.26/homa/__init__.py +0 -11
- homa-0.26/homa/camera.py +0 -22
- homa-0.26/homa/classes/Collection.py +0 -11
- homa-0.26/homa/classes/Image.py +0 -19
- homa-0.26/homa/classes/Logger.py +0 -4
- homa-0.26/homa/classes/Repository.py +0 -35
- homa-0.26/homa/classes/Window.py +0 -119
- homa-0.26/homa/classes/__init__.py +0 -0
- homa-0.26/homa/constants.py +0 -0
- homa-0.26/homa/events.py +0 -40
- homa-0.26/homa/helpers/__init__.py +0 -0
- homa-0.26/homa/helpers/alias.py +0 -18
- homa-0.26/homa/helpers/environment.py +0 -9
- homa-0.26/homa/helpers/kernel.py +0 -15
- homa-0.26/homa/helpers/string.py +0 -16
- homa-0.26/homa/main.py +0 -32
- homa-0.26/homa/orientation.py +0 -38
- homa-0.26/homa/shapes.py +0 -50
- homa-0.26/homa/spaces.py +0 -39
- homa-0.26/homa.egg-info/PKG-INFO +0 -129
- homa-0.26/homa.egg-info/SOURCES.txt +0 -29
- homa-0.26/homa.egg-info/requires.txt +0 -2
- homa-0.26/homa.egg-info/top_level.txt +0 -2
- homa-0.26/tests/__init__.py +0 -0
- homa-0.26/tests/test_images.py +0 -27
- {homa-0.26 → homa-2.1}/LICENSE +0 -0
- {homa-0.26 → homa-2.1}/homa.egg-info/dependency_links.txt +0 -0
- {homa-0.26 → homa-2.1}/setup.cfg +0 -0
homa-2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: homa
|
|
3
|
+
Version: 2.1
|
|
4
|
+
Maintainer: Taha Shieenavaz
|
|
5
|
+
Maintainer-email: tahashieenavaz@gmail.com
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: torchvision
|
|
9
|
+
Requires-Dist: torch
|
|
10
|
+
|
|
11
|
+
# Homa
|
|
12
|
+
|
|
13
|
+
<div align="center">
|
|
14
|
+
<img src="art/homa.svg" width="500" />
|
|
15
|
+
</div>
|
homa-2.1/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from torchvision import transforms
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ImageDataset(torch.utils.data.Dataset):
|
|
6
|
+
def __init__(self, images, labels, transform=None):
|
|
7
|
+
self.images = images
|
|
8
|
+
self.labels = labels
|
|
9
|
+
self.transform = transform
|
|
10
|
+
|
|
11
|
+
def __len__(self):
|
|
12
|
+
return len(self.labels)
|
|
13
|
+
|
|
14
|
+
def __getitem__(self, idx):
|
|
15
|
+
image = self.images[idx]
|
|
16
|
+
label = self.labels[idx]
|
|
17
|
+
|
|
18
|
+
if self.transform:
|
|
19
|
+
image = self.transform(image)
|
|
20
|
+
|
|
21
|
+
return image, torch.tensor(label, dtype=torch.long)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AugmentedDataset(torch.utils.data.Dataset):
|
|
25
|
+
def __init__(self, dataset, transform_probability=0.6):
|
|
26
|
+
self.original_dataset = dataset
|
|
27
|
+
self.transform_probability = transform_probability
|
|
28
|
+
self.augmented_data = []
|
|
29
|
+
self.transformations = [
|
|
30
|
+
transforms.Compose(
|
|
31
|
+
[
|
|
32
|
+
transforms.RandomHorizontalFlip(),
|
|
33
|
+
transforms.ColorJitter(
|
|
34
|
+
brightness=0.5, contrast=0.5, saturation=0.5, hue=0.2
|
|
35
|
+
),
|
|
36
|
+
transforms.RandomRotation(45),
|
|
37
|
+
]
|
|
38
|
+
),
|
|
39
|
+
transforms.Compose(
|
|
40
|
+
[
|
|
41
|
+
transforms.RandomVerticalFlip(),
|
|
42
|
+
transforms.RandomAffine(
|
|
43
|
+
degrees=30, translate=(0.1, 0.1), scale=(0.8, 1.2)
|
|
44
|
+
),
|
|
45
|
+
transforms.GaussianBlur(kernel_size=(5, 5), sigma=(0.1, 2.0)),
|
|
46
|
+
]
|
|
47
|
+
),
|
|
48
|
+
transforms.Compose(
|
|
49
|
+
[
|
|
50
|
+
transforms.RandomResizedCrop(size=(224, 224), scale=(0.5, 1.0)),
|
|
51
|
+
transforms.RandomPerspective(distortion_scale=0.5, p=1.0),
|
|
52
|
+
transforms.RandomGrayscale(p=0.3),
|
|
53
|
+
]
|
|
54
|
+
),
|
|
55
|
+
]
|
|
56
|
+
self._augment_dataset()
|
|
57
|
+
|
|
58
|
+
def _augment_dataset(self):
|
|
59
|
+
for image, label in self.original_dataset:
|
|
60
|
+
if torch.rand(1).item() < self.transform_probability:
|
|
61
|
+
for transform in self.transformations:
|
|
62
|
+
augmented_image = transform(image)
|
|
63
|
+
self.augmented_data.append((augmented_image, label))
|
|
64
|
+
else:
|
|
65
|
+
self.augmented_data.append((image, label))
|
|
66
|
+
|
|
67
|
+
def __len__(self):
|
|
68
|
+
return len(self.augmented_data)
|
|
69
|
+
|
|
70
|
+
def __getitem__(self, idx):
|
|
71
|
+
return self.augmented_data[idx]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: homa
|
|
3
|
+
Version: 2.1
|
|
4
|
+
Maintainer: Taha Shieenavaz
|
|
5
|
+
Maintainer-email: tahashieenavaz@gmail.com
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: torchvision
|
|
9
|
+
Requires-Dist: torch
|
|
10
|
+
|
|
11
|
+
# Homa
|
|
12
|
+
|
|
13
|
+
<div align="center">
|
|
14
|
+
<img src="art/homa.svg" width="500" />
|
|
15
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
homa
|
{homa-0.26 → homa-2.1}/setup.py
RENAMED
|
@@ -18,10 +18,7 @@ setup(
|
|
|
18
18
|
maintainer_email="tahashieenavaz@gmail.com",
|
|
19
19
|
version=next_version,
|
|
20
20
|
packages=find_packages(),
|
|
21
|
-
install_requires=[
|
|
22
|
-
"opencv-python",
|
|
23
|
-
"numpy"
|
|
24
|
-
],
|
|
21
|
+
install_requires=["torchvision", "torch"],
|
|
25
22
|
long_description=description,
|
|
26
23
|
long_description_content_type="text/markdown",
|
|
27
24
|
)
|
homa-0.26/PKG-INFO
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: homa
|
|
3
|
-
Version: 0.26
|
|
4
|
-
Maintainer: Taha Shieenavaz
|
|
5
|
-
Maintainer-email: tahashieenavaz@gmail.com
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<img
|
|
11
|
-
src="https://raw.githubusercontent.com/tahashieenavaz/homa/main/art/homa.svg"
|
|
12
|
-
width=500
|
|
13
|
-
/>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
<hr />
|
|
17
|
-
|
|
18
|
-
Homa is an easy way to start learning Computer Vision with OpenCV.
|
|
19
|
-
|
|
20
|
-
## Loading Images
|
|
21
|
-
|
|
22
|
-
Images could be loaded with the `image` helper, that accepts the file name and a key for the repository.
|
|
23
|
-
|
|
24
|
-
```python
|
|
25
|
-
from homa import *
|
|
26
|
-
|
|
27
|
-
image("horse.jpg", "horse")
|
|
28
|
-
show("horse", wait=True)
|
|
29
|
-
|
|
30
|
-
# or alternatively
|
|
31
|
-
showWait("horse")
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
from homa import *
|
|
38
|
-
|
|
39
|
-
image("horse.jpg") # stored as "horse"
|
|
40
|
-
showWait("horse")
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Smoothing
|
|
44
|
-
|
|
45
|
-
### Blur
|
|
46
|
-
|
|
47
|
-
```python
|
|
48
|
-
from homa import *
|
|
49
|
-
|
|
50
|
-
image("horse.jpg")
|
|
51
|
-
|
|
52
|
-
blur("horse", 7) # rewrites "horse" key
|
|
53
|
-
blur("horse", (7, 19)) # rewrites "horse" key
|
|
54
|
-
blur("horse", 9, "blurred horse") # as a new key in the repository
|
|
55
|
-
|
|
56
|
-
showWait("blurred horse")
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Gaussian Blur
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from homa import *
|
|
63
|
-
|
|
64
|
-
image("horse.jpg")
|
|
65
|
-
|
|
66
|
-
gaussian("horse", 7) # rewrites "horse" key
|
|
67
|
-
gaussian("horse", (7, 19)) # rewrites "horse" key
|
|
68
|
-
gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
|
|
69
|
-
|
|
70
|
-
showWait("gaussian blurred horse")
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Median Blur
|
|
74
|
-
|
|
75
|
-
```python
|
|
76
|
-
from homa import *
|
|
77
|
-
|
|
78
|
-
image("horse.jpg")
|
|
79
|
-
|
|
80
|
-
median("horse", 7) # rewrites "horse" key
|
|
81
|
-
median("horse", (7, 19)) # rewrites "horse" key
|
|
82
|
-
median("horse", 9, "median blurred horse") # as a new key in the repository
|
|
83
|
-
|
|
84
|
-
showWait("median blurred horse")
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Stacking
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
from homa import *
|
|
91
|
-
|
|
92
|
-
image("horse.jpg")
|
|
93
|
-
blur("horse", 9, "blurred horse")
|
|
94
|
-
|
|
95
|
-
show(
|
|
96
|
-
vstack("horse", "blurred horse"),
|
|
97
|
-
window="Vstacked"
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
showWait(
|
|
101
|
-
hstack("horse", "blurred horse"),
|
|
102
|
-
window="Hstacked"
|
|
103
|
-
)
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Camera
|
|
107
|
-
|
|
108
|
-
Camera frames could be access from the repository with a key of `camera`.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
from homa import *
|
|
112
|
-
|
|
113
|
-
for _ in camera():
|
|
114
|
-
show("camera")
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
You can simply combine camera frames with the supported effects.
|
|
118
|
-
|
|
119
|
-
```python
|
|
120
|
-
from homa import *
|
|
121
|
-
|
|
122
|
-
for _ in camera():
|
|
123
|
-
blur("camera", 13, "blurred camera")
|
|
124
|
-
|
|
125
|
-
show(
|
|
126
|
-
vstack("camera", "blurred camera"),
|
|
127
|
-
window="Camera Effect"
|
|
128
|
-
)
|
|
129
|
-
```
|
homa-0.26/README.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img
|
|
3
|
-
src="https://raw.githubusercontent.com/tahashieenavaz/homa/main/art/homa.svg"
|
|
4
|
-
width=500
|
|
5
|
-
/>
|
|
6
|
-
</p>
|
|
7
|
-
|
|
8
|
-
<hr />
|
|
9
|
-
|
|
10
|
-
Homa is an easy way to start learning Computer Vision with OpenCV.
|
|
11
|
-
|
|
12
|
-
## Loading Images
|
|
13
|
-
|
|
14
|
-
Images could be loaded with the `image` helper, that accepts the file name and a key for the repository.
|
|
15
|
-
|
|
16
|
-
```python
|
|
17
|
-
from homa import *
|
|
18
|
-
|
|
19
|
-
image("horse.jpg", "horse")
|
|
20
|
-
show("horse", wait=True)
|
|
21
|
-
|
|
22
|
-
# or alternatively
|
|
23
|
-
showWait("horse")
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
from homa import *
|
|
30
|
-
|
|
31
|
-
image("horse.jpg") # stored as "horse"
|
|
32
|
-
showWait("horse")
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Smoothing
|
|
36
|
-
|
|
37
|
-
### Blur
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
from homa import *
|
|
41
|
-
|
|
42
|
-
image("horse.jpg")
|
|
43
|
-
|
|
44
|
-
blur("horse", 7) # rewrites "horse" key
|
|
45
|
-
blur("horse", (7, 19)) # rewrites "horse" key
|
|
46
|
-
blur("horse", 9, "blurred horse") # as a new key in the repository
|
|
47
|
-
|
|
48
|
-
showWait("blurred horse")
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Gaussian Blur
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
from homa import *
|
|
55
|
-
|
|
56
|
-
image("horse.jpg")
|
|
57
|
-
|
|
58
|
-
gaussian("horse", 7) # rewrites "horse" key
|
|
59
|
-
gaussian("horse", (7, 19)) # rewrites "horse" key
|
|
60
|
-
gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
|
|
61
|
-
|
|
62
|
-
showWait("gaussian blurred horse")
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Median Blur
|
|
66
|
-
|
|
67
|
-
```python
|
|
68
|
-
from homa import *
|
|
69
|
-
|
|
70
|
-
image("horse.jpg")
|
|
71
|
-
|
|
72
|
-
median("horse", 7) # rewrites "horse" key
|
|
73
|
-
median("horse", (7, 19)) # rewrites "horse" key
|
|
74
|
-
median("horse", 9, "median blurred horse") # as a new key in the repository
|
|
75
|
-
|
|
76
|
-
showWait("median blurred horse")
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Stacking
|
|
80
|
-
|
|
81
|
-
```python
|
|
82
|
-
from homa import *
|
|
83
|
-
|
|
84
|
-
image("horse.jpg")
|
|
85
|
-
blur("horse", 9, "blurred horse")
|
|
86
|
-
|
|
87
|
-
show(
|
|
88
|
-
vstack("horse", "blurred horse"),
|
|
89
|
-
window="Vstacked"
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
showWait(
|
|
93
|
-
hstack("horse", "blurred horse"),
|
|
94
|
-
window="Hstacked"
|
|
95
|
-
)
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Camera
|
|
99
|
-
|
|
100
|
-
Camera frames could be access from the repository with a key of `camera`.
|
|
101
|
-
|
|
102
|
-
```python
|
|
103
|
-
from homa import *
|
|
104
|
-
|
|
105
|
-
for _ in camera():
|
|
106
|
-
show("camera")
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
You can simply combine camera frames with the supported effects.
|
|
110
|
-
|
|
111
|
-
```python
|
|
112
|
-
from homa import *
|
|
113
|
-
|
|
114
|
-
for _ in camera():
|
|
115
|
-
blur("camera", 13, "blurred camera")
|
|
116
|
-
|
|
117
|
-
show(
|
|
118
|
-
vstack("camera", "blurred camera"),
|
|
119
|
-
window="Camera Effect"
|
|
120
|
-
)
|
|
121
|
-
```
|
homa-0.26/homa/__init__.py
DELETED
homa-0.26/homa/camera.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import cv2
|
|
2
|
-
from typing import Iterator
|
|
3
|
-
from .classes.Repository import Repository
|
|
4
|
-
from .classes.Window import Window
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def camera(delay: int = 10, exit_on: str = "q") -> Iterator[int]:
|
|
8
|
-
cameraWindow = Window(640, 480)
|
|
9
|
-
|
|
10
|
-
pressed_key = None
|
|
11
|
-
capture = cv2.VideoCapture(0)
|
|
12
|
-
frame_number = 0
|
|
13
|
-
while pressed_key != ord(exit_on):
|
|
14
|
-
_, frame = capture.read()
|
|
15
|
-
cameraWindow.update(frame)
|
|
16
|
-
|
|
17
|
-
frame_number += 1
|
|
18
|
-
yield frame_number
|
|
19
|
-
|
|
20
|
-
pressed_key = cv2.waitKey(delay)
|
|
21
|
-
|
|
22
|
-
capture.release()
|
homa-0.26/homa/classes/Image.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
from .Window import Window
|
|
2
|
-
from ..helpers.string import randomLowercaseString
|
|
3
|
-
import cv2
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Image(Window):
|
|
7
|
-
def __init__(self, filename: str | Window):
|
|
8
|
-
if isinstance(filename, Window):
|
|
9
|
-
image = filename.getImage()
|
|
10
|
-
title = f"{filename.getTitle()} Cloned"
|
|
11
|
-
|
|
12
|
-
elif isinstance(filename, str):
|
|
13
|
-
image = cv2.imread(filename)
|
|
14
|
-
title = filename
|
|
15
|
-
|
|
16
|
-
super().__init__(
|
|
17
|
-
image=image,
|
|
18
|
-
title=title
|
|
19
|
-
)
|
homa-0.26/homa/classes/Logger.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
from ..helpers.environment import isColab
|
|
2
|
-
from ..helpers.string import randomLowercaseString
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class RepositoryWrapper:
|
|
6
|
-
def __init__(self):
|
|
7
|
-
self.directory = "./"
|
|
8
|
-
|
|
9
|
-
self.settings = {
|
|
10
|
-
"thickness": 2,
|
|
11
|
-
"color": (0, 0, 0),
|
|
12
|
-
"sigma": [0, 0]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if isColab():
|
|
16
|
-
from google.colab.patches import cv2_imshow as imshow
|
|
17
|
-
else:
|
|
18
|
-
from cv2 import imshow
|
|
19
|
-
|
|
20
|
-
def final_imshow(window, image):
|
|
21
|
-
if isColab():
|
|
22
|
-
imshow(image)
|
|
23
|
-
else:
|
|
24
|
-
imshow(window, image)
|
|
25
|
-
|
|
26
|
-
self.imshow = final_imshow
|
|
27
|
-
|
|
28
|
-
def addImageWithRandomKey(self, image):
|
|
29
|
-
self.addImage(randomLowercaseString(), image)
|
|
30
|
-
|
|
31
|
-
def addImage(self, key, image):
|
|
32
|
-
Repository.images[key] = image
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Repository = RepositoryWrapper()
|
homa-0.26/homa/classes/Window.py
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import numpy
|
|
2
|
-
import cv2
|
|
3
|
-
|
|
4
|
-
from ..helpers.kernel import createKernel
|
|
5
|
-
from ..helpers.string import randomLowercaseString
|
|
6
|
-
from ..helpers.environment import isNotColab
|
|
7
|
-
|
|
8
|
-
from ..classes.Repository import Repository
|
|
9
|
-
|
|
10
|
-
from ..events import createMouseCallback
|
|
11
|
-
|
|
12
|
-
from typing_extensions import Self
|
|
13
|
-
from typing import List
|
|
14
|
-
|
|
15
|
-
from ..shapes import color
|
|
16
|
-
from ..shapes import stroke
|
|
17
|
-
|
|
18
|
-
from ..main import setting
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Window:
|
|
22
|
-
def __init__(self, width: int = 300, height: int = 300, image=None, title: str | None = None, channels: int = 3, dtype="uint8") -> None:
|
|
23
|
-
if title is None:
|
|
24
|
-
title = randomLowercaseString(10)
|
|
25
|
-
|
|
26
|
-
if image is None:
|
|
27
|
-
image = numpy.zeros([height, width, channels], dtype=dtype)
|
|
28
|
-
|
|
29
|
-
self.__title = title
|
|
30
|
-
self.__image = image
|
|
31
|
-
self.__events = {}
|
|
32
|
-
|
|
33
|
-
def show(self):
|
|
34
|
-
if isNotColab():
|
|
35
|
-
cv2.namedWindow(self.__title)
|
|
36
|
-
cv2.setMouseCallback(
|
|
37
|
-
self.__title, createMouseCallback(self.__events))
|
|
38
|
-
|
|
39
|
-
Repository.imshow(self.__title, self.__image)
|
|
40
|
-
|
|
41
|
-
def title(self, newTitle: str) -> Self:
|
|
42
|
-
self.__title = newTitle
|
|
43
|
-
return self
|
|
44
|
-
|
|
45
|
-
def update(self, newImage) -> Self:
|
|
46
|
-
self.__image = newImage
|
|
47
|
-
self.refresh()
|
|
48
|
-
return self
|
|
49
|
-
|
|
50
|
-
def click(self, handler: callable) -> Self:
|
|
51
|
-
self.__events["click"] = (handler, self)
|
|
52
|
-
return self
|
|
53
|
-
|
|
54
|
-
def move(self, handler: callable) -> Self:
|
|
55
|
-
self.__events["mousemove"] = (handler, self)
|
|
56
|
-
return self
|
|
57
|
-
|
|
58
|
-
def white(self) -> Self:
|
|
59
|
-
self.__image = numpy.ones([
|
|
60
|
-
self.__image.shape[0],
|
|
61
|
-
self.__image.shape[1],
|
|
62
|
-
self.__image.shape[2]
|
|
63
|
-
]) * (2 ** 8 - 1)
|
|
64
|
-
return self
|
|
65
|
-
|
|
66
|
-
def blur(self, kernel: int | List[int] = (7, 7)) -> Self:
|
|
67
|
-
self.update(cv2.blur(
|
|
68
|
-
self.__image,
|
|
69
|
-
createKernel(kernel),
|
|
70
|
-
))
|
|
71
|
-
|
|
72
|
-
return self
|
|
73
|
-
|
|
74
|
-
def gaussian(self, kernel: int | List[int] = (7, 7)) -> Self:
|
|
75
|
-
self.update(cv2.GaussianBlur(
|
|
76
|
-
self.__image,
|
|
77
|
-
createKernel(kernel),
|
|
78
|
-
setting("sigma")[0],
|
|
79
|
-
setting("sigma")[1],
|
|
80
|
-
))
|
|
81
|
-
|
|
82
|
-
return self
|
|
83
|
-
|
|
84
|
-
def median(self, kernel: int) -> Self:
|
|
85
|
-
self.update(cv2.medianBlur(
|
|
86
|
-
self.__image, kernel
|
|
87
|
-
))
|
|
88
|
-
|
|
89
|
-
return self
|
|
90
|
-
|
|
91
|
-
def refresh(self):
|
|
92
|
-
Repository.imshow(self.__title, self.__image)
|
|
93
|
-
|
|
94
|
-
def circle(self, x: int, y: int, radius: int, circleColor: tuple | None = None, thickness: int | None = None):
|
|
95
|
-
if circleColor is not None:
|
|
96
|
-
color(*circleColor)
|
|
97
|
-
|
|
98
|
-
if thickness is not None:
|
|
99
|
-
stroke(thickness)
|
|
100
|
-
|
|
101
|
-
self.update(cv2.circle(
|
|
102
|
-
self.__image,
|
|
103
|
-
(x, y),
|
|
104
|
-
radius,
|
|
105
|
-
setting("color"),
|
|
106
|
-
setting("thickness")
|
|
107
|
-
))
|
|
108
|
-
|
|
109
|
-
def getImage(self):
|
|
110
|
-
return self.__image
|
|
111
|
-
|
|
112
|
-
def getTitle(self):
|
|
113
|
-
return self.__title
|
|
114
|
-
|
|
115
|
-
def __getattr__(self, key):
|
|
116
|
-
if key == "shape":
|
|
117
|
-
return self.__image.shape
|
|
118
|
-
|
|
119
|
-
return None
|
|
File without changes
|
homa-0.26/homa/constants.py
DELETED
|
File without changes
|
homa-0.26/homa/events.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import cv2
|
|
2
|
-
from inspect import signature
|
|
3
|
-
from .classes.Repository import Repository
|
|
4
|
-
|
|
5
|
-
event_map = {
|
|
6
|
-
"click": cv2.EVENT_LBUTTONDOWN,
|
|
7
|
-
"rclick": cv2.EVENT_RBUTTONDOWN,
|
|
8
|
-
"mclick": cv2.EVENT_MBUTTONDOWN,
|
|
9
|
-
"mouseup": cv2.EVENT_LBUTTONUP,
|
|
10
|
-
"rmouseup": cv2.EVENT_RBUTTONUP,
|
|
11
|
-
"dblclick": cv2.EVENT_LBUTTONDBLCLK,
|
|
12
|
-
"rdblclick": cv2.EVENT_RBUTTONDBLCLK,
|
|
13
|
-
"mousemove": cv2.EVENT_MOUSEMOVE
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def createMouseCallback(events: dict):
|
|
18
|
-
def innerMouseCallback(event, x, y, flags, param):
|
|
19
|
-
for e, values in events.items():
|
|
20
|
-
if event != event_map[e]:
|
|
21
|
-
continue
|
|
22
|
-
|
|
23
|
-
handler, context = values
|
|
24
|
-
argumentCount = len(signature(handler).parameters)
|
|
25
|
-
if argumentCount == 2:
|
|
26
|
-
args = (x, y)
|
|
27
|
-
elif argumentCount == 3:
|
|
28
|
-
args = (x, y, context)
|
|
29
|
-
elif argumentCount == 4:
|
|
30
|
-
args = (x, y, context, flags)
|
|
31
|
-
elif argumentCount == 5:
|
|
32
|
-
args = (x, y, context, flags, param)
|
|
33
|
-
elif argumentCount == 1:
|
|
34
|
-
args = (context,)
|
|
35
|
-
elif args == 0:
|
|
36
|
-
args = tuple()
|
|
37
|
-
|
|
38
|
-
handler(*args)
|
|
39
|
-
|
|
40
|
-
return innerMouseCallback
|
|
File without changes
|
homa-0.26/homa/helpers/alias.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
from ..classes.Repository import Repository
|
|
2
|
-
from ..classes.Collection import Collection
|
|
3
|
-
from typing import List
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def repo(key: str | None = None, value: any = None) -> any:
|
|
7
|
-
if key is None and value is None:
|
|
8
|
-
return Repository.images
|
|
9
|
-
|
|
10
|
-
if key is not None and value is None:
|
|
11
|
-
return Repository.addImage(key, value)
|
|
12
|
-
|
|
13
|
-
Repository.addImage(key, value)
|
|
14
|
-
return True
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def collection(items: List[any]):
|
|
18
|
-
return Collection(items)
|
homa-0.26/homa/helpers/kernel.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from typing import Tuple
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def createKernel(value: int | Tuple[int, int]) -> Tuple[int, int]:
|
|
5
|
-
if isinstance(value, tuple):
|
|
6
|
-
x, y = value
|
|
7
|
-
|
|
8
|
-
x = x - 1 if x % 2 == 0 else x
|
|
9
|
-
y = y - 1 if y % 2 == 0 else y
|
|
10
|
-
|
|
11
|
-
return (x, y)
|
|
12
|
-
|
|
13
|
-
value = value - 1 if value % 2 == 0 else value
|
|
14
|
-
|
|
15
|
-
return (value, value)
|
homa-0.26/homa/helpers/string.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import numpy
|
|
2
|
-
import string
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def randomLowercaseString(length: int = 10):
|
|
6
|
-
return randomString(length, string.ascii_lowercase)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def randomUppercaseString(length: int = 10):
|
|
10
|
-
return randomString(length, string.ascii_uppercase)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def randomString(length: int = 10, letters: str = string.ascii_letters):
|
|
14
|
-
return "".join(
|
|
15
|
-
numpy.random.choice(list(letters), length)
|
|
16
|
-
)
|
homa-0.26/homa/main.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import cv2
|
|
2
|
-
from .classes.Repository import Repository
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def destroy(key: str | None = None) -> None:
|
|
6
|
-
if key is not None:
|
|
7
|
-
cv2.destroyWindow(key)
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
cv2.destroyAllWindows()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def show(*windows, **settings):
|
|
14
|
-
for window in windows:
|
|
15
|
-
window.show()
|
|
16
|
-
|
|
17
|
-
if settings["wait"] == True:
|
|
18
|
-
cv2.waitKey()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def showWait(*args, **kwargs):
|
|
22
|
-
kwargs["wait"] = True
|
|
23
|
-
show(*args, **kwargs)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def setting(key: str, value: any = None) -> any:
|
|
27
|
-
if value is not None:
|
|
28
|
-
Repository.settings[key] = value
|
|
29
|
-
return True
|
|
30
|
-
|
|
31
|
-
setting_value = Repository.settings[key]
|
|
32
|
-
return setting_value if setting_value else None
|
homa-0.26/homa/orientation.py
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
from .classes.Repository import Repository
|
|
2
|
-
from .helpers.alias import collection
|
|
3
|
-
import numpy
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def stack(*keys, **settings):
|
|
7
|
-
default_settings = {
|
|
8
|
-
"axis": 1,
|
|
9
|
-
"new_key": None
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
settings = {
|
|
13
|
-
**default_settings,
|
|
14
|
-
**settings
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if all(isinstance(item, str) for item in keys):
|
|
18
|
-
keys = collection(keys).map(lambda key: Repository.images[key])
|
|
19
|
-
|
|
20
|
-
stacked_image = numpy.concatenate(
|
|
21
|
-
keys,
|
|
22
|
-
axis=settings["axis"]
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
if settings["new_key"] is not None:
|
|
26
|
-
Repository.images[settings["new_key"]] = stacked_image
|
|
27
|
-
|
|
28
|
-
return stacked_image
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def vstack(*keys, **settings):
|
|
32
|
-
settings["axis"] = 1
|
|
33
|
-
return stack(*keys, **settings)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def hstack(*keys, **settings):
|
|
37
|
-
settings["axis"] = 0
|
|
38
|
-
return stack(*keys, **settings)
|
homa-0.26/homa/shapes.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import cv2
|
|
2
|
-
from .main import setting
|
|
3
|
-
from .helpers.alias import repo
|
|
4
|
-
from typing import Tuple
|
|
5
|
-
import numpy
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def stroke(value: int = 1):
|
|
9
|
-
setting("thickness", value)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def fill(*args):
|
|
13
|
-
setting("thickness", -1)
|
|
14
|
-
|
|
15
|
-
if len(args) == 3:
|
|
16
|
-
color(*args)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def randomColor() -> Tuple[int, int, int]:
|
|
20
|
-
r = numpy.random.randint(0, 255)
|
|
21
|
-
g = numpy.random.randint(0, 255)
|
|
22
|
-
b = numpy.random.randint(0, 255)
|
|
23
|
-
|
|
24
|
-
return (b, g, r)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def color(*args):
|
|
28
|
-
if len(args) == 1 and isinstance(args[0], str) and args[0] in ["random", "rand"]:
|
|
29
|
-
args = randomColor()
|
|
30
|
-
|
|
31
|
-
setting("color", args)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def circle(key: str, x: int, y: int, radius: int = 1):
|
|
35
|
-
cv2.circle(
|
|
36
|
-
repo(key),
|
|
37
|
-
(x, y),
|
|
38
|
-
radius,
|
|
39
|
-
setting("color"),
|
|
40
|
-
setting("thickness")
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def rect(key: str, x: int, y: int, width: int, height: int):
|
|
45
|
-
cv2.rectangle(
|
|
46
|
-
repo(key),
|
|
47
|
-
(x - width // 2, y - height // 2), (x + width // 2, y + height // 2),
|
|
48
|
-
thickness=setting("thickness"),
|
|
49
|
-
color=setting("color")
|
|
50
|
-
)
|
homa-0.26/homa/spaces.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
from typing import Tuple
|
|
2
|
-
from .helpers.alias import repo
|
|
3
|
-
import cv2
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def hsv(key: str):
|
|
7
|
-
image = repo(key)
|
|
8
|
-
cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
9
|
-
|
|
10
|
-
h = image[:, :, 0]
|
|
11
|
-
s = image[:, :, 1]
|
|
12
|
-
v = image[:, :, 2]
|
|
13
|
-
|
|
14
|
-
return (h, s, v)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def bgr(key: str) -> Tuple[int, int, int]:
|
|
18
|
-
return rgb(key, bgr_flag=True)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def rgb(key: str, bgr_flag: bool = False) -> Tuple[int, int, int]:
|
|
22
|
-
image = repo(key)
|
|
23
|
-
|
|
24
|
-
if image.shape[2] == 3:
|
|
25
|
-
# found three channels in stored image
|
|
26
|
-
# meaning that it has been loaded as a color image
|
|
27
|
-
|
|
28
|
-
b = image[:, :, 0]
|
|
29
|
-
g = image[:, :, 0]
|
|
30
|
-
r = image[:, :, 0]
|
|
31
|
-
|
|
32
|
-
if bgr_flag:
|
|
33
|
-
return (b, g, r)
|
|
34
|
-
|
|
35
|
-
return (r, g, b)
|
|
36
|
-
|
|
37
|
-
if image.shape[2] == 1:
|
|
38
|
-
gray = image[:, :, 0]
|
|
39
|
-
return (gray, gray, gray)
|
homa-0.26/homa.egg-info/PKG-INFO
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: homa
|
|
3
|
-
Version: 0.26
|
|
4
|
-
Maintainer: Taha Shieenavaz
|
|
5
|
-
Maintainer-email: tahashieenavaz@gmail.com
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<img
|
|
11
|
-
src="https://raw.githubusercontent.com/tahashieenavaz/homa/main/art/homa.svg"
|
|
12
|
-
width=500
|
|
13
|
-
/>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
<hr />
|
|
17
|
-
|
|
18
|
-
Homa is an easy way to start learning Computer Vision with OpenCV.
|
|
19
|
-
|
|
20
|
-
## Loading Images
|
|
21
|
-
|
|
22
|
-
Images could be loaded with the `image` helper, that accepts the file name and a key for the repository.
|
|
23
|
-
|
|
24
|
-
```python
|
|
25
|
-
from homa import *
|
|
26
|
-
|
|
27
|
-
image("horse.jpg", "horse")
|
|
28
|
-
show("horse", wait=True)
|
|
29
|
-
|
|
30
|
-
# or alternatively
|
|
31
|
-
showWait("horse")
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
from homa import *
|
|
38
|
-
|
|
39
|
-
image("horse.jpg") # stored as "horse"
|
|
40
|
-
showWait("horse")
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Smoothing
|
|
44
|
-
|
|
45
|
-
### Blur
|
|
46
|
-
|
|
47
|
-
```python
|
|
48
|
-
from homa import *
|
|
49
|
-
|
|
50
|
-
image("horse.jpg")
|
|
51
|
-
|
|
52
|
-
blur("horse", 7) # rewrites "horse" key
|
|
53
|
-
blur("horse", (7, 19)) # rewrites "horse" key
|
|
54
|
-
blur("horse", 9, "blurred horse") # as a new key in the repository
|
|
55
|
-
|
|
56
|
-
showWait("blurred horse")
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Gaussian Blur
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from homa import *
|
|
63
|
-
|
|
64
|
-
image("horse.jpg")
|
|
65
|
-
|
|
66
|
-
gaussian("horse", 7) # rewrites "horse" key
|
|
67
|
-
gaussian("horse", (7, 19)) # rewrites "horse" key
|
|
68
|
-
gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
|
|
69
|
-
|
|
70
|
-
showWait("gaussian blurred horse")
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Median Blur
|
|
74
|
-
|
|
75
|
-
```python
|
|
76
|
-
from homa import *
|
|
77
|
-
|
|
78
|
-
image("horse.jpg")
|
|
79
|
-
|
|
80
|
-
median("horse", 7) # rewrites "horse" key
|
|
81
|
-
median("horse", (7, 19)) # rewrites "horse" key
|
|
82
|
-
median("horse", 9, "median blurred horse") # as a new key in the repository
|
|
83
|
-
|
|
84
|
-
showWait("median blurred horse")
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Stacking
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
from homa import *
|
|
91
|
-
|
|
92
|
-
image("horse.jpg")
|
|
93
|
-
blur("horse", 9, "blurred horse")
|
|
94
|
-
|
|
95
|
-
show(
|
|
96
|
-
vstack("horse", "blurred horse"),
|
|
97
|
-
window="Vstacked"
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
showWait(
|
|
101
|
-
hstack("horse", "blurred horse"),
|
|
102
|
-
window="Hstacked"
|
|
103
|
-
)
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Camera
|
|
107
|
-
|
|
108
|
-
Camera frames could be access from the repository with a key of `camera`.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
from homa import *
|
|
112
|
-
|
|
113
|
-
for _ in camera():
|
|
114
|
-
show("camera")
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
You can simply combine camera frames with the supported effects.
|
|
118
|
-
|
|
119
|
-
```python
|
|
120
|
-
from homa import *
|
|
121
|
-
|
|
122
|
-
for _ in camera():
|
|
123
|
-
blur("camera", 13, "blurred camera")
|
|
124
|
-
|
|
125
|
-
show(
|
|
126
|
-
vstack("camera", "blurred camera"),
|
|
127
|
-
window="Camera Effect"
|
|
128
|
-
)
|
|
129
|
-
```
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
README.md
|
|
3
|
-
setup.py
|
|
4
|
-
homa/__init__.py
|
|
5
|
-
homa/camera.py
|
|
6
|
-
homa/constants.py
|
|
7
|
-
homa/events.py
|
|
8
|
-
homa/main.py
|
|
9
|
-
homa/orientation.py
|
|
10
|
-
homa/shapes.py
|
|
11
|
-
homa/spaces.py
|
|
12
|
-
homa.egg-info/PKG-INFO
|
|
13
|
-
homa.egg-info/SOURCES.txt
|
|
14
|
-
homa.egg-info/dependency_links.txt
|
|
15
|
-
homa.egg-info/requires.txt
|
|
16
|
-
homa.egg-info/top_level.txt
|
|
17
|
-
homa/classes/Collection.py
|
|
18
|
-
homa/classes/Image.py
|
|
19
|
-
homa/classes/Logger.py
|
|
20
|
-
homa/classes/Repository.py
|
|
21
|
-
homa/classes/Window.py
|
|
22
|
-
homa/classes/__init__.py
|
|
23
|
-
homa/helpers/__init__.py
|
|
24
|
-
homa/helpers/alias.py
|
|
25
|
-
homa/helpers/environment.py
|
|
26
|
-
homa/helpers/kernel.py
|
|
27
|
-
homa/helpers/string.py
|
|
28
|
-
tests/__init__.py
|
|
29
|
-
tests/test_images.py
|
homa-0.26/tests/__init__.py
DELETED
|
File without changes
|
homa-0.26/tests/test_images.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from homa import *
|
|
2
|
-
|
|
3
|
-
import unittest
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class LoadingImagesTest(unittest.TestCase):
|
|
7
|
-
def setUp(self):
|
|
8
|
-
pass
|
|
9
|
-
|
|
10
|
-
def test_can_load_images_into_repository(self):
|
|
11
|
-
image("italy.jpg", "italy")
|
|
12
|
-
self.assertIn("italy", repo())
|
|
13
|
-
|
|
14
|
-
def test_it_does_not_load_extra_images(self):
|
|
15
|
-
image("italy.jpg", "italy")
|
|
16
|
-
self.assertEqual(len(repo()), 1)
|
|
17
|
-
|
|
18
|
-
image("italy.jpg", "italy again")
|
|
19
|
-
self.assertEqual(len(repo()), 2)
|
|
20
|
-
|
|
21
|
-
def test_it_can_load_images_as_black_and_white(self):
|
|
22
|
-
image("italy.jpg", "italy", color=False)
|
|
23
|
-
self.assertEqual(len(repo("italy").shape), 2)
|
|
24
|
-
|
|
25
|
-
def test_it_can_load_images_as_colorful(self):
|
|
26
|
-
image("italy.jpg", "italy", color=True)
|
|
27
|
-
self.assertEqual(len(repo("italy").shape), 3)
|
{homa-0.26 → homa-2.1}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
{homa-0.26 → homa-2.1}/setup.cfg
RENAMED
|
File without changes
|