Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for RTSP feeds #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions umt/umt_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def main():
parser.add_argument('-imageseq', dest='image_path', type=str, required=False, help='specify an image sequence')
parser.add_argument('-video', dest='video_path', type=str, required=False, help='specify video file')
parser.add_argument('-camera', dest='camera', default=False, action='store_true', help='specify this when using the rpi camera as the input')
parser.add_argument('-rtsp', dest='rtsp_url', type=str, required=False, help='specify RTSP camera URL')
parser.add_argument('-threshold', dest='threshold', type=float, default=0.5, required=False, help='specify a custom inference threshold')
parser.add_argument('-tpu', dest='tpu', required=False, default=False, action='store_true', help='add this when using a coral usb accelerator')
parser.add_argument('-nframes', dest='nframes', type=int, required=False, default=10, help='specify nunber of frames to process')
Expand Down
18 changes: 18 additions & 0 deletions umt/umt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ def video_frame_gen(args):
yield Image.fromarray(frame)


def rtsp_frame_gen(args):

cap = cv2.VideoCapture(args.rtsp_url, cv2.CAP_FFMPEG)

while True:
if cv2.waitKey(1) & 0xFF == ord('q'): break

# pull frame from video stream
_, frame = cap.read()

# array to PIL image format
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

yield Image.fromarray(frame)


def initialize_img_source(args):

# track objects from video file
Expand All @@ -85,6 +101,8 @@ def initialize_img_source(args):
# track objects from camera source
if args.camera: return camera_frame_gen

# track objects from RTSP camera feed
if args.rtsp_url: return rtsp_frame_gen

def initialize_detector(args):

Expand Down