Permalink
Browse files

Add gain disabling for cameras

  • Loading branch information...
1 parent 5f6d880 commit 95c18c963fef05405b3bc21362ae6321cb10a5d1 @cpvaughn cpvaughn committed Mar 23, 2014
Showing with 62 additions and 8 deletions.
  1. +1 −1 config/ocupus.yml
  2. +4 −1 scripts/ocupus_orchestrator.py
  3. +52 −1 scripts/system_utilities.py
  4. +5 −5 scripts/video_compactor.py
View
@@ -4,7 +4,7 @@ cameras:
capabilities: video/x-raw,width=320,height=240,framerate=30/1
v4l2settings: -c auto_gain=0 -c main_gain=0
v4l2settings-off: -c auto_gain=1
- processor: /home/odroid/getting2rectanglesandcomparing.py
+ #processor: /home/odroid/getting2rectanglesandcomparing.py
record: No
bitrate: 256
@@ -13,6 +13,7 @@
import code
import traceback
import yaml
+import system_utilities
BIN_DIR='/home/odroid/ocupus/bin/armv7-neon/'
@@ -179,6 +180,8 @@ def gstCommandLine(self):
v4l2loopback_devices.difference_update(current_devices)
+system_utilities.setup_cameras(cameras)
+
# Configure the cameras
for c in [z for z in cameras if cameras[z].v4l2_ctl]:
print("======================= Setting v4l2 controls for %s =======================" % cameras[c].name)
@@ -234,5 +237,5 @@ def gstCommandLine(self):
# Fire up the video vacuum
proc = subprocess.Popen(["python","/home/odroid/ocupus/scripts/video_compactor.py"])
phandles.append(proc)
-
+system_utilities.run_camera_control()
peerconnection_client.monitor_system_requests()
@@ -1,5 +1,15 @@
import subprocess
import zmq
+import json
+import yaml
+from multiprocessing import Process, Value, Queue
+import shlex
+
+system_cameras = None
+
+def setup_cameras(cameras):
+ global system_cameras
+ system_cameras = cameras
def get_traffic_info():
try:
@@ -37,4 +47,45 @@ def power_control_listener():
if messagedata == "shutdown":
subprocess.call(['poweroff'])
if messagedata == "restart":
- subprocess.call(['reboot'])
+ subprocess.call(['reboot'])
+
+def run_camera_control():
+ print system_cameras
+ sysproc = Process(target=camera_control_listener, args=(system_cameras,))
+ sysproc.daemon = True
+ sysproc.start()
+
+
+"""
+Responsible for handling camera control requests
+"""
+def camera_control_listener(camera_info):
+ print camera_info
+ cameras = yaml.load(file('/home/odroid/ocupus/config/ocupus.yml', 'r'))['cameras']
+
+ port = "5554"
+ context = zmq.Context()
+ socket = context.socket(zmq.SUB)
+ socket.connect ("tcp://localhost:%s" % port)
+
+ topicfilter = "cameraControl"
+ socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
+ print "STARTING POWER CONTROL LISTENING"
+
+ while True:
+ string = socket.recv_unicode()
+
+ topic, _, messagedata = string.partition(' ')
+
+ # Need to fix the json->python serialization happening in peercon
+ messagedata = messagedata.replace("u'","'")
+ messagedata = messagedata.replace("'",'"')
+
+ control = json.loads(messagedata)
+
+ name = control['camera']
+
+ v4l2args = [a['v4l2settings-off'] for a in cameras if a['name'] == name][0]
+
+ args = shlex.split("v4l2-ctl -d " + camera_info[name].device + " " + v4l2args)
+ proc = subprocess.call(args)
@@ -35,12 +35,12 @@
least_file_time = when
least_file = f
- fn = f.replace("mjpeg","avi").replace("/Videos/","/Videos/converted/")
+ if least_file:
+ fn = least_file.replace("mjpeg","avi").replace("/Videos/","/Videos/converted/")
+ p = subprocess.Popen('nice -n 15 avconv -y -v error -i %s -b:v 2M %s' % (least_file, fn), shell=True)
+ r = p.wait()
- p = subprocess.Popen('nice -n 15 avconv -y -v error -i %s -b:v 2M %s' % (f, fn), shell=True)
- r = p.wait()
-
- subprocess.check_call(["rm", f])
+ subprocess.check_call(["rm", least_file])
time.sleep(10)

0 comments on commit 95c18c9

Please sign in to comment.