Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 14, 2020
2 parents a6b9f5e + 768e66e commit 6bc8a31
Show file tree
Hide file tree
Showing 38 changed files with 13,493 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
*.pyc
Binary file added .main.py.swp
Binary file not shown.
9 changes: 5 additions & 4 deletions cameras/generic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Calibration constants for a portrait mode webcam
Calibration constants for a webcam
"""

FRAME_HEIGHT = 1024
FRAME_WIDTH = 768
FRAME_WIDTH = 640
FRAME_HEIGHT = 480
FPS = 120

FOCAL_LENGTH = 1100
FOCAL_LENGTH = 1170
12 changes: 11 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import config

config.networktables_server_ip = '127.0.0.1'

# when using static ip for robot
#config.networktables_server_ip = '10.26.1.11'

config.video_source_number = 0
config.networktables_table = 'SmartDashboard'

config.gstreamer_bitrate = '3500000'
config.gstreamer_client_ip = '10.26.1.5'
config.gstreamer_client_port = '5805'
config.gstreamer_pipeline = 'appsrc ! videoconvert ! omxh264enc bitrate=%s ! video/x-h264, stream-format=(string)byte-stream ! h264parse ! rtph264pay ! udpsink host=%s port=%s' % (config.gstreamer_bitrate, config.gstreamer_client_ip, config.gstreamer_client_port)

# config.gstreamer_pipeline = 'appsrc ! videoconvert ! omxh265enc bitrate=%s ! video/x-h265, stream-format=(string)byte-stream ! h265parse ! rtph265pay ! udpsink host=%s port=%s' % (config.gstreamer_bitrate, config.gstreamer_client_ip, config.gstreamer_client_port)

tornado_server_port="8080"
tornado_server_port="8080"
15 changes: 8 additions & 7 deletions controls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from network import controller_listener

CAMERA_MODE_RAW = 'R'
CAMERA_MODE_BALL = 'B'
CAMERA_MODE_LOADING_BAY = 'L'
CAMERA_MODE_HEXAGON = 'H'
CAMERA_MODE_RAW = 'RAW'
CAMERA_MODE_CALIBRATE = 'CALIBRATE'
CAMERA_MODE_BALL = 'BALL'
CAMERA_MODE_HEXAGON = 'HEXAGON'
CAMERA_MODE_LOADING_BAY = 'BAY'

class Controls():

def __init__(self):
self.enable_camera = True
# self.enable_processing = False
self.camera_mode = CAMERA_MODE_LOADING_BAY
self.enable_processing = False
self.enable_streaming = True
self.camera_mode = CAMERA_MODE_CALIBRATE

self.enable_feed = True
self.turn_camera_off = False


def connect(self):
controller_listener.connect(self)

Expand Down
23 changes: 23 additions & 0 deletions example_imagezmq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import cv2
import config
import time

from imagezmq import imagezmq
from processing import filters

def main():

cap = cv2.VideoCapture(config.video_source_number)

sender = imagezmq.ImageSender(connect_to="tcp://{}:5555".format('192.168.1.25'))

while(True):

_, frame = cap.read()

frame = filters.resize(frame, 640, 480, interpolation=cv2.INTER_CUBIC)

sender.send_image('testImage', frame)

if __name__ == '__main__':
main()
74 changes: 74 additions & 0 deletions gst_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
collect all known GStreamer methods here
"""

import logging

logger = logging.getLogger('gst')

def get_udp_streamer_pipeline2(host, port, bitrate):

# config.gstreamer_pipeline = 'appsrc ! videoconvert ! omxh264enc bitrate=%s ! video/x-h264, stream-format=(string)byte-stream ! h264parse ! rtph264pay ! udpsink host=%s port=%s' % (config.gstreamer_bitrate, config.gstreamer_client_ip, config.gstreamer_client_port)

pipeline = ' ! '.join( [appsrc(),
videoconvert(),
omxh264enc(bitrate=bitrate),
video_x264(byteStream=True),
h264parse(),
rtph264pay(),
udpsink(host,port)])
logger.info(pipeline)
return pipeline

def get_udp_sender(host, port):
'appsrc ! queue ! videoconvert ! video/x-raw ! x264enc tune=zerolatency ! h264parse ! rtph264pay ! udpsink host="192.168.1.10" port="5000" sync=false'
pipeline = ' ! '.join( [appsrc(),
queue(),
videoconvert(),
video_x_raw(),
x264enc(zerolatency=True),
h264parse(),
rtph264pay(),
udpsink(host,port)])

print(pipeline)
return pipeline

## PIPELINES
def omxh264enc(bitrate=None):
if bitrate is not None:
return 'omxh264enc bitrate=%s' % bitrate
return 'omxh264enc'

def appsrc():
return 'appsrc'

def queue():
return 'queue'

def videoconvert():
return 'videoconvert'

def video_x_raw():
return 'video/x-raw'

def video_x264(byteStream=False):
if byteStream:
return 'video/x-h264 stream-format=(string)byte-stream'
return 'video/x-h264'

def x264enc(zerolatency=True):
if zerolatency:
return 'x264enc tune=zerolatency'
return 'x264enc'

def h264parse():
return 'h264parse'

def rtph264pay():
return 'rtph264pay'

def udpsink(host, port, sync=False):
if sync is False:
return 'udpsink host="%s" port="%s" sync=false' % (host,port)
return 'udpsink host="%s" port="%s"' % (host,port)
14 changes: 14 additions & 0 deletions imagezmq/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
imagezmq: transport OpenCV images via ZMQ.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A pair of Python classes that transport OpenCV images from one
computer to another. For example, OpenCV images gathered by
a Raspberry Pi camera could be sent to another computer
for displaying the images using cv2.imshow() or for further image processing.
Copyright (c) 2017 by Jeff Bass.
License: MIT, see LICENSE for more details.
"""
# populate fields for >>>help(imagezmq)
from .__version__ import __title__, __description__, __url__, __version__
from .__version__ import __author__, __author_email__, __license__
from .__version__ import __copyright__
9 changes: 9 additions & 0 deletions imagezmq/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# populates fields for >>>help(imagezmq)
__title__ = 'imagezmq'
__description__ = 'Transporting OpenCV images via ZMQ'
__url__ = 'https://github.com/jeffbass/imagezmq'
__version__ = '0.3.0'
__author__ = 'Jeff Bass'
__author_email__ = '[email protected]'
__license__ = 'MIT 1.0'
__copyright__ = 'Copyright 2019 Jeff Bass'
Loading

0 comments on commit 6bc8a31

Please sign in to comment.