From 33701eaf3400fe9e241e401af40e9c7ab10049c4 Mon Sep 17 00:00:00 2001 From: ori Date: Fri, 9 Aug 2019 03:29:03 -0700 Subject: [PATCH] added cam port sending and change camera bug fix --- backend/app/classes/SettingsManager.py | 3 ++- backend/app/handlers/SocketHandler.py | 7 +++++++ backend/app/handlers/VisionHandler.py | 10 ++++++++-- .../settings/cams/USB Camera-B4.09.24.1.json | 2 +- backend/settings/cams/USB2.0 PC CAMERA.json | 1 + backend/settings/settings.json | 2 +- chameleon-client/src/components/Vision.vue | 2 +- chameleon-client/src/store.js | 17 ++++++++--------- 8 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 backend/settings/cams/USB2.0 PC CAMERA.json diff --git a/backend/app/classes/SettingsManager.py b/backend/app/classes/SettingsManager.py index ad66ba42e..76a1f0309 100644 --- a/backend/app/classes/SettingsManager.py +++ b/backend/app/classes/SettingsManager.py @@ -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"]: diff --git a/backend/app/handlers/SocketHandler.py b/backend/app/handlers/SocketHandler.py index 390dbcb6a..618cbb84e 100644 --- a/backend/app/handlers/SocketHandler.py +++ b/backend/app/handlers/SocketHandler.py @@ -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): diff --git a/backend/app/handlers/VisionHandler.py b/backend/app/handlers/VisionHandler.py index 16a326f52..56c1433ba 100644 --- a/backend/app/handlers/VisionHandler.py +++ b/backend/app/handlers/VisionHandler.py @@ -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({ diff --git a/backend/settings/cams/USB Camera-B4.09.24.1.json b/backend/settings/cams/USB Camera-B4.09.24.1.json index b2d504b01..794e41662 100644 --- a/backend/settings/cams/USB Camera-B4.09.24.1.json +++ b/backend/settings/cams/USB Camera-B4.09.24.1.json @@ -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} \ No newline at end of file +{"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} \ No newline at end of file diff --git a/backend/settings/cams/USB2.0 PC CAMERA.json b/backend/settings/cams/USB2.0 PC CAMERA.json new file mode 100644 index 000000000..c26acf48d --- /dev/null +++ b/backend/settings/cams/USB2.0 PC CAMERA.json @@ -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} \ No newline at end of file diff --git a/backend/settings/settings.json b/backend/settings/settings.json index 4768b240f..41fe0b582 100644 --- a/backend/settings/settings.json +++ b/backend/settings/settings.json @@ -1 +1 @@ -{"team_number": 1567, "connection_type": "DHCP", "ip": "", "gateway": "", "hostname": "Chameleon-Vision", "curr_camera": "USB Camera-B4.09.24.1", "curr_pipeline": "pipeline0"} \ No newline at end of file +{"team_number": 1567, "connection_type": "DHCP", "ip": "", "gateway": "", "hostname": "Chameleon-Vision", "curr_camera": "USB2.0 PC CAMERA", "curr_pipeline": "pipeline0"} \ No newline at end of file diff --git a/chameleon-client/src/components/Vision.vue b/chameleon-client/src/components/Vision.vue index 349de6798..ab20901ab 100644 --- a/chameleon-client/src/components/Vision.vue +++ b/chameleon-client/src/components/Vision.vue @@ -59,7 +59,7 @@ }, steamAdress: { get: function(){ - return this.$store.state.streamAdress; + return "http://"+location.hostname + ":"+ this.$store.state.port +"/stream.mjpg"; } }, isBinary: { diff --git a/chameleon-client/src/store.js b/chameleon-client/src/store.js index 92c539ddd..29be7a60d 100644 --- a/chameleon-client/src/store.js +++ b/chameleon-client/src/store.js @@ -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 }, }); \ No newline at end of file