homa 0.22__tar.gz → 0.24__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: homa
3
- Version: 0.22
3
+ Version: 0.24
4
4
  Maintainer: Taha Shieenavaz
5
5
  Maintainer-email: tahashieenavaz@gmail.com
6
6
  Description-Content-Type: text/markdown
@@ -25,6 +25,10 @@ Images could be loaded with the `image` helper, that accepts the file name and a
25
25
  from homa import *
26
26
 
27
27
  image("horse.jpg", "horse")
28
+ show("horse", wait=True)
29
+
30
+ # or alternatively
31
+ showWait("horse")
28
32
  ```
29
33
 
30
34
  Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
@@ -33,6 +37,7 @@ Alternatively, following code will load the file into the repository with a key
33
37
  from homa import *
34
38
 
35
39
  image("horse.jpg") # stored as "horse"
40
+ showWait("horse")
36
41
  ```
37
42
 
38
43
  ## Smoothing
@@ -47,7 +52,8 @@ image("horse.jpg")
47
52
  blur("horse", 7) # rewrites "horse" key
48
53
  blur("horse", (7, 19)) # rewrites "horse" key
49
54
  blur("horse", 9, "blurred horse") # as a new key in the repository
50
- show("blurred horse")
55
+
56
+ showWait("blurred horse")
51
57
  ```
52
58
 
53
59
  ### Gaussian Blur
@@ -60,7 +66,22 @@ image("horse.jpg")
60
66
  gaussian("horse", 7) # rewrites "horse" key
61
67
  gaussian("horse", (7, 19)) # rewrites "horse" key
62
68
  gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
63
- show("gaussian blurred horse")
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")
64
85
  ```
65
86
 
66
87
  ## Stacking
@@ -17,6 +17,10 @@ Images could be loaded with the `image` helper, that accepts the file name and a
17
17
  from homa import *
18
18
 
19
19
  image("horse.jpg", "horse")
20
+ show("horse", wait=True)
21
+
22
+ # or alternatively
23
+ showWait("horse")
20
24
  ```
21
25
 
22
26
  Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
@@ -25,6 +29,7 @@ Alternatively, following code will load the file into the repository with a key
25
29
  from homa import *
26
30
 
27
31
  image("horse.jpg") # stored as "horse"
32
+ showWait("horse")
28
33
  ```
29
34
 
30
35
  ## Smoothing
@@ -39,7 +44,8 @@ image("horse.jpg")
39
44
  blur("horse", 7) # rewrites "horse" key
40
45
  blur("horse", (7, 19)) # rewrites "horse" key
41
46
  blur("horse", 9, "blurred horse") # as a new key in the repository
42
- show("blurred horse")
47
+
48
+ showWait("blurred horse")
43
49
  ```
44
50
 
45
51
  ### Gaussian Blur
@@ -52,7 +58,22 @@ image("horse.jpg")
52
58
  gaussian("horse", 7) # rewrites "horse" key
53
59
  gaussian("horse", (7, 19)) # rewrites "horse" key
54
60
  gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
55
- show("gaussian blurred horse")
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")
56
77
  ```
57
78
 
58
79
  ## Stacking
@@ -2,3 +2,8 @@ from .main import *
2
2
  from .filters import *
3
3
  from .camera import *
4
4
  from .orientation import *
5
+ from .spaces import *
6
+ from .events import *
7
+ from .shapes import *
8
+
9
+ from .helpers import *
@@ -1,21 +1,19 @@
1
1
  import cv2
2
2
  from .classes.Repository import Repository
3
+ from typing import Iterator
3
4
 
4
5
 
5
- def camera(delay=10):
6
- capture = cv2.VideoCapture(0)
7
-
6
+ def camera(delay: int = 10, exit_on: str = "q") -> Iterator[int]:
8
7
  pressed_key = None
9
-
8
+ capture = cv2.VideoCapture(0)
10
9
  frame_number = 0
11
-
12
- while pressed_key != ord("q"):
13
- frame_number += 1
10
+ while pressed_key != ord(exit_on):
14
11
  _, frame = capture.read()
15
-
16
12
  Repository.images["camera"] = frame
17
13
 
14
+ frame_number += 1
18
15
  yield frame_number
16
+
19
17
  pressed_key = cv2.waitKey(delay)
20
18
 
21
19
  capture.release()
@@ -1,4 +1,4 @@
1
- from ..helpers import is_colab
1
+ from ..helpers.environment import is_colab
2
2
 
3
3
 
4
4
  class RepositoryWrapper:
@@ -8,8 +8,7 @@ class RepositoryWrapper:
8
8
 
9
9
  self.directory = "./"
10
10
  self.images = {}
11
- self.cameras = {}
12
- self.window_counter = 0
11
+ self.windows = {}
13
12
 
14
13
  if is_colab():
15
14
  from google.colab.patches import cv2_imshow as imshow
@@ -24,9 +23,5 @@ class RepositoryWrapper:
24
23
 
25
24
  self.imshow = final_imshow
26
25
 
27
- def get_counter(self):
28
- self.window_counter += 1
29
- return self.window_counter
30
-
31
26
 
32
27
  Repository = RepositoryWrapper()
@@ -0,0 +1,70 @@
1
+ # enum MouseEventTypes
2
+ # {
3
+ # EVENT_MOUSEMOVE = 0,
4
+ # EVENT_LBUTTONDOWN = 1,
5
+ # EVENT_RBUTTONDOWN = 2,
6
+ # EVENT_MBUTTONDOWN = 3,
7
+ # EVENT_LBUTTONUP = 4,
8
+ # EVENT_RBUTTONUP = 5,
9
+ # EVENT_MBUTTONUP = 6,
10
+ # EVENT_LBUTTONDBLCLK = 7,
11
+ # EVENT_RBUTTONDBLCLK = 8,
12
+ # EVENT_MBUTTONDBLCLK = 9,
13
+ # EVENT_MOUSEWHEEL = 10,
14
+ # EVENT_MOUSEHWHEEL = 11,
15
+ # };
16
+ import cv2
17
+ from .main import win
18
+ from inspect import signature
19
+
20
+ event_map = {
21
+ "click": cv2.EVENT_LBUTTONDOWN,
22
+ "rclick": cv2.EVENT_RBUTTONDOWN,
23
+ "mclick": cv2.EVENT_MBUTTONDOWN,
24
+ "mouseup": cv2.EVENT_LBUTTONUP,
25
+ "rmouseup": cv2.EVENT_RBUTTONUP,
26
+ "dblclick": cv2.EVENT_LBUTTONDBLCLK,
27
+ "rdblclick": cv2.EVENT_RBUTTONDBLCLK,
28
+ "move": cv2.EVENT_MOUSEMOVE
29
+ }
30
+
31
+
32
+ def create_wrapper_function(event_name: str, handler: callable):
33
+ def wrapper_function(event, x, y, flags, param):
34
+ if event != event_map[event_name]:
35
+ return
36
+
37
+ argument_count = len(signature(handler).parameters)
38
+ if argument_count == 2:
39
+ handler(x, y)
40
+ elif argument_count == 3:
41
+ handler(x, y, flags)
42
+ elif argument_count == 4:
43
+ handler(x, y, flags, param)
44
+
45
+ return wrapper_function
46
+
47
+
48
+ def onClick(key: str, handler: callable):
49
+ win(key)
50
+ cv2.setMouseCallback(key, create_wrapper_function("click", handler))
51
+
52
+
53
+ def onRightClick(key: str, handler: callable):
54
+ win(key)
55
+ cv2.setMouseCallback(key, create_wrapper_function("rclick", handler))
56
+
57
+
58
+ def onMouseUp(key: str, handler: callable):
59
+ win(key)
60
+ cv2.setMouseCallback(key, create_wrapper_function("mouseup", handler))
61
+
62
+
63
+ def onMove(key: str, handler: callable):
64
+ win(key)
65
+ cv2.setMouseCallback(key, create_wrapper_function("mousemove", handler))
66
+
67
+
68
+ def onDoubleClick(key: str, handler: callable):
69
+ win(key)
70
+ cv2.setMouseCallback(key, create_wrapper_function("dblclick", handler))
@@ -1,10 +1,10 @@
1
1
  from typing import List
2
2
  from .classes.Repository import Repository
3
- from .helpers import create_kernel
3
+ from .helpers.kernel import create_kernel
4
4
  import cv2
5
5
 
6
6
 
7
- def blur(key: str, kernel: int | List[int] = (7, 7), new_key: str | None = None):
7
+ def blur(key: str, kernel: int | List[int] = (7, 7), new_key: str | None = None) -> None:
8
8
  if new_key is None:
9
9
  new_key = key
10
10
 
@@ -14,21 +14,28 @@ def blur(key: str, kernel: int | List[int] = (7, 7), new_key: str | None = None)
14
14
  )
15
15
 
16
16
 
17
- def sigma(x: float = 0, y: float = 0):
17
+ def median(key: str, kernel: int | List[int] = (7, 7), new_key: str | None = None) -> None:
18
+ if new_key is None:
19
+ new_key = key
20
+
21
+ Repository.images[new_key] = cv2.medianBlur(
22
+ Repository.images[key],
23
+ create_kernel(kernel)
24
+ )
25
+
26
+
27
+ def sigma(x: float = 0, y: float = 0) -> None:
18
28
  Repository.sigmaX = x
19
29
  Repository.sigmaY = y
20
30
 
21
31
 
22
- def gaussian(key: str, kernel: None | List[int] = None, new_key: str | None = None):
32
+ def gaussian(key: str, kernel: None | List[int] = None, new_key: str | None = None) -> None:
23
33
  if new_key is None:
24
34
  new_key = key
25
35
 
26
- if isinstance(kernel, int):
27
- kernel = (kernel, kernel)
28
-
29
36
  Repository.images[new_key] = cv2.GaussianBlur(
30
37
  Repository.images[key],
31
- kernel,
38
+ create_kernel(kernel),
32
39
  sigmaX=Repository.sigmaX,
33
40
  sigmaY=Repository.sigmaY
34
41
  )
File without changes
@@ -0,0 +1,14 @@
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):
7
+ if key is None:
8
+ return Repository.images
9
+
10
+ return Repository.images[key]
11
+
12
+
13
+ def collection(items: List[any]):
14
+ return Collection(items)
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+
4
+ def is_colab() -> bool:
5
+ return 'google.colab' in sys.modules
@@ -0,0 +1,15 @@
1
+ from typing import Tuple
2
+
3
+
4
+ def create_kernel(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)
File without changes
@@ -1,8 +1,20 @@
1
1
  import cv2
2
- from .helpers import danger
2
+ from .classes.Logger import Logger
3
3
  from .classes.Repository import Repository
4
4
 
5
5
 
6
+ def destroy(key: str | None = None) -> None:
7
+ if key is not None:
8
+ cv2.destroyWindow(key)
9
+ return
10
+
11
+ cv2.destroyAllWindows()
12
+
13
+
14
+ def win(key: str):
15
+ cv2.namedWindow(key)
16
+
17
+
6
18
  def path(directory: str) -> None:
7
19
  Repository.directory = directory
8
20
 
@@ -45,12 +57,18 @@ def show(key: any = None, wait: bool = False, window: str = "Homa Window") -> No
45
57
  elif key is None:
46
58
  for key, image in Repository.images.items():
47
59
  Repository.imshow(key, image)
60
+ Repository.windows[key] = key
48
61
 
49
62
  elif key is not None:
50
63
  if key in Repository.images:
51
64
  Repository.imshow(key, Repository.images[key])
65
+ Repository.windows[key] = key
52
66
  else:
53
- danger(f"No image found with key {key}")
67
+ Logger.danger(f"No image found with key {key}")
54
68
 
55
69
  if wait:
56
70
  cv2.waitKey(0)
71
+
72
+
73
+ def refresh(key: str) -> None:
74
+ cv2.imshow(Repository.windows[key], Repository.images[key])
@@ -1,6 +1,5 @@
1
- from typing import List
2
1
  from .classes.Repository import Repository
3
- from .helpers import collection
2
+ from .helpers.alias import collection
4
3
  import numpy
5
4
 
6
5
 
@@ -15,8 +14,11 @@ def stack(*keys, **settings):
15
14
  **settings
16
15
  }
17
16
 
17
+ if all(isinstance(item, str) for item in keys):
18
+ keys = collection(keys).map(lambda key: Repository.images[key])
19
+
18
20
  stacked_image = numpy.concatenate(
19
- collection(keys).map(lambda key: Repository.images[key]),
21
+ keys,
20
22
  axis=settings["axis"]
21
23
  )
22
24
 
@@ -0,0 +1,9 @@
1
+ import cv2
2
+ from .main import refresh
3
+ from .helpers.alias import repo
4
+ from .classes.Repository import Repository
5
+
6
+
7
+ def circle(key: str, x: int = 0, y: int = 0, r: int = 1, color=(0, 0, 255), thickness: int = 1):
8
+ cv2.circle(repo(key), (x, y), r, color, thickness)
9
+ refresh(key)
@@ -0,0 +1,20 @@
1
+ from typing import Tuple
2
+ from .helpers.alias import repo
3
+
4
+
5
+ def rgb(key: str) -> Tuple[int, int, int]:
6
+ image = repo(key)
7
+
8
+ if image.shape[2] == 3:
9
+ # found three channels in stored image
10
+ # meaning that it has been loaded as a color image
11
+
12
+ b = image[:, :, 0]
13
+ g = image[:, :, 0]
14
+ r = image[:, :, 0]
15
+
16
+ return (r, g, b)
17
+
18
+ if image.shape[2] == 1:
19
+ gray = image[:, :, 0]
20
+ return (gray, gray, gray)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: homa
3
- Version: 0.22
3
+ Version: 0.24
4
4
  Maintainer: Taha Shieenavaz
5
5
  Maintainer-email: tahashieenavaz@gmail.com
6
6
  Description-Content-Type: text/markdown
@@ -25,6 +25,10 @@ Images could be loaded with the `image` helper, that accepts the file name and a
25
25
  from homa import *
26
26
 
27
27
  image("horse.jpg", "horse")
28
+ show("horse", wait=True)
29
+
30
+ # or alternatively
31
+ showWait("horse")
28
32
  ```
29
33
 
30
34
  Alternatively, following code will load the file into the repository with a key of everything before the last in the filename.
@@ -33,6 +37,7 @@ Alternatively, following code will load the file into the repository with a key
33
37
  from homa import *
34
38
 
35
39
  image("horse.jpg") # stored as "horse"
40
+ showWait("horse")
36
41
  ```
37
42
 
38
43
  ## Smoothing
@@ -47,7 +52,8 @@ image("horse.jpg")
47
52
  blur("horse", 7) # rewrites "horse" key
48
53
  blur("horse", (7, 19)) # rewrites "horse" key
49
54
  blur("horse", 9, "blurred horse") # as a new key in the repository
50
- show("blurred horse")
55
+
56
+ showWait("blurred horse")
51
57
  ```
52
58
 
53
59
  ### Gaussian Blur
@@ -60,7 +66,22 @@ image("horse.jpg")
60
66
  gaussian("horse", 7) # rewrites "horse" key
61
67
  gaussian("horse", (7, 19)) # rewrites "horse" key
62
68
  gaussian("horse", 9, "gaussian blurred horse") # as a new key in the repository
63
- show("gaussian blurred horse")
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")
64
85
  ```
65
86
 
66
87
  ## Stacking
@@ -4,10 +4,13 @@ setup.py
4
4
  homa/__init__.py
5
5
  homa/camera.py
6
6
  homa/constants.py
7
+ homa/events.py
7
8
  homa/filters.py
8
9
  homa/helpers.py
9
10
  homa/main.py
10
11
  homa/orientation.py
12
+ homa/shapes.py
13
+ homa/spaces.py
11
14
  homa.egg-info/PKG-INFO
12
15
  homa.egg-info/SOURCES.txt
13
16
  homa.egg-info/dependency_links.txt
@@ -16,4 +19,10 @@ homa.egg-info/top_level.txt
16
19
  homa/classes/Collection.py
17
20
  homa/classes/Logger.py
18
21
  homa/classes/Repository.py
19
- homa/classes/__init__.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
+ tests/__init__.py
28
+ tests/test_images.py
@@ -0,0 +1,2 @@
1
+ homa
2
+ tests
File without changes
@@ -0,0 +1,27 @@
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.22/homa/helpers.py DELETED
@@ -1,30 +0,0 @@
1
- import sys
2
- from typing import List
3
- from .classes.Collection import Collection
4
- from .classes.Logger import Logger
5
-
6
-
7
- def is_colab() -> bool:
8
- return 'google.colab' in sys.modules
9
-
10
-
11
- def collection(items: List[any]):
12
- return Collection(items)
13
-
14
-
15
- def danger(message: str) -> None:
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)
@@ -1 +0,0 @@
1
- homa
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes