mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
added cam port sending and change camera bug fix
This commit is contained in:
@@ -13,6 +13,7 @@ class SettingsManager(metaclass=Singleton):
|
||||
usb_cameras = {}
|
||||
usb_cameras_info = {}
|
||||
general_settings = {}
|
||||
cams_port = {}
|
||||
|
||||
default_pipeline = {
|
||||
"exposure": 50,
|
||||
@@ -165,7 +166,7 @@ class SettingsManager(metaclass=Singleton):
|
||||
def set_curr_camera(self, cam_name):
|
||||
if cam_name in self.cams:
|
||||
self.general_settings["curr_camera"] = cam_name
|
||||
self.general_settings["curr_pipeline"] = self.get_curr_cam()["pipelines"].keys()[0]
|
||||
self.general_settings["curr_pipeline"] = list(self.get_curr_cam()["pipelines"].keys())[0]
|
||||
|
||||
def set_curr_pipeline(self, pipe_name):
|
||||
if pipe_name in self.get_curr_cam()["pipelines"]:
|
||||
|
||||
@@ -86,6 +86,11 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
|
||||
# TODO: return something if no camera connected
|
||||
self.write_message("No camera connected")
|
||||
|
||||
def send_curr_port(self):
|
||||
self.write_message({
|
||||
'port': self.settings_manager.cams_port[self.settings_manager.general_settings["curr_camera"]]
|
||||
})
|
||||
|
||||
def send_full_settings(self):
|
||||
full_settings = self.settings_manager.general_settings.copy()
|
||||
full_settings["cameraList"] = list(self.settings_manager.cams.copy().keys())
|
||||
@@ -95,6 +100,7 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
|
||||
full_settings["resolutionList"] = self.settings_manager.get_resolution_list()
|
||||
full_settings['resolution'] = self.settings_manager.get_curr_cam()['resolution']
|
||||
full_settings['FOV'] = self.settings_manager.get_curr_cam()['FOV']
|
||||
full_settings['port'] = self.settings_manager.cams_port[self.settings_manager.general_settings["curr_camera"]]
|
||||
except NoCameraConnectedException:
|
||||
# TODO: return something if no camera connected
|
||||
full_settings["data"] = None
|
||||
@@ -103,6 +109,7 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
|
||||
|
||||
def change_curr_camera(self, dic):
|
||||
self.settings_manager.set_curr_camera(cam_name=dic["curr_camera"])
|
||||
self.send_curr_port()
|
||||
self.send_curr_cam()
|
||||
|
||||
def change_curr_pipeline(self, dic):
|
||||
|
||||
@@ -279,7 +279,7 @@ class VisionHandler(metaclass=Singleton):
|
||||
flags=networktables.NetworkTablesInstance.NotifyFlags.UPDATE)
|
||||
table.addEntryListenerEx(mode_listener, key="Driver_Mode",
|
||||
flags=networktables.NetworkTablesInstance.NotifyFlags.UPDATE)
|
||||
|
||||
#gettings video from curent camera
|
||||
cv_sink = cs.getVideo(camera=SettingsManager.usb_cameras[cam_name])
|
||||
|
||||
width = SettingsManager().cams[cam_name]["video_mode"]["width"]
|
||||
@@ -287,16 +287,22 @@ class VisionHandler(metaclass=Singleton):
|
||||
|
||||
image = numpy.zeros(shape=(width, height, 3), dtype=numpy.uint8)
|
||||
|
||||
#setting up a video server for camera
|
||||
cv_publish = cs.putVideo(name=cam_name, width=width, height=height)
|
||||
# saving camera port in cam name dict for usage in client
|
||||
SettingsManager().cams_port[cam_name] = cs._sinks['serve_'+cam_name].getPort()
|
||||
|
||||
#setting up a zmq connection to the opencv subprocess
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.PAIR)
|
||||
socket.bind('tcp://*:%s' % str(port))
|
||||
|
||||
#starting the process with inital values
|
||||
p = Process(target=self.camera_process, args=(cam_name, port, FOV))
|
||||
p.start()
|
||||
|
||||
change_camera_values(pipeline)
|
||||
|
||||
while True:
|
||||
_, image = cv_sink.grabFrame(image)
|
||||
socket.send_json(dict(
|
||||
@@ -313,7 +319,7 @@ class VisionHandler(metaclass=Singleton):
|
||||
table.putNumber('pitch', nt_data['pitch'])
|
||||
table.putNumber('yaw', nt_data['yaw'])
|
||||
#if the selected camera in ui is this cam send the point to the ui
|
||||
if SettingsManager().general_settings['curr_camera'] is cam_name:
|
||||
if SettingsManager().general_settings['curr_camera'] == cam_name:
|
||||
try:
|
||||
if nt_data['raw_point'] is not None:
|
||||
send_all_async({
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"pipelines": {"pipeline0": {"exposure": 50, "brightness": 50, "orientation": "Normal", "hue": [0, 100], "saturation": [0, 100], "value": [0, 100], "erode": false, "dilate": false, "area": [0, 100], "ratio": [0, 20], "extent": [0, 100], "is_binary": 0, "sort_mode": "Largest", "target_group": "Single", "target_intersection": "Up"}}, "path": "/dev/v4l/by-path/pci-0000:02:03.0-usb-0:1:1.0-video-index0", "video_mode": {"fps": 15, "width": 640, "height": 480, "pixel_format": "kYUYV"}, "resolution": 14, "FOV": 56}
|
||||
{"pipelines": {"pipeline0": {"exposure": 50, "brightness": 10, "orientation": "Normal", "hue": [0, 56], "saturation": [0, 47], "value": [0, 100], "erode": false, "dilate": false, "area": [0, 100], "ratio": [0, 99], "extent": [0, 100], "is_binary": 1, "sort_mode": "Rightmost", "target_group": "Single", "target_intersection": "Up"}}, "path": "/dev/v4l/by-path/pci-0000:02:03.0-usb-0:1:1.0-video-index0", "video_mode": {"fps": 15, "width": 640, "height": 480, "pixel_format": "kYUYV"}, "resolution": 14, "FOV": 56}
|
||||
1
backend/settings/cams/USB2.0 PC CAMERA.json
Normal file
1
backend/settings/cams/USB2.0 PC CAMERA.json
Normal file
@@ -0,0 +1 @@
|
||||
{"pipelines": {"pipeline0": {"exposure": 50, "brightness": 50, "orientation": "Normal", "hue": [0, 100], "saturation": [0, 100], "value": [0, 100], "erode": false, "dilate": false, "area": [0, 100], "ratio": [0, 20], "extent": [0, 100], "is_binary": "Normal", "sort_mode": "Largest", "target_group": "Single", "target_intersection": "Up"}}, "path": "/dev/v4l/by-path/pci-0000:02:03.0-usb-0:2:1.0-video-index0", "video_mode": {"fps": 30, "width": 640, "height": 480, "pixel_format": "kYUYV"}, "resolution": 0, "FOV": 60.8}
|
||||
@@ -1 +1 @@
|
||||
{"team_number": 1567, "connection_type": "DHCP", "ip": "", "gateway": "", "hostname": "Chameleon-Vision", "curr_camera": "USB Camera-B4.09.24.1", "curr_pipeline": "pipeline0"}
|
||||
{"team_number": 1567, "connection_type": "DHCP", "ip": "", "gateway": "", "hostname": "Chameleon-Vision", "curr_camera": "USB2.0 PC CAMERA", "curr_pipeline": "pipeline0"}
|
||||
@@ -59,7 +59,7 @@
|
||||
},
|
||||
steamAdress: {
|
||||
get: function(){
|
||||
return this.$store.state.streamAdress;
|
||||
return "http://"+location.hostname + ":"+ this.$store.state.port +"/stream.mjpg";
|
||||
}
|
||||
},
|
||||
isBinary: {
|
||||
|
||||
@@ -40,14 +40,14 @@ export const store = new Vuex.Store({
|
||||
gateWay:0,
|
||||
hostname:"",
|
||||
//live info
|
||||
streamAdress:("http://"+location.hostname + ":1181/stream.mjpg"),
|
||||
port:1181,
|
||||
is_binary:0,
|
||||
//camera lists
|
||||
|
||||
},
|
||||
mutations:{
|
||||
camera (state,value){
|
||||
state['camera'] = value;
|
||||
curr_camera (state,value){
|
||||
state['curr_camera'] = value;
|
||||
state['pipeline'] = "0";
|
||||
},
|
||||
pipeline: set('curr_pipeline'),
|
||||
@@ -68,17 +68,17 @@ export const store = new Vuex.Store({
|
||||
ip: set('ip'),
|
||||
gateWay : set('gateway'),
|
||||
hostname : set('hostname'),
|
||||
streamAdress : set('streamAdress'),
|
||||
is_binary: set('is_binary'),
|
||||
cameraList : set('cameraList'),
|
||||
pipelineList: set('piplineList'),
|
||||
sort_mode: set('sort_mode'),
|
||||
target_group:set('target_group'),
|
||||
target_intersection:set('target_intersection'),
|
||||
FOV:set('FOV')
|
||||
FOV:set('FOV'),
|
||||
port:set('port')
|
||||
},
|
||||
getters:{
|
||||
camera: state => state.camera,
|
||||
curr_camera: state => state.curr_camera,
|
||||
pipeline: state => state.pipeline,
|
||||
brightness: state => state.brightness,
|
||||
exposure: state => state.exposure,
|
||||
@@ -97,15 +97,14 @@ export const store = new Vuex.Store({
|
||||
ip: state => state.ip,
|
||||
gateWay: state => state.gateWay,
|
||||
hostname: state => state.hostName,
|
||||
streamAdress: state => state.streamAdress,
|
||||
is_binary: state => state.is_binary,
|
||||
cameraList: state => state.cameraList,
|
||||
pipelineList: state => state.pipelineList,
|
||||
sort_mode: state => state.sort_mode,
|
||||
target_group: state => state.target_group,
|
||||
target_intersection: state => state.target_intersection,
|
||||
FOV: state => state.FOV
|
||||
|
||||
FOV: state => state.FOV,
|
||||
port: state => state.port
|
||||
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user