Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

cameras are fun :D

Jon32def4b61fb1
diff --git a/requirements.txt b/requirements.txt
index 12cd626c..04ce3d77 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@ aniposelib==0.4.3
h5py>=3.1.0
imutils~=0.5.4
matplotlib~=3.1.3
-mediapipe==0.8.8
+# mediapipe==0.8.8
opencv-contrib-python==4.5.5.62
pandas~=1.2.5
rich~=10.4.0
diff --git a/src/core_processor/board_detection/detect.py b/src/core_processor/board_detection/detect.py
index e8274472..c2bc2fed 100644
--- a/src/core_processor/board_detection/detect.py
+++ b/src/core_processor/board_detection/detect.py
@@ -1,12 +1,23 @@
import logging
import cv2
+import numpy as np
+
from aiomultiprocess import Process
from aiomultiprocess.types import Queue
from src.core_processor.processor import ImagePayload
-logger = logging.getLogger(__name__)
+
+from rich import inspect
+
+
+# aruco_dict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_250)
+# charuco_length = 7
+# charuco_width = 5
+
+# board = cv2.aruco.CharucoBoard_create(charuco_length, charuco_width, 1, .8, aruco_dict)
+# num_charuco_corners = (charuco_length-1) * (charuco_width-1)
class BoardDetection:
@@ -17,47 +28,62 @@ class BoardDetection:
await p.join()
async def process(self, queue: Queue):
+ logger = logging.getLogger(__name__)
while True:
+ message = None
try:
message = queue.get(timeout=1) # type: ImagePayload
- frames = message.frames
- for f in frames:
- cv2.imshow(str(f.port_number), f.image)
- exit_key = cv2.waitKey(1)
- if exit_key == 27:
- break
except Exception as e:
- print(e)
- logger.error(e)
-
- # def detect_charuco_board(self, image):
- # """
- # Charuco base pose estimation.
- # more-or-less copied from - https://mecaruco2.readthedocs.io/en/latest/notebooks_rst/Aruco
- # /sandbox/ludovic/aruco_calibration_rotation.html
- # """
- # charuco_corners = []
- # charuco_ids = []
- #
- # # SUB PIXEL CORNER DETECTION CRITERION
- # criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.00001)
- #
- # gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- # aruco_square_corners, aruco_square_ids, rejectedImgPoints = cv2.aruco.detectMarkers(gray,
- # aruco_dict)
- #
- # if len(aruco_square_corners) > 0:
- # # SUB PIXEL DETECTION
- # for this_corner in aruco_square_corners:
- # cv2.cornerSubPix(gray, this_corner,
- # winSize=(3, 3),
- # zeroZone=(-1, -1),
- # criteria=criteria)
- # res2 = cv2.aruco.interpolateCornersCharuco(aruco_square_corners, aruco_square_ids, gray,
- # board)
- #
- # if res2[1] is not None and res2[2] is not None and len(res2[1]) > 3:
- # charuco_corners = res2[1]
- # charuco_ids = res2[2]
- #
- # return charuco_corners, charuco_ids, aruco_square_corners, aruco_square_ids
+ pass
+ print('got message from the queue')
+
+
+
+ if not message:
+ continue
+
+ frames = message.frames
+ print(f'got image of shape {f.image.shape}')
+
+ for f in frames:
+ # charuco_corners, charuco_ids, aruco_square_corners, aruco_square_ids = self.detect_charuco_board(f.image)
+ # cv2.polylines(f.image, np.int32([charuco_corners]), True, (0,100,255), 2)
+
+ cv2.imshow(str(f.port_number), f.image)
+ exit_key = cv2.waitKey(1)
+ if exit_key == 27:
+ break
+
+
+ def detect_charuco_board(self, image):
+ """
+ Charuco base pose estimation.
+ more-or-less copied from - https://mecaruco2.readthedocs.io/en/latest/notebooks_rst/Aruco
+ /sandbox/ludovic/aruco_calibration_rotation.html
+ """
+ charuco_corners = []
+ charuco_ids = []
+
+ # SUB PIXEL CORNER DETECTION CRITERION
+ criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.00001)
+
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+ aruco_square_corners, aruco_square_ids, rejectedImgPoints = cv2.aruco.detectMarkers(gray,
+ aruco_dict)
+
+ if len(aruco_square_corners) > 0:
+ # SUB PIXEL DETECTION
+ for this_corner in aruco_square_corners:
+ cv2.cornerSubPix(gray, this_corner,
+ winSize=(3, 3),
+ zeroZone=(-1, -1),
+ criteria=criteria)
+ res2 = cv2.aruco.interpolateCornersCharuco(aruco_square_corners, aruco_square_ids, gray,
+ board)
+
+ if res2[1] is not None and res2[2] is not None and len(res2[1]) > 3:
+ charuco_corners = res2[1]
+ charuco_ids = res2[2]
+
+ return charuco_corners, charuco_ids, aruco_square_corners, aruco_square_ids
+
diff --git a/src/core_processor/processor.py b/src/core_processor/processor.py
index 0a9a2c53..f1b2011c 100644
--- a/src/core_processor/processor.py
+++ b/src/core_processor/processor.py
@@ -53,6 +53,7 @@ class CameraCaptureProcess:
image_list: List[FramePayload] = []
for cv_cam in cv_cams:
success, image, timestamp = cv_cam.get_next_frame()
+
if not success:
continue
if image is None:
@@ -67,4 +68,4 @@ class CameraCaptureProcess:
_queue.put(
ImagePayload(frames=image_list)
)
- # _logger.info("Im printing stuff")
+ _logger.info("Im printing stuff")