homa 0.21__py3-none-any.whl → 0.22__py3-none-any.whl

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/__init__.py CHANGED
@@ -1 +1,4 @@
1
1
  from .main import *
2
+ from .filters import *
3
+ from .camera import *
4
+ from .orientation import *
homa/camera.py ADDED
@@ -0,0 +1,21 @@
1
+ import cv2
2
+ from .classes.Repository import Repository
3
+
4
+
5
+ def camera(delay=10):
6
+ capture = cv2.VideoCapture(0)
7
+
8
+ pressed_key = None
9
+
10
+ frame_number = 0
11
+
12
+ while pressed_key != ord("q"):
13
+ frame_number += 1
14
+ _, frame = capture.read()
15
+
16
+ Repository.images["camera"] = frame
17
+
18
+ yield frame_number
19
+ pressed_key = cv2.waitKey(delay)
20
+
21
+ capture.release()
homa/filters.py ADDED
@@ -0,0 +1,34 @@
1
+ from typing import List
2
+ from .classes.Repository import Repository
3
+ from .helpers import create_kernel
4
+ import cv2
5
+
6
+
7
+ def blur(key: str, kernel: int | List[int] = (7, 7), new_key: str | None = None):
8
+ if new_key is None:
9
+ new_key = key
10
+
11
+ Repository.images[new_key] = cv2.blur(
12
+ Repository.images[key],
13
+ create_kernel(kernel)
14
+ )
15
+
16
+
17
+ def sigma(x: float = 0, y: float = 0):
18
+ Repository.sigmaX = x
19
+ Repository.sigmaY = y
20
+
21
+
22
+ def gaussian(key: str, kernel: None | List[int] = None, new_key: str | None = None):
23
+ if new_key is None:
24
+ new_key = key
25
+
26
+ if isinstance(kernel, int):
27
+ kernel = (kernel, kernel)
28
+
29
+ Repository.images[new_key] = cv2.GaussianBlur(
30
+ Repository.images[key],
31
+ kernel,
32
+ sigmaX=Repository.sigmaX,
33
+ sigmaY=Repository.sigmaY
34
+ )
homa/helpers.py CHANGED
@@ -14,3 +14,17 @@ def collection(items: List[any]):
14
14
 
15
15
  def danger(message: str) -> None:
16
16
  Logger.danger(message)
17
+
18
+
19
+ def create_kernel(value: int | tuple) -> tuple:
20
+ if isinstance(value, tuple):
21
+ x, y = value
22
+
23
+ x = x - 1 if x % 2 == 0 else x
24
+ y = y - 1 if y % 2 == 0 else y
25
+
26
+ return (x, y)
27
+
28
+ value = value - 1 if value % 2 == 0 else value
29
+
30
+ return (value, value)
homa/main.py CHANGED
@@ -1,10 +1,5 @@
1
1
  import cv2
2
- import numpy
3
- from typing import List
4
- from .helpers import collection
5
2
  from .helpers import danger
6
- from .helpers import is_colab
7
-
8
3
  from .classes.Repository import Repository
9
4
 
10
5
 
@@ -19,24 +14,33 @@ def write(key: str, filename: str) -> None:
19
14
  )
20
15
 
21
16
 
22
- def save(key: str, filename: str) -> None:
23
- write(key, filename)
17
+ def save(*args, **kwargs) -> None:
18
+ write(args, kwargs)
24
19
 
25
20
 
26
21
  def image(filename: str, key: str | None = None, color: bool = True) -> None:
27
22
  # TODO: add no extension in the file
28
23
  if key is None:
29
- key = filename
24
+ key = filename.split(".")[0]
30
25
 
31
26
  Repository.images[key] = cv2.imread(filename, int(color))
32
27
  return Repository.images[key]
33
28
 
34
29
 
35
- def show(key: any = None) -> None:
30
+ def wait(delay=0):
31
+ cv2.waitKey(delay)
32
+
33
+
34
+ def showWait(*args, **kwargs):
35
+ kwargs["wait"] = True
36
+ show(*args, **kwargs)
37
+
38
+
39
+ def show(key: any = None, wait: bool = False, window: str = "Homa Window") -> None:
36
40
  # TODO: add functionality to distinguish between camera and images
37
41
 
38
42
  if key is not None and not isinstance(key, str):
39
- Repository.imshow(f"Window #{Repository.get_counter()}", key)
43
+ Repository.imshow(window, key)
40
44
 
41
45
  elif key is None:
42
46
  for key, image in Repository.images.items():
@@ -48,62 +52,5 @@ def show(key: any = None) -> None:
48
52
  else:
49
53
  danger(f"No image found with key {key}")
50
54
 
51
- cv2.waitKey(0)
52
-
53
-
54
- def camera():
55
- capture = cv2.VideoCapture()
56
- _, frame = capture.read()
57
- Repository.camera_frame = frame
58
-
59
-
60
- def stack(keys: List[str], new_key: str, axis: int):
61
- Repository.images[new_key] = numpy.concatenate(
62
- collection(keys).map(lambda key: Repository.images[key]),
63
- axis=axis
64
- )
65
-
66
-
67
- def vstack(keys: List[str], new_key: str) -> None:
68
- stack(keys, new_key, 1)
69
-
70
-
71
- def hstack(keys: List[str] | str, new_key: str | None = None):
72
- if isinstance(keys, str) and new_key is None:
73
- hstack([keys], keys)
74
- return
75
-
76
- stack(keys, new_key, 0)
77
-
78
-
79
- def blur(key: str, kernel: int | List[int] = (7, 7), new_key: str | None = None):
80
- if new_key is None:
81
- new_key = key
82
-
83
- if isinstance(kernel, int):
84
- kernel = (kernel, kernel)
85
-
86
- Repository.images[new_key] = cv2.blur(
87
- Repository.images[key],
88
- kernel
89
- )
90
-
91
-
92
- def sigma(x: float = 0, y: float = 0):
93
- Repository.sigmaX = x
94
- Repository.sigmaY = y
95
-
96
-
97
- def gaussian(key: str, kernel: None | List[int] = None, new_key: str | None = None):
98
- if new_key is None:
99
- new_key = key
100
-
101
- if isinstance(kernel, int):
102
- kernel = (kernel, kernel)
103
-
104
- Repository.images[new_key] = cv2.GaussianBlur(
105
- Repository.images[key],
106
- kernel,
107
- sigmaX=Repository.sigmaX,
108
- sigmaY=Repository.sigmaY
109
- )
55
+ if wait:
56
+ cv2.waitKey(0)
homa/orientation.py ADDED
@@ -0,0 +1,36 @@
1
+ from typing import List
2
+ from .classes.Repository import Repository
3
+ from .helpers import collection
4
+ import numpy
5
+
6
+
7
+ def stack(*keys, **settings):
8
+ default_settings = {
9
+ "axis": 1,
10
+ "new_key": None
11
+ }
12
+
13
+ settings = {
14
+ **default_settings,
15
+ **settings
16
+ }
17
+
18
+ stacked_image = numpy.concatenate(
19
+ collection(keys).map(lambda key: Repository.images[key]),
20
+ axis=settings["axis"]
21
+ )
22
+
23
+ if settings["new_key"] is not None:
24
+ Repository.images[settings["new_key"]] = stacked_image
25
+
26
+ return stacked_image
27
+
28
+
29
+ def vstack(*keys, **settings):
30
+ settings["axis"] = 1
31
+ return stack(*keys, **settings)
32
+
33
+
34
+ def hstack(*keys, **settings):
35
+ settings["axis"] = 0
36
+ return stack(*keys, **settings)
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.1
2
+ Name: homa
3
+ Version: 0.22
4
+ Maintainer: Taha Shieenavaz
5
+ Maintainer-email: tahashieenavaz@gmail.com
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: opencv-python
9
+ Requires-Dist: numpy
10
+
11
+ <p align="center">
12
+ <img
13
+ src="https://raw.githubusercontent.com/tahashieenavaz/homa/main/art/homa.svg"
14
+ width=500
15
+ />
16
+ </p>
17
+
18
+ <hr />
19
+
20
+ Homa is an easy way to start learning Computer Vision with OpenCV.
21
+
22
+ ## Loading Images
23
+
24
+ Images could be loaded with the `image` helper, that accepts the file name and a key for the repository.
25
+
26
+ ```python
27
+ from homa import *
28
+
29
+ image("horse.jpg", "horse")
30
+ ```
31
+
32
+ Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
33
+
34
+ ```python
35
+ from homa import *
36
+
37
+ image("horse.jpg") # stored as "horse"
38
+ ```
39
+
40
+ ## Smoothing
41
+
42
+ ### Blur
43
+
44
+ ```python
45
+ from homa import *
46
+
47
+ image("horse.jpg")
48
+
49
+ blur("horse", 7) # rewrites "horse" key
50
+ blur("horse", (7, 19)) # rewrites "horse" key
51
+ blur("horse", 9, "blurred horse") # as a new key in the repository
52
+ show("blurred horse")
53
+ ```
54
+
55
+ ### Gaussian Blur
56
+
57
+ ```python
58
+ from homa import *
59
+
60
+ image("horse.jpg")
61
+
62
+ gaussian("horse", 7) # rewrites "horse" key
63
+ gaussian("horse", (7, 19)) # rewrites "horse" key
64
+ gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
65
+ show("gaussian blurred horse")
66
+ ```
67
+
68
+ ## Stacking
69
+
70
+ ```python
71
+ from homa import *
72
+
73
+ image("horse.jpg")
74
+ blur("horse", 9, "blurred horse")
75
+
76
+ show(
77
+ vstack("horse", "blurred horse"),
78
+ window="Vstacked"
79
+ )
80
+
81
+ showWait(
82
+ hstack("horse", "blurred horse"),
83
+ window="Hstacked"
84
+ )
85
+ ```
86
+
87
+ ## Camera
88
+
89
+ Camera frames could be access from the repository with a key of `camera`.
90
+
91
+ ```python
92
+ from homa import *
93
+
94
+ for _ in camera():
95
+ show("camera")
96
+ ```
97
+
98
+ You can simply combine camera frames with the supported effects.
99
+
100
+ ```python
101
+ from homa import *
102
+
103
+ for _ in camera():
104
+ blur("camera", 13, "blurred camera")
105
+
106
+ show(
107
+ vstack("camera", "blurred camera"),
108
+ window="Camera Effect"
109
+ )
110
+ ```
@@ -0,0 +1,16 @@
1
+ homa/__init__.py,sha256=BKmHKbWAjj61ESPbgQTmsQ7GH_NjRBowkD15QOIZBf0,92
2
+ homa/camera.py,sha256=KZf1r7olUkMRmX5c2qcDskMAq19cKWN5gTwj24pOM9o,391
3
+ homa/constants.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ homa/filters.py,sha256=oIo6dsB8OnCAkSDlYUzOySxEhlUI4D6ZHkKvO2GvuP4,821
5
+ homa/helpers.py,sha256=iS-MzPtcfwJYxmhM9NtWfWmWuLUwnAKaN3ZxxVA4SHw,593
6
+ homa/main.py,sha256=g0Uk271_qE8xq6Gs2hVMGNI73Sp7zjPbP-jiaaFndfo,1346
7
+ homa/orientation.py,sha256=0BdvozqBuuscMjG9zSl6YFt__MS4zM52Ja04SjbxIpk,749
8
+ homa/classes/Collection.py,sha256=7hskbC8wxTAC3hHmFYXtzR5W05lsA4GaYTzjiez_6Zg,222
9
+ homa/classes/Logger.py,sha256=2VjXJzBLMW5joArFpu2wGrbWUw7S-77z7LNhKUG1Iow,93
10
+ homa/classes/Repository.py,sha256=c0F_okpC6d8ppsOQ5X6eUD2dfHmIiVInNrGNe6b-3ss,705
11
+ homa/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ homa-0.22.dist-info/LICENSE,sha256=js3WDbJn9k5EN6sy1uuP2QBXxyPgS5DjO4Bf5yE35hQ,1072
13
+ homa-0.22.dist-info/METADATA,sha256=VpZ5AVoNJwnwHp0o8mSryTdO9oghE1u8Ha5zJfnoi4Y,2061
14
+ homa-0.22.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
15
+ homa-0.22.dist-info/top_level.txt,sha256=tmOfy2tuaAwc3W5-i6j61_vYJsXgR4ivBWkhJ3ZtJDc,5
16
+ homa-0.22.dist-info/RECORD,,
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: homa
3
- Version: 0.21
4
- Maintainer: Taha Shieenavaz
5
- Maintainer-email: tahashieenavaz@gmail.com
6
- Description-Content-Type: text/markdown
7
- License-File: LICENSE
8
- Requires-Dist: opencv-python
9
- Requires-Dist: numpy
10
-
11
- <p align="center">
12
- <img
13
- src="https://raw.githubusercontent.com/tahashieenavaz/homa/main/art/homa.svg"
14
- width=400
15
- />
16
- </p>
17
-
18
- <hr />
@@ -1,13 +0,0 @@
1
- homa/__init__.py,sha256=8D5a8oKgqd6WA1RUkiKCn4l_PVemtyuckxQut0vDHXM,20
2
- homa/constants.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- homa/helpers.py,sha256=Ldf52cbYfSsjAinQ4Vmw4zUaT7bphadwLAvgHBAO1KY,308
4
- homa/main.py,sha256=Mq6z6p5OkeACU98Q7Gq2tPL6s-jt0jVp82Cf-E0qrwk,2618
5
- homa/classes/Collection.py,sha256=7hskbC8wxTAC3hHmFYXtzR5W05lsA4GaYTzjiez_6Zg,222
6
- homa/classes/Logger.py,sha256=2VjXJzBLMW5joArFpu2wGrbWUw7S-77z7LNhKUG1Iow,93
7
- homa/classes/Repository.py,sha256=c0F_okpC6d8ppsOQ5X6eUD2dfHmIiVInNrGNe6b-3ss,705
8
- homa/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- homa-0.21.dist-info/LICENSE,sha256=js3WDbJn9k5EN6sy1uuP2QBXxyPgS5DjO4Bf5yE35hQ,1072
10
- homa-0.21.dist-info/METADATA,sha256=si2fgf66RaZh8qz-yJwbLAkmXza0v8z5QGKr0t5tE3E,365
11
- homa-0.21.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
12
- homa-0.21.dist-info/top_level.txt,sha256=tmOfy2tuaAwc3W5-i6j61_vYJsXgR4ivBWkhJ3ZtJDc,5
13
- homa-0.21.dist-info/RECORD,,
File without changes
File without changes