hexss 0.2.2__tar.gz → 0.4.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.
Files changed (31) hide show
  1. {hexss-0.2.2 → hexss-0.4.1}/PKG-INFO +1 -1
  2. {hexss-0.2.2 → hexss-0.4.1}/hexss/__init__.py +2 -0
  3. hexss-0.4.1/hexss/constants/__init__.py +1 -0
  4. hexss-0.4.1/hexss/example/image.py +45 -0
  5. hexss-0.4.1/hexss/example/multicore.py +33 -0
  6. hexss-0.4.1/hexss/example/multicore2.py +56 -0
  7. hexss-0.4.1/hexss/get_ipv4.py +5 -0
  8. hexss-0.4.1/hexss/image/__init__.py +1 -0
  9. hexss-0.4.1/hexss/image/func.py +45 -0
  10. hexss-0.4.1/hexss/json/__init__.py +1 -0
  11. hexss-0.4.1/hexss/kill.py +6 -0
  12. hexss-0.4.1/hexss/multiprocessing/__init__.py +2 -0
  13. hexss-0.4.1/hexss/multiprocessing/multicore.py +26 -0
  14. {hexss-0.2.2 → hexss-0.4.1}/hexss.egg-info/PKG-INFO +1 -1
  15. {hexss-0.2.2 → hexss-0.4.1}/hexss.egg-info/SOURCES.txt +10 -1
  16. {hexss-0.2.2 → hexss-0.4.1}/setup.py +1 -1
  17. hexss-0.2.2/hexss/example/__init__.py +0 -0
  18. hexss-0.2.2/hexss/json/__init__.py +0 -1
  19. {hexss-0.2.2 → hexss-0.4.1}/LICENSE +0 -0
  20. {hexss-0.2.2 → hexss-0.4.1}/hexss/constants/cml.py +0 -0
  21. {hexss-0.2.2/hexss/constants → hexss-0.4.1/hexss/example}/__init__.py +0 -0
  22. {hexss-0.2.2 → hexss-0.4.1}/hexss/example/camera_server.py +0 -0
  23. {hexss-0.2.2 → hexss-0.4.1}/hexss/example/example.py +0 -0
  24. /hexss-0.2.2/hexss/json/json_utils.py → /hexss-0.4.1/hexss/json/func.py +0 -0
  25. /hexss-0.2.2/hexss/multiprocessing/__init__.py → /hexss-0.4.1/hexss/multiprocessing/func.py +0 -0
  26. {hexss-0.2.2 → hexss-0.4.1}/hexss/server/__init__.py +0 -0
  27. {hexss-0.2.2 → hexss-0.4.1}/hexss/server/camera_server.py +0 -0
  28. {hexss-0.2.2 → hexss-0.4.1}/hexss/server/templates/simulate_CCTV.html +0 -0
  29. {hexss-0.2.2 → hexss-0.4.1}/hexss.egg-info/dependency_links.txt +0 -0
  30. {hexss-0.2.2 → hexss-0.4.1}/hexss.egg-info/top_level.txt +0 -0
  31. {hexss-0.2.2 → hexss-0.4.1}/setup.cfg +0 -0
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hexss
3
- Version: 0.2.2
3
+ Version: 0.4.1
4
4
  License-File: LICENSE
@@ -1,2 +1,4 @@
1
1
  from .json import json_load, json_dump, json_update
2
2
  from .multiprocessing import list_to_manager_list, dict_to_manager_dict
3
+ from .get_ipv4 import get_ipv4
4
+ from .kill import kill
@@ -0,0 +1 @@
1
+ from .cml import *
@@ -0,0 +1,45 @@
1
+ import cv2
2
+ import pygame
3
+ from hexss.image import get_image
4
+
5
+
6
+ def test_np():
7
+ while True:
8
+ img = get_image(source)
9
+ cv2.imshow('img', img)
10
+ key = cv2.waitKey(1)
11
+ if key == 27:
12
+ break
13
+
14
+
15
+ def test_pygame():
16
+ pygame.init()
17
+ screen = pygame.display.set_mode((640, 480))
18
+ clock = pygame.time.Clock()
19
+
20
+ try:
21
+ while True:
22
+ for event in pygame.event.get():
23
+ if event.type == pygame.QUIT:
24
+ raise SystemExit
25
+
26
+ img = get_image(source, output='pygame')
27
+ if img is not None:
28
+ screen.blit(img, (0, 0))
29
+ pygame.display.flip()
30
+ else:
31
+ print("Failed to retrieve image. Retrying...")
32
+
33
+ clock.tick(30)
34
+ finally:
35
+ if isinstance(source, cv2.VideoCapture):
36
+ source.release()
37
+ pygame.quit()
38
+
39
+
40
+ if __name__ == "__main__":
41
+ source = cv2.VideoCapture(0)
42
+ # source = "http://192.168.225.137:2000/image?source=video_capture&id=0"
43
+
44
+ test_np()
45
+ # test_pygame()
@@ -0,0 +1,33 @@
1
+ import time
2
+ from hexss.constants import RED, BLUE, ENDC
3
+ from hexss.multiprocessing import Multicore
4
+
5
+
6
+ def func1(data):
7
+ while True:
8
+ data['func1'] = data.get('func1', 0) + 1
9
+ data['list'].append(data['func1'])
10
+ if len(data['list']) > 20:
11
+ data['list'] = data['list'][:20]
12
+ print(f'{RED}{data["func1"]} {data['list']}{ENDC}')
13
+ time.sleep(1)
14
+
15
+
16
+ def func2(data):
17
+ while True:
18
+ data['func2'] = data.get('func2', 0) + 1
19
+ print(f'{BLUE}{data["func2"]}{ENDC}')
20
+ time.sleep(2)
21
+
22
+
23
+ if __name__ == '__main__':
24
+ m = Multicore()
25
+ m.set_data({
26
+ 'func1': -50,
27
+ 'func2': -50,
28
+ 'list': []
29
+ })
30
+ m.add_func(func1)
31
+ m.add_func(func2)
32
+ m.start()
33
+ m.join()
@@ -0,0 +1,56 @@
1
+ import cv2
2
+ from hexss.multiprocessing import Multicore
3
+
4
+
5
+ def capture_video(data):
6
+ cap = cv2.VideoCapture(0)
7
+ if not cap.isOpened():
8
+ print("Error: Could not open camera.")
9
+ data['play'] = False
10
+ return
11
+
12
+ while data['play']:
13
+ ret, frame = cap.read()
14
+ if not ret:
15
+ print("Error: Failed to capture frame.")
16
+ data['play'] = False
17
+ data['frame'] = frame.copy()
18
+ cap.release()
19
+
20
+
21
+ def process_video(data):
22
+ while data['play']:
23
+ if 'frame' in data and data['frame'] is not None:
24
+ cv2.imshow('frame', data['frame'])
25
+ if cv2.waitKey(1) & 0xFF == ord('q'):
26
+ data['play'] = False
27
+ cv2.destroyAllWindows()
28
+
29
+
30
+ # def capture_video(data):
31
+ # cap = cv2.VideoCapture(0)
32
+ # while data['play']:
33
+ # ret, frame = cap.read()
34
+ # data['frame'] = frame.copy()
35
+ #
36
+ #
37
+ # def process_video(data):
38
+ # while data['play']:
39
+ # if data['frame'] is not None:
40
+ # cv2.imshow('frame', data['frame'])
41
+ #
42
+ # if cv2.waitKey(1) & 0xFF == ord('q'):
43
+ # data['play'] = False
44
+ #
45
+ # cv2.destroyAllWindows()
46
+
47
+ if __name__ == '__main__':
48
+ m = Multicore()
49
+ m.set_data({
50
+ 'play': True,
51
+ 'frame': None,
52
+ })
53
+ m.add_func(capture_video)
54
+ m.add_func(process_video)
55
+ m.start()
56
+ m.join()
@@ -0,0 +1,5 @@
1
+ import socket
2
+
3
+
4
+ def get_ipv4():
5
+ return socket.gethostbyname(socket.gethostname())
@@ -0,0 +1 @@
1
+ from .func import get_image, get_image_from_cam, get_image_from_url
@@ -0,0 +1,45 @@
1
+ import cv2
2
+ import numpy as np
3
+ import urllib.request
4
+ from typing import Optional, Union, Literal
5
+ import pygame
6
+
7
+
8
+ def get_image_from_cam(cap: cv2.VideoCapture) -> Optional[np.ndarray]:
9
+ ret, frame = cap.read()
10
+ if not ret:
11
+ print("Failed to capture frame from camera")
12
+ return None
13
+ return frame
14
+
15
+
16
+ def get_image_from_url(url: str) -> Optional[np.ndarray]:
17
+ try:
18
+ with urllib.request.urlopen(url, timeout=5) as req:
19
+ arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
20
+ return cv2.imdecode(arr, cv2.IMREAD_COLOR)
21
+ except Exception as e:
22
+ print(f"Error loading image from URL: {e}")
23
+ return None
24
+
25
+
26
+ def numpy_to_pygame_surface(arr: np.ndarray) -> pygame.Surface:
27
+ arr = cv2.cvtColor(arr, cv2.COLOR_BGR2RGB)
28
+ return pygame.surfarray.make_surface(arr.swapaxes(0, 1))
29
+
30
+
31
+ def get_image(source: Union[cv2.VideoCapture, str], output: Literal['numpy', 'pygame'] = 'numpy') -> Optional[
32
+ Union[np.ndarray, pygame.Surface]]:
33
+ if isinstance(source, str):
34
+ img = get_image_from_url(source)
35
+ elif isinstance(source, cv2.VideoCapture):
36
+ img = get_image_from_cam(source)
37
+ else:
38
+ raise ValueError("Invalid source type. Expected cv2.VideoCapture or str (URL).")
39
+
40
+ if img is None:
41
+ return None
42
+
43
+ if output == 'pygame':
44
+ return numpy_to_pygame_surface(img)
45
+ return img
@@ -0,0 +1 @@
1
+ from .func import json_load, json_dump, json_update
@@ -0,0 +1,6 @@
1
+ import os
2
+ import signal
3
+
4
+
5
+ def kill():
6
+ os.kill(os.getpid(), signal.SIGINT)
@@ -0,0 +1,2 @@
1
+ from .multicore import Multicore
2
+ from .func import dict_to_manager_dict, list_to_manager_list
@@ -0,0 +1,26 @@
1
+ from multiprocessing import Process, Manager
2
+ from hexss.multiprocessing.func import dict_to_manager_dict
3
+
4
+
5
+ class Multicore:
6
+ def __init__(self):
7
+ self.processes = []
8
+ self.manager = Manager()
9
+ self.data = self.manager.dict()
10
+ self.func_join = []
11
+
12
+ def set_data(self, data: dict):
13
+ self.data = dict_to_manager_dict(self.manager, data)
14
+
15
+ def add_func(self, func, join=True):
16
+ self.processes.append(Process(target=func, args=(self.data,)))
17
+ self.func_join.append(join)
18
+
19
+ def start(self):
20
+ for process in self.processes:
21
+ process.start()
22
+
23
+ def join(self):
24
+ for i, process in enumerate(self.processes):
25
+ if self.func_join[i]:
26
+ process.join()
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hexss
3
- Version: 0.2.2
3
+ Version: 0.4.1
4
4
  License-File: LICENSE
@@ -1,6 +1,8 @@
1
1
  LICENSE
2
2
  setup.py
3
3
  hexss/__init__.py
4
+ hexss/get_ipv4.py
5
+ hexss/kill.py
4
6
  hexss.egg-info/PKG-INFO
5
7
  hexss.egg-info/SOURCES.txt
6
8
  hexss.egg-info/dependency_links.txt
@@ -10,9 +12,16 @@ hexss/constants/cml.py
10
12
  hexss/example/__init__.py
11
13
  hexss/example/camera_server.py
12
14
  hexss/example/example.py
15
+ hexss/example/image.py
16
+ hexss/example/multicore.py
17
+ hexss/example/multicore2.py
18
+ hexss/image/__init__.py
19
+ hexss/image/func.py
13
20
  hexss/json/__init__.py
14
- hexss/json/json_utils.py
21
+ hexss/json/func.py
15
22
  hexss/multiprocessing/__init__.py
23
+ hexss/multiprocessing/func.py
24
+ hexss/multiprocessing/multicore.py
16
25
  hexss/server/__init__.py
17
26
  hexss/server/camera_server.py
18
27
  hexss/server/templates/simulate_CCTV.html
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='hexss',
5
- version='0.2.2',
5
+ version='0.4.1',
6
6
  packages=find_packages(),
7
7
  include_package_data=True,
8
8
  install_requires=[],
File without changes
@@ -1 +0,0 @@
1
- from .json_utils import json_load, json_dump, json_update
File without changes
File without changes
File without changes
File without changes
File without changes