Skip to content

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

TypeScript

new camera class setup

Endurance Idehena2f99b6136b6
diff --git a/bin/run_uvicorn_server.sh b/bin/run_uvicorn_server.sh
index 5fd0c524..2290cd31 100755
--- a/bin/run_uvicorn_server.sh
+++ b/bin/run_uvicorn_server.sh
@@ -4,3 +4,4 @@
uvicorn --factory src.api.app_factory:create_app --port 8080 --host 0.0.0.0 --reload
+
diff --git a/freemocap/__init__.py b/freemocap/__init__.py
index d089c90c..1a0524c7 100644
--- a/freemocap/__init__.py
+++ b/freemocap/__init__.py
@@ -3,8 +3,8 @@ from ._version import get_versions
__version__ = get_versions()["version"]
del get_versions
-from freemocap.fmc_runme import RunMe
-from freemocap import fmc_demo, fmc_runme
+# from freemocap.fmc_runme import RunMe
+# from freemocap import fmc_demo, fmc_runme
# from freemocap import fmc_runme, fmc_demo #JSM NOTE - there's gotta be a better way to do this lol
@@ -37,10 +37,10 @@ from freemocap import fmc_demo, fmc_runme
# userDataPath,
# recordVid)
-def RunDemo():
- """
- Will (eventually) download sample data from Figshare, and run the animation for it
- """
- sample_data_location, sample_data_name = fmc_demo.DemoSetup() #run a bunch of GUIs, get the location of the directory where the data folder with the sample data is
- #fmc_runme.RunMe(sessionID = sample_data_name,stage = 5,useOpenPose = False, useMediaPipe = True,useDLC = True, userDataPath = sample_data_location)
+# def RunDemo():
+# """
+# Will (eventually) download sample data from Figshare, and run the animation for it
+# """
+# sample_data_location, sample_data_name = fmc_demo.DemoSetup() #run a bunch of GUIs, get the location of the directory where the data folder with the sample data is
+# #fmc_runme.RunMe(sessionID = sample_data_name,stage = 5,useOpenPose = False, useMediaPipe = True,useDLC = True, userDataPath = sample_data_location)
diff --git a/freemocap/prod/__init__.py b/freemocap/prod/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/freemocap/prod/cam/__init__.py b/freemocap/prod/cam/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/freemocap/prod/cam/cam_detection.py b/freemocap/prod/cam/cam_detection.py
new file mode 100644
index 00000000..b5b980b9
--- /dev/null
+++ b/freemocap/prod/cam/cam_detection.py
@@ -0,0 +1,45 @@
+import logging
+from typing import List
+
+import cv2
+from pydantic import BaseModel
+
+CAM_CHECK_NUM = 5
+
+logger = logging.getLogger(__name__)
+
+
+class RawCamera(BaseModel):
+ name: str
+ index: int
+
+
+class FindAvailableResponse(BaseModel):
+ camera_found_count: int
+ cams_to_use: List[RawCamera]
+
+
+class DetectPossibleCameras:
+
+ def find_available_cameras(self) -> FindAvailableResponse:
+ capBackend = cv2.CAP_ANY
+
+ cams_to_use_list = []
+ for camNum in range(CAM_CHECK_NUM):
+ cap = cv2.VideoCapture(camNum, capBackend)
+ success, image = cap.read()
+ if success:
+ cams_to_use_list.append(RawCamera(
+ index=camNum,
+ name='test'
+ ))
+ cap.release()
+ logger.info("I was successful")
+ logger.info(cap.get(cv2.CAP_PROP_SETTINGS))
+
+ return FindAvailableResponse(
+ camera_found_count=len(cams_to_use_list),
+ cams_to_use=cams_to_use_list
+ )
+
+
diff --git a/freemocap/prod/cam/camera.py b/freemocap/prod/cam/camera.py
new file mode 100644
index 00000000..7b1ecf39
--- /dev/null
+++ b/freemocap/prod/cam/camera.py
@@ -0,0 +1,12 @@
+
+
+# Single Responsibility
+
+# Open a stream between the computer and a camera?
+# Open a connection to a usb attached webcam using OpenCV
+# Feeds frames to someone else
+class Camera:
+
+ def __init__(self):
+ pass
+
diff --git a/freemocap/prod/cam/opencv_camera.py b/freemocap/prod/cam/opencv_camera.py
new file mode 100644
index 00000000..d2b92444
--- /dev/null
+++ b/freemocap/prod/cam/opencv_camera.py
@@ -0,0 +1,20 @@
+import cv2
+from pydantic import BaseModel
+
+
+class OpenCVCameraOptions(BaseModel):
+ port_number: int
+ exposure: int = -5
+ resolution_width: int = 1280
+ resolution_height: int = 720
+
+
+# # OpenCV Implementation of interacting with a camera
+# class OpenCVCamera:
+#
+# def __init__(self, options: OpenCVCameraOptions):
+# self._options = options
+#
+# def connect(self):
+# # c = cv2.VideoCapture()
+# cv2.VideoCapture(, cv2.CAP_ANY)
diff --git a/requirements.txt b/requirements.txt
index c6465a83..65b021df 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -16,4 +16,6 @@ pydantic==1.9.0
uvicorn==0.16.0
fastapi==0.71.0
gunicorn==20.1.0
-requests==2.27.1
\ No newline at end of file
+requests==2.27.1
+# opencv-python-headless==4.5.5.62
+# opencv-python
\ No newline at end of file
diff --git a/src/__init__.py b/src/__init__.py
index e69de29b..6a6ca888 100644
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -0,0 +1,3 @@
+from src.config import configure_logging
+
+configure_logging()
diff --git a/src/api/app_factory.py b/src/api/app_factory.py
index 0e1974d2..bd972cc1 100644
--- a/src/api/app_factory.py
+++ b/src/api/app_factory.py
@@ -1,3 +1,4 @@
+import uvicorn
from fastapi import FastAPI
from src.api.routes import enabled_routers
@@ -10,3 +11,8 @@ def create_app():
app.include_router(router)
return app
+
+
+if __name__ == "__main__":
+ app = create_app()
+ uvicorn.run(app, host="127.0.0.1", port=5000, log_level="info")
diff --git a/src/api/routes/__init__.py b/src/api/routes/__init__.py
index 7a73bf20..266b2cc6 100644
--- a/src/api/routes/__init__.py
+++ b/src/api/routes/__init__.py
@@ -1,3 +1,8 @@
+from src.api.routes.camera.camera_route import camera_router
from src.api.routes.health.health_check_route import healthcheck_router
-enabled_routers = [healthcheck_router]
+# REGISTER NEW ROUTES HERE
+enabled_routers = [
+ healthcheck_router,
+ camera_router
+]
diff --git a/src/api/routes/camera/__init__.py b/src/api/routes/camera/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/api/routes/camera/camera_route.py b/src/api/routes/camera/camera_route.py
new file mode 100644
index 00000000..5d237161
--- /dev/null
+++ b/src/api/routes/camera/camera_route.py
@@ -0,0 +1,12 @@
+from fastapi import APIRouter
+from freemocap.prod.cam.cam_detection import DetectPossibleCameras
+
+# Make a router
+camera_router = APIRouter()
+
+
+# create an endpoint
+@camera_router.get("/camera/detect")
+def camera_detect():
+ dpc = DetectPossibleCameras()
+ return dpc.find_available_cameras()
diff --git a/src/config.py b/src/config.py
new file mode 100644
index 00000000..5966b8d5
--- /dev/null
+++ b/src/config.py
@@ -0,0 +1,43 @@
+
+
+import logging
+import logging.handlers
+import sys
+from logging.config import dictConfig
+
+
+DEFAULT_LOGGING = {"version": 1, "disable_existing_loggers": False}
+
+
+def get_logging_handlers():
+ """
+ Initialize logging defaults for Project.
+ :param logfile_path: logfile used to the logfile
+ :type logfile_path: string
+ This function does:
+ - Assign INFO and DEBUG level to logger file handler and console handler
+ """
+ dictConfig(DEFAULT_LOGGING)
+
+ default_formatter = logging.Formatter(
+ "[%(asctime)s] [%(levelname)8s] [%(name)s] [%(funcName)s():%(lineno)s] [PID:%(process)d "
+ "TID:%(thread)d] %(message)s",
+ "%d/%m/%Y %H:%M:%S",
+ )
+
+ console_handler = logging.StreamHandler(sys.stdout)
+ console_handler.setLevel(logging.DEBUG)
+ console_handler.setFormatter(default_formatter)
+
+ return [console_handler]
+
+
+def configure_logging():
+ handlers = get_logging_handlers()
+ logging.getLogger("").handlers.extend(handlers)
+ logging.root.setLevel(logging.DEBUG)
+
+
+def disable_flask_logging(flask_app):
+ flask_app.logger.handlers = []
+ flask_app.logger.propagate = False
\ No newline at end of file