pynode-flow 0.2.0__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.
Files changed (227) hide show
  1. pynode/__init__.py +37 -0
  2. pynode/__main__.py +9 -0
  3. pynode/_perf.py +65 -0
  4. pynode/_version.py +24 -0
  5. pynode/api/__init__.py +15 -0
  6. pynode/api/helpers.py +79 -0
  7. pynode/api/nodes.py +423 -0
  8. pynode/api/services.py +124 -0
  9. pynode/api/sse.py +58 -0
  10. pynode/api/uploads.py +59 -0
  11. pynode/api/workflows.py +466 -0
  12. pynode/config.py +93 -0
  13. pynode/install_nodes.py +143 -0
  14. pynode/main.py +118 -0
  15. pynode/node_registry.py +156 -0
  16. pynode/nodes/AutoSyncNode/auto_sync_node.py +151 -0
  17. pynode/nodes/BBoxMetricsNode/__init__.py +3 -0
  18. pynode/nodes/BBoxMetricsNode/bbox_metrics_node.py +250 -0
  19. pynode/nodes/BBoxMetricsNode/requirements.txt +1 -0
  20. pynode/nodes/BatchNode/__init__.py +3 -0
  21. pynode/nodes/BatchNode/batch_node.py +86 -0
  22. pynode/nodes/BatchNode/requirements.txt +1 -0
  23. pynode/nodes/CameraNode/__init__.py +4 -0
  24. pynode/nodes/CameraNode/camera_node.py +204 -0
  25. pynode/nodes/CameraNode/requirements.txt +2 -0
  26. pynode/nodes/ChangeNode/__init__.py +1 -0
  27. pynode/nodes/ChangeNode/change_node.py +255 -0
  28. pynode/nodes/ChangeNode/requirements.txt +1 -0
  29. pynode/nodes/ConfidenceFilterNode/__init__.py +4 -0
  30. pynode/nodes/ConfidenceFilterNode/confidence_filter_node.py +208 -0
  31. pynode/nodes/ConfidenceFilterNode/requirements.txt +1 -0
  32. pynode/nodes/CounterNode/__init__.py +3 -0
  33. pynode/nodes/CounterNode/counter_node.py +191 -0
  34. pynode/nodes/CropNode/__init__.py +4 -0
  35. pynode/nodes/CropNode/crop_node.py +317 -0
  36. pynode/nodes/CropNode/requirements.txt +2 -0
  37. pynode/nodes/DebugNode/__init__.py +4 -0
  38. pynode/nodes/DebugNode/debug_node.py +169 -0
  39. pynode/nodes/DebugNode/requirements.txt +1 -0
  40. pynode/nodes/DelayNode/delay_node.py +218 -0
  41. pynode/nodes/DelayNode/requirements.txt +1 -0
  42. pynode/nodes/DrawPredictionsNode/__init__.py +3 -0
  43. pynode/nodes/DrawPredictionsNode/draw_predictions_node.py +365 -0
  44. pynode/nodes/DrawPredictionsNode/requirements.txt +2 -0
  45. pynode/nodes/ErrorNode/error_node.py +94 -0
  46. pynode/nodes/ErrorNode/requirements.txt +1 -0
  47. pynode/nodes/FilterNode/__init__.py +3 -0
  48. pynode/nodes/FilterNode/filter_node.py +102 -0
  49. pynode/nodes/FilterNode/requirements.txt +1 -0
  50. pynode/nodes/FrameSourceNode/__init__.py +4 -0
  51. pynode/nodes/FrameSourceNode/frame_source_node.py +319 -0
  52. pynode/nodes/FrameSourceNode/requirements.txt +1 -0
  53. pynode/nodes/FunctionNode/__init__.py +3 -0
  54. pynode/nodes/FunctionNode/function_node.py +168 -0
  55. pynode/nodes/FunctionNode/requirements.txt +1 -0
  56. pynode/nodes/GateNode/gate_node.py +60 -0
  57. pynode/nodes/GateNode/requirements.txt +1 -0
  58. pynode/nodes/GetiUploadNode/__init__.py +3 -0
  59. pynode/nodes/GetiUploadNode/geti_upload_node.py +278 -0
  60. pynode/nodes/GetiUploadNode/requirements.txt +1 -0
  61. pynode/nodes/ImageFormatNode/__init__.py +4 -0
  62. pynode/nodes/ImageFormatNode/image_format_node.py +310 -0
  63. pynode/nodes/ImageFormatNode/requirements.txt +2 -0
  64. pynode/nodes/ImageUploadNode/image_upload_node.py +96 -0
  65. pynode/nodes/ImageViewerNode/__init__.py +4 -0
  66. pynode/nodes/ImageViewerNode/image_viewer_node.py +162 -0
  67. pynode/nodes/ImageViewerNode/requirements.txt +2 -0
  68. pynode/nodes/ImageWriterNode/__init__.py +3 -0
  69. pynode/nodes/ImageWriterNode/imagewriter_node.py +352 -0
  70. pynode/nodes/ImageWriterNode/requirements.txt +1 -0
  71. pynode/nodes/InferenceNode/InferenceEngine/__init__.py +15 -0
  72. pynode/nodes/InferenceNode/InferenceEngine/device_detection.py +149 -0
  73. pynode/nodes/InferenceNode/InferenceEngine/engines/base_engine.py +155 -0
  74. pynode/nodes/InferenceNode/InferenceEngine/engines/example_engine_template.py +272 -0
  75. pynode/nodes/InferenceNode/InferenceEngine/engines/geti_engine.py +309 -0
  76. pynode/nodes/InferenceNode/InferenceEngine/engines/onnx_engine.py +346 -0
  77. pynode/nodes/InferenceNode/InferenceEngine/engines/pass_engine.py +86 -0
  78. pynode/nodes/InferenceNode/InferenceEngine/engines/ultralytics_engine.py +863 -0
  79. pynode/nodes/InferenceNode/InferenceEngine/inference_engine_factory.py +533 -0
  80. pynode/nodes/InferenceNode/InferenceEngine/readme.md +107 -0
  81. pynode/nodes/InferenceNode/InferenceEngine/result_converters.py +121 -0
  82. pynode/nodes/InferenceNode/inference_node.py +451 -0
  83. pynode/nodes/InferenceNode/requirements.txt +13 -0
  84. pynode/nodes/InjectNode/inject_node.py +245 -0
  85. pynode/nodes/InjectNode/requirements.txt +1 -0
  86. pynode/nodes/JoinNode/__init__.py +3 -0
  87. pynode/nodes/JoinNode/join_node.py +156 -0
  88. pynode/nodes/JoinNode/requirements.txt +1 -0
  89. pynode/nodes/LabelFilterNode/__init__.py +3 -0
  90. pynode/nodes/LabelFilterNode/label_filter_node.py +188 -0
  91. pynode/nodes/LabelFilterNode/requirements.txt +1 -0
  92. pynode/nodes/MQTTNode/__init__.py +8 -0
  93. pynode/nodes/MQTTNode/mqtt_in_node.py +148 -0
  94. pynode/nodes/MQTTNode/mqtt_out_node.py +157 -0
  95. pynode/nodes/MQTTNode/mqtt_service.py +367 -0
  96. pynode/nodes/MQTTNode/requirements.txt +1 -0
  97. pynode/nodes/MessageWriterNode/__init__.py +7 -0
  98. pynode/nodes/MessageWriterNode/messagereader_node.py +568 -0
  99. pynode/nodes/MessageWriterNode/messagewriter_node.py +505 -0
  100. pynode/nodes/OmronCameraNode/__init__.py +3 -0
  101. pynode/nodes/OmronCameraNode/omron_camera_node.py +652 -0
  102. pynode/nodes/OmronCameraNode/requirements.txt +4 -0
  103. pynode/nodes/OpenCV/__init__.py +1 -0
  104. pynode/nodes/OpenCV/arithmetic_node.py +376 -0
  105. pynode/nodes/OpenCV/bitwise_node.py +127 -0
  106. pynode/nodes/OpenCV/blend_node.py +127 -0
  107. pynode/nodes/OpenCV/blob_detector_node.py +233 -0
  108. pynode/nodes/OpenCV/blur_node.py +141 -0
  109. pynode/nodes/OpenCV/color_space_node.py +139 -0
  110. pynode/nodes/OpenCV/colormap_node.py +262 -0
  111. pynode/nodes/OpenCV/contours_node.py +258 -0
  112. pynode/nodes/OpenCV/denormalize_coords_node.py +365 -0
  113. pynode/nodes/OpenCV/draw_node.py +312 -0
  114. pynode/nodes/OpenCV/edge_detector_node.py +177 -0
  115. pynode/nodes/OpenCV/equirectangular_node.py +447 -0
  116. pynode/nodes/OpenCV/fft_node.py +102 -0
  117. pynode/nodes/OpenCV/focus_estimation_node.py +189 -0
  118. pynode/nodes/OpenCV/frequency_filter_node.py +241 -0
  119. pynode/nodes/OpenCV/histogram_node.py +160 -0
  120. pynode/nodes/OpenCV/hough_circles_node.py +224 -0
  121. pynode/nodes/OpenCV/hough_lines_node.py +243 -0
  122. pynode/nodes/OpenCV/in_range_node.py +186 -0
  123. pynode/nodes/OpenCV/morphology_node.py +136 -0
  124. pynode/nodes/OpenCV/normalize_coords_node.py +344 -0
  125. pynode/nodes/OpenCV/paste_node.py +244 -0
  126. pynode/nodes/OpenCV/perspective_node.py +174 -0
  127. pynode/nodes/OpenCV/realsense_depth_node.py +253 -0
  128. pynode/nodes/OpenCV/requirements.txt +2 -0
  129. pynode/nodes/OpenCV/resize_node.py +175 -0
  130. pynode/nodes/OpenCV/rotate_node.py +159 -0
  131. pynode/nodes/OpenCV/template_match_node.py +227 -0
  132. pynode/nodes/OpenCV/threshold_node.py +167 -0
  133. pynode/nodes/PointInShapeNode/__init__.py +3 -0
  134. pynode/nodes/PointInShapeNode/point_in_shape_node.py +313 -0
  135. pynode/nodes/PointInShapeNode/requirements.txt +2 -0
  136. pynode/nodes/PolygonMetricsNode/__init__.py +3 -0
  137. pynode/nodes/PolygonMetricsNode/polygon_metrics_node.py +331 -0
  138. pynode/nodes/PolygonMetricsNode/requirements.txt +2 -0
  139. pynode/nodes/QueueLengthProbeNode/__init__.py +3 -0
  140. pynode/nodes/QueueLengthProbeNode/queue_length_probe_node.py +116 -0
  141. pynode/nodes/Qwen3VLMNode/__init__.py +3 -0
  142. pynode/nodes/Qwen3VLMNode/qwen3_vlm_node.py +519 -0
  143. pynode/nodes/Qwen3VLMNode/requirements.txt +5 -0
  144. pynode/nodes/RESTEndpointNode/__init__.py +3 -0
  145. pynode/nodes/RESTEndpointNode/rest_endpoint_node.py +491 -0
  146. pynode/nodes/RangeNode/__init__.py +3 -0
  147. pynode/nodes/RangeNode/range_node.py +115 -0
  148. pynode/nodes/RangeNode/requirements.txt +1 -0
  149. pynode/nodes/RateProbeNode/__init__.py +3 -0
  150. pynode/nodes/RateProbeNode/rate_probe_node.py +183 -0
  151. pynode/nodes/RateProbeNode/requirements.txt +1 -0
  152. pynode/nodes/RoboflowUploadNode/__init__.py +3 -0
  153. pynode/nodes/RoboflowUploadNode/requirements.txt +1 -0
  154. pynode/nodes/RoboflowUploadNode/roboflow_upload_node.py +229 -0
  155. pynode/nodes/SliceNode/README.md +149 -0
  156. pynode/nodes/SliceNode/__init__.py +5 -0
  157. pynode/nodes/SliceNode/merge_predictions_node.py +444 -0
  158. pynode/nodes/SliceNode/requirements.txt +3 -0
  159. pynode/nodes/SliceNode/slice_collector_node.py +370 -0
  160. pynode/nodes/SliceNode/slice_image_node.py +380 -0
  161. pynode/nodes/SplitNode/__init__.py +3 -0
  162. pynode/nodes/SplitNode/requirements.txt +1 -0
  163. pynode/nodes/SplitNode/split_node.py +155 -0
  164. pynode/nodes/SwitchNode/requirements.txt +1 -0
  165. pynode/nodes/SwitchNode/switch_node.py +259 -0
  166. pynode/nodes/SyncNode/__init__.py +3 -0
  167. pynode/nodes/SyncNode/sync_node.py +287 -0
  168. pynode/nodes/TemplateNode/requirements.txt +1 -0
  169. pynode/nodes/TemplateNode/template_node.py +86 -0
  170. pynode/nodes/TrackerNode/__init__.py +2 -0
  171. pynode/nodes/TrackerNode/supervision_tracker_node.py +248 -0
  172. pynode/nodes/TrackerNode/tracker_node.py +745 -0
  173. pynode/nodes/UltralyticsNode/__init__.py +4 -0
  174. pynode/nodes/UltralyticsNode/requirements.txt +2 -0
  175. pynode/nodes/UltralyticsNode/ultralytics_node.py +364 -0
  176. pynode/nodes/UnknownNode/__init__.py +93 -0
  177. pynode/nodes/VLLMNode/__init__.py +3 -0
  178. pynode/nodes/VLLMNode/vllm_node.py +345 -0
  179. pynode/nodes/VideoReaderNode/__init__.py +3 -0
  180. pynode/nodes/VideoReaderNode/video_reader_node.py +425 -0
  181. pynode/nodes/VideoWriterNode/__init__.py +3 -0
  182. pynode/nodes/VideoWriterNode/video_writer_node.py +441 -0
  183. pynode/nodes/WebhookNode/__init__.py +3 -0
  184. pynode/nodes/WebhookNode/webhook_node.py +591 -0
  185. pynode/nodes/__init__.py +109 -0
  186. pynode/nodes/base_node.py +562 -0
  187. pynode/nodes/image_utils.py +291 -0
  188. pynode/nodes/info.py +109 -0
  189. pynode/nodes/mDNSNode/__init__.py +13 -0
  190. pynode/nodes/mDNSNode/mdns_broadcast_node.py +214 -0
  191. pynode/nodes/mDNSNode/mdns_discovery_node.py +362 -0
  192. pynode/nodes/mDNSNode/mdns_manager.py +399 -0
  193. pynode/nodes/mDNSNode/requirements.txt +1 -0
  194. pynode/nodes/messages.py +81 -0
  195. pynode/server.py +187 -0
  196. pynode/static/images/favicon4.png +0 -0
  197. pynode/static/index.html +200 -0
  198. pynode/static/js/README.md +139 -0
  199. pynode/static/js/auth.js +89 -0
  200. pynode/static/js/clipboard.js +152 -0
  201. pynode/static/js/config.js +14 -0
  202. pynode/static/js/connections.js +844 -0
  203. pynode/static/js/debug.js +524 -0
  204. pynode/static/js/events.js +775 -0
  205. pynode/static/js/history.js +199 -0
  206. pynode/static/js/main.js +55 -0
  207. pynode/static/js/minimap.js +242 -0
  208. pynode/static/js/nodes.js +995 -0
  209. pynode/static/js/palette.js +255 -0
  210. pynode/static/js/properties.js +1270 -0
  211. pynode/static/js/selection.js +241 -0
  212. pynode/static/js/state.js +211 -0
  213. pynode/static/js/ui-utils.js +28 -0
  214. pynode/static/js/viewport.js +204 -0
  215. pynode/static/js/workflow.js +469 -0
  216. pynode/static/js/workflows.js +344 -0
  217. pynode/static/style.css +2751 -0
  218. pynode/workflow_engine.py +483 -0
  219. pynode/workflow_manager.py +440 -0
  220. pynode_flow-0.2.0.dist-info/METADATA +520 -0
  221. pynode_flow-0.2.0.dist-info/RECORD +227 -0
  222. pynode_flow-0.2.0.dist-info/WHEEL +5 -0
  223. pynode_flow-0.2.0.dist-info/entry_points.txt +3 -0
  224. pynode_flow-0.2.0.dist-info/licenses/LICENSE +21 -0
  225. pynode_flow-0.2.0.dist-info/scm_file_list.json +270 -0
  226. pynode_flow-0.2.0.dist-info/scm_version.json +8 -0
  227. pynode_flow-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,177 @@
1
+ """
2
+ OpenCV Edge Detection Node - detects edges using various algorithms.
3
+ """
4
+
5
+ import cv2
6
+ import numpy as np
7
+ from typing import Any, Dict
8
+ from pynode.nodes.base_node import BaseNode, process_image, Info
9
+
10
+ _info = Info()
11
+ _info.add_text("Detects edges in images using various algorithms. Converts color images to grayscale automatically.")
12
+ _info.add_header("Inputs")
13
+ _info.add_bullets(("Input 0:", "Image (color or grayscale)"))
14
+ _info.add_header("Outputs")
15
+ _info.add_bullets(("Output 0:", "Edge-detected image (grayscale)"))
16
+ _info.add_header("Methods")
17
+ _info.add_bullets(
18
+ ("Canny:", "Two-threshold hysteresis edge detection (most common)"),
19
+ ("Sobel:", "Gradient-based detection with directional control"),
20
+ ("Laplacian:", "Second derivative edge detection"),
21
+ ("Scharr:", "More accurate gradient than Sobel")
22
+ )
23
+ _info.add_header("Tips")
24
+ _info.add_bullets(
25
+ ("Canny:", "Lower threshold1 detects more edges"),
26
+ ("Sobel/Scharr:", "Use 'Both X and Y' for all edge directions")
27
+ )
28
+
29
+
30
+ class EdgeDetectorNode(BaseNode):
31
+ info = str(_info)
32
+ """
33
+ Edge Detection node - detects edges in images.
34
+ Supports Canny, Sobel, Laplacian, and Scharr methods.
35
+ """
36
+ display_name = 'Edge Detector'
37
+ icon = '⧈'
38
+ category = 'opencv'
39
+ color = '#4A90D9'
40
+ border_color = '#2E6BB0'
41
+ text_color = '#FFFFFF'
42
+ input_count = 1
43
+ output_count = 1
44
+
45
+ DEFAULT_CONFIG = {
46
+ 'method': 'canny',
47
+ 'threshold1': 100,
48
+ 'threshold2': 200,
49
+ 'aperture_size': 3,
50
+ 'sobel_direction': 'both',
51
+ 'l2_gradient': 'no'
52
+ }
53
+
54
+ properties = [
55
+ {
56
+ 'name': 'method',
57
+ 'label': 'Method',
58
+ 'type': 'select',
59
+ 'options': [
60
+ {'value': 'canny', 'label': 'Canny'},
61
+ {'value': 'sobel', 'label': 'Sobel'},
62
+ {'value': 'laplacian', 'label': 'Laplacian'},
63
+ {'value': 'scharr', 'label': 'Scharr'}
64
+ ],
65
+ 'default': DEFAULT_CONFIG['method'],
66
+ 'help': 'Edge detection algorithm'
67
+ },
68
+ {
69
+ 'name': 'threshold1',
70
+ 'label': 'Threshold 1',
71
+ 'type': 'number',
72
+ 'default': DEFAULT_CONFIG['threshold1'],
73
+ 'min': 0,
74
+ 'max': 500,
75
+ 'help': 'First threshold for Canny hysteresis',
76
+ 'showIf': {'method': 'canny'}
77
+ },
78
+ {
79
+ 'name': 'threshold2',
80
+ 'label': 'Threshold 2',
81
+ 'type': 'number',
82
+ 'default': DEFAULT_CONFIG['threshold2'],
83
+ 'min': 0,
84
+ 'max': 500,
85
+ 'help': 'Second threshold for Canny hysteresis',
86
+ 'showIf': {'method': 'canny'}
87
+ },
88
+ {
89
+ 'name': 'aperture_size',
90
+ 'label': 'Aperture Size',
91
+ 'type': 'number',
92
+ 'default': DEFAULT_CONFIG['aperture_size'],
93
+ 'min': 3,
94
+ 'max': 7,
95
+ 'help': 'Aperture size for Sobel operator (3, 5, or 7)',
96
+ 'showIf': {'method': ['canny', 'sobel', 'laplacian']}
97
+ },
98
+ {
99
+ 'name': 'sobel_direction',
100
+ 'label': 'Sobel Direction',
101
+ 'type': 'select',
102
+ 'options': [
103
+ {'value': 'both', 'label': 'Both X and Y'},
104
+ {'value': 'x', 'label': 'X only'},
105
+ {'value': 'y', 'label': 'Y only'}
106
+ ],
107
+ 'default': DEFAULT_CONFIG['sobel_direction'],
108
+ 'help': 'Direction for Sobel/Scharr edge detection',
109
+ 'showIf': {'method': ['sobel', 'scharr']}
110
+ },
111
+ {
112
+ 'name': 'l2_gradient',
113
+ 'label': 'L2 Gradient (Canny)',
114
+ 'type': 'select',
115
+ 'options': [
116
+ {'value': 'yes', 'label': 'Yes (more accurate)'},
117
+ {'value': 'no', 'label': 'No (faster)'}
118
+ ],
119
+ 'default': DEFAULT_CONFIG['l2_gradient'],
120
+ 'help': 'Use L2 norm for Canny gradient calculation',
121
+ 'showIf': {'method': 'canny'}
122
+ }
123
+ ]
124
+
125
+ def __init__(self, node_id=None, name="edge detector"):
126
+ super().__init__(node_id, name)
127
+
128
+ @process_image()
129
+ def on_input(self, image: np.ndarray, msg: Dict[str, Any], input_index: int = 0):
130
+ """Detect edges in the input image."""
131
+ method = self.config.get('method', 'canny')
132
+ threshold1 = self.get_config_int('threshold1', 100)
133
+ threshold2 = self.get_config_int('threshold2', 200)
134
+ aperture = self.get_config_int('aperture_size', 3)
135
+ direction = self.config.get('sobel_direction', 'both')
136
+ l2_gradient = self.get_config_bool('l2_gradient', False)
137
+
138
+ # Ensure aperture is valid (3, 5, or 7)
139
+ if aperture not in [3, 5, 7]:
140
+ aperture = 3
141
+
142
+ # Convert to grayscale if needed
143
+ if len(image.shape) == 3:
144
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
145
+ else:
146
+ gray = image
147
+
148
+ if method == 'canny':
149
+ result = cv2.Canny(gray, threshold1, threshold2,
150
+ apertureSize=aperture, L2gradient=l2_gradient)
151
+ elif method == 'sobel':
152
+ if direction == 'x':
153
+ result = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=aperture)
154
+ elif direction == 'y':
155
+ result = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=aperture)
156
+ else:
157
+ sobel_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=aperture)
158
+ sobel_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=aperture)
159
+ result = cv2.magnitude(sobel_x, sobel_y)
160
+ result = np.uint8(np.absolute(result))
161
+ elif method == 'laplacian':
162
+ result = cv2.Laplacian(gray, cv2.CV_64F, ksize=aperture)
163
+ result = np.uint8(np.absolute(result))
164
+ elif method == 'scharr':
165
+ if direction == 'x':
166
+ result = cv2.Scharr(gray, cv2.CV_64F, 1, 0)
167
+ elif direction == 'y':
168
+ result = cv2.Scharr(gray, cv2.CV_64F, 0, 1)
169
+ else:
170
+ scharr_x = cv2.Scharr(gray, cv2.CV_64F, 1, 0)
171
+ scharr_y = cv2.Scharr(gray, cv2.CV_64F, 0, 1)
172
+ result = cv2.magnitude(scharr_x, scharr_y)
173
+ result = np.uint8(np.absolute(result))
174
+ else:
175
+ result = gray
176
+
177
+ return result
@@ -0,0 +1,447 @@
1
+ """
2
+ Equirectangular to Pinhole Projection Node - converts 360° equirectangular images to standard pinhole camera views.
3
+ Uses optimized Numba JIT compilation for high-performance coordinate mapping.
4
+ """
5
+
6
+ import math
7
+ import cv2
8
+ import numpy as np
9
+ from typing import Any, Dict, Tuple
10
+ from pynode.nodes.base_node import BaseNode, Info, MessageKeys
11
+
12
+ _info = Info()
13
+ _info.add_text("Converts 360° equirectangular images to standard pinhole camera perspective views. Uses optimized Numba JIT compilation for high-performance coordinate mapping when available.")
14
+ _info.add_header("Inputs")
15
+ _info.add_bullets(
16
+ ("Input 0:", "Equirectangular (360°) image frame")
17
+ )
18
+ _info.add_header("Outputs")
19
+ _info.add_bullets(
20
+ ("Output 0:", "Projected pinhole camera view image")
21
+ )
22
+ _info.add_header("Configuration")
23
+ _info.add_bullets(
24
+ ("Yaw:", "Horizontal rotation angle (-180° to 180°)"),
25
+ ("Pitch:", "Vertical rotation angle (-90° to 90°)"),
26
+ ("Roll:", "Rotation around view axis (-180° to 180°)"),
27
+ ("FOV:", "Field of view in degrees (1° to 179°)"),
28
+ ("Output Width/Height:", "Resolution of the projected output image"),
29
+ ("Angle Source:", "Use config values or read from msg.angles"),
30
+ ("Interpolation:", "Nearest, Linear, or Cubic sampling")
31
+ )
32
+
33
+ # Check for Numba availability
34
+ try:
35
+ from numba import njit, prange
36
+ _HAS_NUMBA = True
37
+ except ImportError:
38
+ _HAS_NUMBA = False
39
+
40
+
41
+ # Numba JIT-compiled functions for maximum performance
42
+ if _HAS_NUMBA:
43
+ @njit(cache=True, fastmath=True)
44
+ def _generate_mapping_jit(output_width, output_height, focal_length, cx, cy,
45
+ R00, R01, R02, R10, R11, R12, R20, R21, R22,
46
+ frame_height, frame_width):
47
+ """JIT-compiled coordinate mapping generation for maximum speed"""
48
+ pixel_x = np.empty((output_height, output_width), dtype=np.float32)
49
+ pixel_y = np.empty((output_height, output_width), dtype=np.float32)
50
+
51
+ inv_focal = 1.0 / focal_length
52
+ inv_2pi = 1.0 / (2.0 * np.pi)
53
+ inv_pi = 1.0 / np.pi
54
+ half_pi = np.pi * 0.5
55
+ frame_width_minus_1 = frame_width - 1
56
+ frame_height_minus_1 = frame_height - 1
57
+
58
+ for j in range(output_height):
59
+ y_norm = (j - cy) * inv_focal
60
+ for i in range(output_width):
61
+ x_norm = (i - cx) * inv_focal
62
+
63
+ norm_factor = 1.0 / math.sqrt(x_norm * x_norm + y_norm * y_norm + 1.0)
64
+ x_unit = x_norm * norm_factor
65
+ y_unit = y_norm * norm_factor
66
+ z_unit = norm_factor
67
+
68
+ x_rot = R00 * x_unit + R01 * y_unit + R02 * z_unit
69
+ y_rot = R10 * x_unit + R11 * y_unit + R12 * z_unit
70
+ z_rot = R20 * x_unit + R21 * y_unit + R22 * z_unit
71
+
72
+ theta = math.atan2(x_rot, z_rot)
73
+ phi = math.asin(max(-1.0, min(1.0, y_rot)))
74
+
75
+ u = (theta + np.pi) * inv_2pi
76
+ v = (phi + half_pi) * inv_pi
77
+
78
+ pixel_x[j, i] = max(0.0, min(frame_width_minus_1, u * frame_width_minus_1))
79
+ pixel_y[j, i] = max(0.0, min(frame_height_minus_1, v * frame_height_minus_1))
80
+
81
+ return pixel_x, pixel_y
82
+
83
+ @njit(cache=True, fastmath=True, parallel=True)
84
+ def _generate_mapping_jit_parallel(output_width, output_height, focal_length, cx, cy,
85
+ R00, R01, R02, R10, R11, R12, R20, R21, R22,
86
+ frame_height, frame_width):
87
+ """Parallel JIT-compiled coordinate mapping for multi-core systems"""
88
+ pixel_x = np.empty((output_height, output_width), dtype=np.float32)
89
+ pixel_y = np.empty((output_height, output_width), dtype=np.float32)
90
+
91
+ inv_focal = 1.0 / focal_length
92
+ inv_2pi = 0.15915494309189535
93
+ inv_pi = 0.3183098861837907
94
+ half_pi = 1.5707963267948966
95
+ frame_width_f = float(frame_width - 1)
96
+ frame_height_f = float(frame_height - 1)
97
+ pi = 3.141592653589793
98
+
99
+ total_pixels = output_height * output_width
100
+
101
+ for idx in prange(total_pixels):
102
+ j = idx // output_width
103
+ i = idx % output_width
104
+
105
+ x_norm = (i - cx) * inv_focal
106
+ y_norm = (j - cy) * inv_focal
107
+
108
+ norm_factor = 1.0 / math.sqrt(x_norm * x_norm + y_norm * y_norm + 1.0)
109
+ x_unit = x_norm * norm_factor
110
+ y_unit = y_norm * norm_factor
111
+ z_unit = norm_factor
112
+
113
+ x_rot = R00 * x_unit + R01 * y_unit + R02 * z_unit
114
+ y_rot = R10 * x_unit + R11 * y_unit + R12 * z_unit
115
+ z_rot = R20 * x_unit + R21 * y_unit + R22 * z_unit
116
+
117
+ theta = math.atan2(x_rot, z_rot)
118
+ phi = math.asin(max(-1.0, min(1.0, y_rot)))
119
+
120
+ u = (theta + pi) * inv_2pi
121
+ v = (phi + half_pi) * inv_pi
122
+
123
+ pixel_x[j, i] = max(0.0, min(frame_width_f, u * frame_width_f))
124
+ pixel_y[j, i] = max(0.0, min(frame_height_f, v * frame_height_f))
125
+
126
+ return pixel_x, pixel_y
127
+
128
+
129
+ class EquirectangularNode(BaseNode):
130
+ """
131
+ Equirectangular to Pinhole Projection node - converts 360° equirectangular images
132
+ to standard pinhole camera perspective views with configurable yaw, pitch, roll, and FOV.
133
+ """
134
+ info = str(_info)
135
+ display_name = 'Equirectangular'
136
+ icon = '🌐'
137
+ category = 'opencv'
138
+ color = '#4A90D9'
139
+ border_color = '#2E6BB0'
140
+ text_color = '#FFFFFF'
141
+ input_count = 1
142
+ output_count = 1
143
+
144
+ DEFAULT_CONFIG = {
145
+ 'yaw': 0,
146
+ 'pitch': 0,
147
+ 'roll': 0,
148
+ 'fov': 90,
149
+ 'output_width': 1920,
150
+ 'output_height': 1080,
151
+ 'angle_source': 'config',
152
+ 'interpolation': 'linear'
153
+ }
154
+
155
+ properties = [
156
+ {
157
+ 'name': 'yaw',
158
+ 'label': 'Yaw (°)',
159
+ 'type': 'number',
160
+ 'default': DEFAULT_CONFIG['yaw'],
161
+ 'min': -180,
162
+ 'max': 180,
163
+ 'step': 1,
164
+ 'help': 'Horizontal rotation (-180 to 180)'
165
+ },
166
+ {
167
+ 'name': 'pitch',
168
+ 'label': 'Pitch (°)',
169
+ 'type': 'number',
170
+ 'default': DEFAULT_CONFIG['pitch'],
171
+ 'min': -90,
172
+ 'max': 90,
173
+ 'step': 1,
174
+ 'help': 'Vertical rotation (-90 to 90)'
175
+ },
176
+ {
177
+ 'name': 'roll',
178
+ 'label': 'Roll (°)',
179
+ 'type': 'number',
180
+ 'default': DEFAULT_CONFIG['roll'],
181
+ 'min': -180,
182
+ 'max': 180,
183
+ 'step': 1,
184
+ 'help': 'Roll rotation (-180 to 180)'
185
+ },
186
+ {
187
+ 'name': 'fov',
188
+ 'label': 'Field of View (°)',
189
+ 'type': 'number',
190
+ 'default': DEFAULT_CONFIG['fov'],
191
+ 'min': 10,
192
+ 'max': 170,
193
+ 'step': 5,
194
+ 'help': 'Field of view angle'
195
+ },
196
+ {
197
+ 'name': 'output_width',
198
+ 'label': 'Output Width',
199
+ 'type': 'number',
200
+ 'default': DEFAULT_CONFIG['output_width'],
201
+ 'min': 64,
202
+ 'max': 4096,
203
+ 'help': 'Width of output image'
204
+ },
205
+ {
206
+ 'name': 'output_height',
207
+ 'label': 'Output Height',
208
+ 'type': 'number',
209
+ 'default': DEFAULT_CONFIG['output_height'],
210
+ 'min': 64,
211
+ 'max': 4096,
212
+ 'help': 'Height of output image'
213
+ },
214
+ {
215
+ 'name': 'angle_source',
216
+ 'label': 'Angle Source',
217
+ 'type': 'select',
218
+ 'options': [
219
+ {'value': 'config', 'label': 'From config'},
220
+ {'value': 'msg', 'label': 'From message (msg.yaw, msg.pitch, msg.roll)'}
221
+ ],
222
+ 'default': DEFAULT_CONFIG['angle_source'],
223
+ 'help': 'Source for yaw/pitch/roll values'
224
+ },
225
+ {
226
+ 'name': 'interpolation',
227
+ 'label': 'Interpolation',
228
+ 'type': 'select',
229
+ 'options': [
230
+ {'value': 'linear', 'label': 'Bilinear (fast)'},
231
+ {'value': 'cubic', 'label': 'Bicubic (quality)'},
232
+ {'value': 'lanczos', 'label': 'Lanczos (best quality)'}
233
+ ],
234
+ 'default': DEFAULT_CONFIG['interpolation'],
235
+ 'help': 'Interpolation method for remapping'
236
+ }
237
+ ]
238
+
239
+ def __init__(self, node_id=None, name="equirectangular"):
240
+ super().__init__(node_id, name)
241
+
242
+ # Coordinate mapping cache
243
+ self._map_cache = {}
244
+ self._cache_size_limit = 20
245
+
246
+ def on_input(self, msg: Dict[str, Any], input_index: int = 0):
247
+ """Convert equirectangular image to pinhole projection."""
248
+ if MessageKeys.PAYLOAD not in msg:
249
+ self.send(msg)
250
+ return
251
+
252
+ # Decode image from any supported format
253
+ img, format_type = self.decode_image(msg[MessageKeys.PAYLOAD])
254
+ if img is None:
255
+ self.report_error("Could not decode image from payload")
256
+ self.send(msg)
257
+ return
258
+
259
+ # Get angles from config or message
260
+ angle_source = self.config.get('angle_source', 'config')
261
+ if angle_source == 'msg':
262
+ yaw = float(msg.get('yaw', self.config.get('yaw', 0)))
263
+ pitch = float(msg.get('pitch', self.config.get('pitch', 0)))
264
+ roll = float(msg.get('roll', self.config.get('roll', 0)))
265
+ else:
266
+ yaw = self.get_config_float('yaw', 0)
267
+ pitch = self.get_config_float('pitch', 0)
268
+ roll = self.get_config_float('roll', 0)
269
+
270
+ fov = self.get_config_float('fov', 90)
271
+ output_width = self.get_config_int('output_width', 1920)
272
+ output_height = self.get_config_int('output_height', 1080)
273
+
274
+ # Normalize angles for consistent caching
275
+ norm_yaw, norm_pitch, norm_roll = self._normalize_angles(yaw, pitch, roll)
276
+
277
+ # Create cache key
278
+ cache_key = (norm_yaw, norm_pitch, norm_roll, fov, output_width, output_height,
279
+ img.shape[0], img.shape[1])
280
+
281
+ # Check cache for coordinate mapping
282
+ if cache_key in self._map_cache:
283
+ pixel_x, pixel_y = self._map_cache[cache_key]
284
+ else:
285
+ # Generate new mapping
286
+ pixel_x, pixel_y = self._generate_coordinate_mapping(
287
+ norm_yaw, norm_pitch, norm_roll, fov, output_width, output_height, img.shape
288
+ )
289
+
290
+ # Cache management
291
+ if len(self._map_cache) >= self._cache_size_limit:
292
+ oldest_key = next(iter(self._map_cache))
293
+ del self._map_cache[oldest_key]
294
+
295
+ self._map_cache[cache_key] = (pixel_x, pixel_y)
296
+
297
+ # Get interpolation method
298
+ interp_str = self.config.get('interpolation', 'linear')
299
+ interp_map = {
300
+ 'linear': cv2.INTER_LINEAR,
301
+ 'cubic': cv2.INTER_CUBIC,
302
+ 'lanczos': cv2.INTER_LANCZOS4
303
+ }
304
+ interpolation = interp_map.get(interp_str, cv2.INTER_LINEAR)
305
+
306
+ # Apply remapping
307
+ result = cv2.remap(img, pixel_x, pixel_y, interpolation, borderMode=cv2.BORDER_WRAP)
308
+
309
+ # Encode back to original format
310
+ if MessageKeys.PAYLOAD not in msg or not isinstance(msg[MessageKeys.PAYLOAD], dict):
311
+ msg[MessageKeys.PAYLOAD] = {}
312
+ msg[MessageKeys.PAYLOAD][MessageKeys.IMAGE.PATH] = self.encode_image(result, format_type)
313
+
314
+ # Add projection info to message
315
+ msg['projection'] = {
316
+ 'yaw': yaw,
317
+ 'pitch': pitch,
318
+ 'roll': roll,
319
+ 'fov': fov,
320
+ 'output_size': [output_width, output_height]
321
+ }
322
+
323
+ self.send(msg)
324
+
325
+ def _generate_coordinate_mapping(self, yaw: float, pitch: float, roll: float, fov: float,
326
+ output_width: int, output_height: int,
327
+ frame_shape: Tuple[int, ...]) -> Tuple[np.ndarray, np.ndarray]:
328
+ """Generate coordinate mapping for equirectangular to pinhole projection."""
329
+ # Convert to radians
330
+ yaw_rad = math.radians(yaw)
331
+ pitch_rad = math.radians(pitch)
332
+ roll_rad = math.radians(roll)
333
+ fov_rad = math.radians(fov)
334
+
335
+ # Calculate focal length and center
336
+ focal_length = output_width / (2 * math.tan(fov_rad / 2))
337
+ cx = output_width * 0.5
338
+ cy = output_height * 0.5
339
+
340
+ # Create rotation matrix elements
341
+ cos_r, sin_r = math.cos(roll_rad), math.sin(roll_rad)
342
+ cos_p, sin_p = math.cos(pitch_rad), math.sin(pitch_rad)
343
+ cos_y, sin_y = math.cos(yaw_rad), math.sin(yaw_rad)
344
+
345
+ # Combined rotation matrix elements
346
+ R00 = cos_y * cos_r + sin_y * sin_r * sin_p
347
+ R01 = cos_y * (-sin_r) + sin_y * cos_r * sin_p
348
+ R02 = sin_y * cos_p
349
+ R10 = sin_r * cos_p
350
+ R11 = cos_r * cos_p
351
+ R12 = -sin_p
352
+ R20 = -sin_y * cos_r + cos_y * sin_r * sin_p
353
+ R21 = -sin_y * (-sin_r) + cos_y * cos_r * sin_p
354
+ R22 = cos_y * cos_p
355
+
356
+ # Choose implementation based on Numba availability and output size
357
+ total_pixels = output_width * output_height
358
+
359
+ if _HAS_NUMBA:
360
+ if total_pixels > 500000:
361
+ return _generate_mapping_jit_parallel(
362
+ output_width, output_height, focal_length, cx, cy,
363
+ R00, R01, R02, R10, R11, R12, R20, R21, R22,
364
+ frame_shape[0], frame_shape[1]
365
+ )
366
+ else:
367
+ return _generate_mapping_jit(
368
+ output_width, output_height, focal_length, cx, cy,
369
+ R00, R01, R02, R10, R11, R12, R20, R21, R22,
370
+ frame_shape[0], frame_shape[1]
371
+ )
372
+ else:
373
+ # Pure NumPy fallback (slower but works without Numba)
374
+ return self._generate_mapping_numpy(
375
+ output_width, output_height, focal_length, cx, cy,
376
+ R00, R01, R02, R10, R11, R12, R20, R21, R22,
377
+ frame_shape[0], frame_shape[1]
378
+ )
379
+
380
+ def _generate_mapping_numpy(self, output_width, output_height, focal_length, cx, cy,
381
+ R00, R01, R02, R10, R11, R12, R20, R21, R22,
382
+ frame_height, frame_width):
383
+ """Pure NumPy fallback for coordinate mapping (no Numba required)."""
384
+ # Create coordinate grids
385
+ i_coords = np.arange(output_width, dtype=np.float32)
386
+ j_coords = np.arange(output_height, dtype=np.float32)
387
+ i_grid, j_grid = np.meshgrid(i_coords, j_coords)
388
+
389
+ # Normalize coordinates
390
+ x_norm = (i_grid - cx) / focal_length
391
+ y_norm = (j_grid - cy) / focal_length
392
+
393
+ # Normalize direction vectors
394
+ norm_factor = 1.0 / np.sqrt(x_norm**2 + y_norm**2 + 1.0)
395
+ x_unit = x_norm * norm_factor
396
+ y_unit = y_norm * norm_factor
397
+ z_unit = norm_factor
398
+
399
+ # Apply rotation matrix
400
+ x_rot = R00 * x_unit + R01 * y_unit + R02 * z_unit
401
+ y_rot = R10 * x_unit + R11 * y_unit + R12 * z_unit
402
+ z_rot = R20 * x_unit + R21 * y_unit + R22 * z_unit
403
+
404
+ # Convert to spherical coordinates
405
+ theta = np.arctan2(x_rot, z_rot)
406
+ phi = np.arcsin(np.clip(y_rot, -1.0, 1.0))
407
+
408
+ # Convert to pixel coordinates
409
+ u = (theta + np.pi) / (2 * np.pi)
410
+ v = (phi + np.pi / 2) / np.pi
411
+
412
+ pixel_x = np.clip(u * (frame_width - 1), 0, frame_width - 1).astype(np.float32)
413
+ pixel_y = np.clip(v * (frame_height - 1), 0, frame_height - 1).astype(np.float32)
414
+
415
+ return pixel_x, pixel_y
416
+
417
+ def _normalize_angles(self, yaw: float, pitch: float, roll: float) -> Tuple[float, float, float]:
418
+ """Normalize angles to canonical ranges for cache consistency."""
419
+ # Normalize yaw to [0, 360)
420
+ yaw = yaw % 360
421
+
422
+ # Normalize pitch properly
423
+ pitch = ((pitch + 180) % 360) - 180
424
+
425
+ # Handle pitch overflow beyond valid range [-90, 90]
426
+ if pitch > 90:
427
+ pitch = 180 - pitch
428
+ yaw = (yaw + 180) % 360
429
+ roll = (roll + 180) % 360
430
+ elif pitch < -90:
431
+ pitch = -180 - pitch
432
+ yaw = (yaw + 180) % 360
433
+ roll = (roll + 180) % 360
434
+
435
+ # Normalize roll to [0, 360)
436
+ roll = roll % 360
437
+
438
+ return yaw, pitch, roll
439
+
440
+ def clear_cache(self):
441
+ """Clear the coordinate mapping cache."""
442
+ self._map_cache.clear()
443
+
444
+ def on_stop(self):
445
+ """Clean up when node is stopped."""
446
+ self.clear_cache()
447
+ super().on_stop()