mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-01 02:41:42 +00:00
Fully merged CmerasHandler to SettingManger
hadn't the time to check, also refractord every use of cameras handler to settings manager, might have missed
This commit is contained in:
@@ -3,13 +3,10 @@ import tornado.ioloop
|
|||||||
from app.ChameleonVisionApp import ChameleonApplication
|
from app.ChameleonVisionApp import ChameleonApplication
|
||||||
from app.classes.SettingsManager import SettingsManager
|
from app.classes.SettingsManager import SettingsManager
|
||||||
from tornado.options import options
|
from tornado.options import options
|
||||||
from app.handlers.CamerasHandler import CamerasHandler
|
|
||||||
from app.handlers.VisionHandler import VisionHandler
|
from app.handlers.VisionHandler import VisionHandler
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
SettingsManager()
|
SettingsManager()
|
||||||
# CamerasHandler.init_camera()
|
|
||||||
|
|
||||||
|
|
||||||
#VisionHandler().run()
|
#VisionHandler().run()
|
||||||
# SettingsManager().save_settings()
|
# SettingsManager().save_settings()
|
||||||
|
|||||||
@@ -59,9 +59,7 @@ class SettingsManager(metaclass=Singleton):
|
|||||||
|
|
||||||
# Initiate our camera's settings
|
# Initiate our camera's settings
|
||||||
def _init_cameras(self):
|
def _init_cameras(self):
|
||||||
cameras = self._get_cameras_info()
|
for cam in self.usb_cameras_info:
|
||||||
|
|
||||||
for cam in cameras:
|
|
||||||
if os.path.exists(os.path.join(self.cams_path, cam.name + '.json')):
|
if os.path.exists(os.path.join(self.cams_path, cam.name + '.json')):
|
||||||
|
|
||||||
with open(os.path.join(self.cams_path, cam.name + '.json'), 'r') as camera:
|
with open(os.path.join(self.cams_path, cam.name + '.json'), 'r') as camera:
|
||||||
@@ -72,17 +70,6 @@ class SettingsManager(metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
self.create_new_cam(cam.name)
|
self.create_new_cam(cam.name)
|
||||||
|
|
||||||
if "path" not in self.cams[cam.name]:
|
|
||||||
self.cams[cam.name]["path"] = cam.otherPaths[0] if len(cam.otherPaths) == 1 else cam.otherPaths[1]
|
|
||||||
if "video_mode" not in self.cams[cam.name]:
|
|
||||||
video_mode: VideoMode = self.cams(cam.name).enumerateVideoModes()[0]
|
|
||||||
self.cams[cam.name]["video_mode"] = {
|
|
||||||
"fps": video_mode.fps,
|
|
||||||
"width": video_mode.width,
|
|
||||||
"height": video_mode.height,
|
|
||||||
"pixel_format": str(video_mode.pixelFormat).split('.')[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Initiate true usb cameras(filters microphones and double cameras)
|
# Initiate true usb cameras(filters microphones and double cameras)
|
||||||
def _init_cameras_info(self):
|
def _init_cameras_info(self):
|
||||||
true_cameras = []
|
true_cameras = []
|
||||||
@@ -198,6 +185,17 @@ class SettingsManager(metaclass=Singleton):
|
|||||||
self.cams[cam_name]["pipelines"] = {}
|
self.cams[cam_name]["pipelines"] = {}
|
||||||
self.create_new_pipeline(cam_name=cam_name)
|
self.create_new_pipeline(cam_name=cam_name)
|
||||||
|
|
||||||
|
self.cams[cam_name]["path"] = self.usb_cameras[cam_name].otherPaths[0] if len(
|
||||||
|
self.usb_cameras[cam_name].otherPaths) == 1 else self.usb_cameras[cam_name].otherPaths[1]
|
||||||
|
|
||||||
|
video_mode: VideoMode = self.usb_cameras[self.usb_cameras[cam_name].name].enumerateVideoModes()[0]
|
||||||
|
self.cams[self.usb_cameras[cam_name].name]["video_mode"] = {
|
||||||
|
"fps": video_mode.fps,
|
||||||
|
"width": video_mode.width,
|
||||||
|
"height": video_mode.height,
|
||||||
|
"pixel_format": str(video_mode.pixelFormat).split('.')[1]
|
||||||
|
}
|
||||||
|
|
||||||
# Savers
|
# Savers
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from cscore._cscore import VideoMode
|
|||||||
|
|
||||||
class CamerasHandler:
|
class CamerasHandler:
|
||||||
|
|
||||||
@staticmethod
|
#@staticmethod
|
||||||
# def get_cameras_info():
|
# def get_cameras_info():
|
||||||
#
|
#
|
||||||
# if not getattr(CamerasHandler, "cams_info", False):
|
# if not getattr(CamerasHandler, "cams_info", False):
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import tornado.websocket
|
import tornado.websocket
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ..classes.Exceptions import NoCameraConnectedException
|
from ..classes.Exceptions import NoCameraConnectedException
|
||||||
from .CamerasHandler import CamerasHandler
|
|
||||||
from ..classes.SettingsManager import SettingsManager
|
from ..classes.SettingsManager import SettingsManager
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import networktables
|
|||||||
import cv2
|
import cv2
|
||||||
import numpy
|
import numpy
|
||||||
from cscore import CameraServer
|
from cscore import CameraServer
|
||||||
from .CamerasHandler import CamerasHandler
|
|
||||||
from app.classes.SettingsManager import SettingsManager
|
from app.classes.SettingsManager import SettingsManager
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
@@ -76,9 +75,8 @@ class VisionHandler:
|
|||||||
NetworkTables.initialize("localhost")
|
NetworkTables.initialize("localhost")
|
||||||
# NetworkTables.initialize()
|
# NetworkTables.initialize()
|
||||||
|
|
||||||
cams = CamerasHandler.get_or_start_cameras(CamerasHandler.get_cameras_info())
|
for cam in SettingsManager().usb_cameras:
|
||||||
for cam in cams:
|
self.camera_process(SettingsManager().usb_cameras[cam])
|
||||||
self.camera_process(cams[cam])
|
|
||||||
|
|
||||||
def camera_process(self, camera):
|
def camera_process(self, camera):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user