Skip to content

Commit

Permalink
Merge pull request #30 from shrimo/dev
Browse files Browse the repository at this point in the history
Added ChessboardDrawer
  • Loading branch information
shrimo authored Oct 7, 2024
2 parents 73d8ef2 + 6baa128 commit 0c28098
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 13 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ python3 -m pip install --upgrade opencv-python

```bash
cd SLAMBox
chmod 777 slambox.sh
./slambox.sh
bash slambox.sh
```

Or you can specify a custom version of Python

```bash
/slambox.sh 3.10
bash slambox.sh 3.10
```

<br>
Expand Down
5 changes: 3 additions & 2 deletions boxes/pipeline/graph_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclasses import dataclass, field
from collections import defaultdict, Counter
import numpy as np
from cv2 import destroyAllWindows # pylint: disable=E0611
from cv2 import destroyAllWindows # pylint: disable=E0611

from boxes import RootNode, plugins

Expand Down Expand Up @@ -46,6 +46,7 @@ def __init__(self, script: ActionScriptType, root_node: str):
"stop": self.stop,
"stop_flask": self.stop_flask,
}
self.top_nodes = ["ChessboardDrawer", "Constant"]

def execution_controller(self, input_script: ActionScriptType) -> None:
"""Controller for building a graph of nodes and control parameter updates"""
Expand All @@ -55,7 +56,7 @@ def graph_update(self, graph: RootNode, data_update: ScriptType) -> None:
"""Updating node graph in real time"""
if graph.get_input():
for node in graph.get_input():
if node.get_input():
if node.get_input() or node.type_ in self.top_nodes:
node_update = find_node_by_attr(data_update, node.id_, "id")
if node_update is None:
continue
Expand Down
67 changes: 62 additions & 5 deletions boxes/plugins/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def out_frame(self):
cv2.rectangle(frame, (20, height - 50), (180, height), (110, 50, 30), -1)
cv2.putText(
frame,
"frame:" + str(self.buffer.metadata['current_frame']),
"frame:" + str(self.buffer.metadata["current_frame"]),
(int(30), int(height - 20)),
self.font,
0.75,
Expand Down Expand Up @@ -163,16 +163,74 @@ def create_blank(self, width, height, color):

def update(self, param):
self.color = self.color_reversed(param["constant_color"])
self.width = int(param["width"])
self.height = int(param["height"])
self.width = int(param["width_"])
self.height = int(param["height_"])


class ChessboardDrawer(RootNode):
"""ChessboardDrawer background with specified color"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.color1 = self.color_reversed(self.param["color1"])
self.color2 = self.color_reversed(self.param["color2"])
self.width = int(self.param["width_"])
self.height = int(self.param["height_"])
self.grid_size_w = int(self.param["grid_size_w"])
self.grid_size_h = int(self.param["grid_size_h"])
self.square_calc()

def square_calc(self):
square_width = self.width // self.grid_size_w
square_height = self.height // self.grid_size_h
self.square_size = min(square_width, square_height) # Ensure square squares

def out_frame(self):
"""
Draws the calibration chessboard with square squares.
"""
rows, cols = self.grid_size_w, self.grid_size_h
img_height = rows * self.square_size
img_width = cols * self.square_size

# Create an empty image
chessboard_img = np.zeros((img_height, img_width, 3), dtype=np.uint8)

# Iterate through the grid and draw squares
for i in range(rows):
for j in range(cols):
# Determine the current square's color
if (i + j) % 2 == 0:
color = self.color1
else:
color = self.color2

# Calculate the top-left and bottom-right corners of the square
top_left = (j * self.square_size, i * self.square_size)
bottom_right = ((j + 1) * self.square_size, (i + 1) * self.square_size)

# Draw the square on the image
cv2.rectangle(chessboard_img, top_left, bottom_right, color, -1)

return chessboard_img

def update(self, param):
print("update")
self.color1 = self.color_reversed(param["color1"])
self.color2 = self.color_reversed(param["color2"])
self.width = int(param["width_"])
self.height = int(param["height_"])
self.grid_size_w = int(param["grid_size_w"])
self.grid_size_h = int(param["grid_size_h"])
self.square_calc()


class Text(RootNode):
"""Show FPS Information"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.color = self.color_reversed(self.param["text_color_"])
self.color = self.color_reversed(self.param["text_color_"])
self.text = self.param["text"]
self.px = int(self.param["px"])
self.py = int(self.param["py"])
Expand Down Expand Up @@ -235,4 +293,3 @@ def update(self, param):
self.size = int(param["size"])
self.track_color = self.color_reversed(param["track_color"])
self.variable = param["variable"]

1 change: 1 addition & 0 deletions boxes/utility/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Color:
kohlrabi: tuple = (101, 207, 156)
red_orange: tuple = (39, 83, 239)
high_visibility: tuple = (0, 199, 241)
scarlet_smile: tuple = (54, 36, 159)


cc = Color()
Expand Down
2 changes: 1 addition & 1 deletion build_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def build() -> None:
"OpenCV": {
"type": "Viewer",
"name": "Viewport",
"version_color": utility.rgb2bgr(cc.strong_blue),
"version_color": utility.rgb2bgr(cc.scarlet_smile),
"text_color": cc.white,
"title_text": f"SLAM box. version: {version}",
"builder": pipeline.GraphBuilder,
Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
port: int = 50001
recv_size: int = 10240
name: str = "SLAM Box"
version: str = "0.7.7"
version: str = "0.7.8"
system: str = platform.system()
gui: str = "Node-based UI"
description: str = "Computer Vision Node Graph Editor"
date: str = "(Sun Oct 6 05:27:06 AM EEST 2024)"
date: str = "(Mon Oct 7 06:27:01 AM EEST 2024)"
nodegraphqt: str = "./NodeGraphQt/"
css_style: str = "QLabel {background-color: #363636; color: white; font-size: 11pt;}"
g2opy_path: str = "/home/cds/github/g2o-pymem/build/lib"
21 changes: 21 additions & 0 deletions plugins_ui/draw_gui_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ def __init__(self):
self.add_text_input("width_", "Width", text="1280", tab="attributes")
self.add_text_input("height_", "Height", text="720", tab="attributes")

class ChessboardDrawer(BaseNode):
__identifier__ = "nodes.Draw"
NODE_NAME = "ChessboardDrawer"

def __init__(self):
super(ChessboardDrawer, self).__init__()
self.add_output("out")
self.set_color(*ncs.Draw)
self.create_property("label_color1", "Color1", widget_type=NODE_PROP_QLABEL)
self.create_property(
"color1", (0, 0, 0), widget_type=NODE_PROP_COLORPICKER
)
self.create_property("label_color2", "Color2", widget_type=NODE_PROP_QLABEL)
self.create_property(
"color2", (255, 255, 255), widget_type=NODE_PROP_COLORPICKER
)
self.add_text_input("width_", "Width", text="1280", tab="attributes")
self.add_text_input("height_", "Height", text="1280", tab="attributes")
self.add_text_input("grid_size_w", "Grid size Width", text="9", tab="attributes")
self.add_text_input("grid_size_h", "Grid size Height", text="16", tab="attributes")


class Text(BaseNode):
__identifier__ = "nodes.Draw"
Expand Down

0 comments on commit 0c28098

Please sign in to comment.