This repository was archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
105 lines (89 loc) · 3.73 KB
/
run.py
File metadata and controls
105 lines (89 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import cv2
import config
import argparse
import configparser
from sys import platform
from process_video import CaptureThread
"""
VARIABLES
"""
global api_preferences
"""
OS platform
"""
if platform == "win32":
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
api_preferences = cv2.CAP_FFMPEG
elif platform == "linux" or platform == "linux2":
api_preferences = None
"""
Camera configuration
"""
file = (configparser.ConfigParser())
file.read(config.INI_FILE)
def url_gen(sys):
username = file[sys]["USERNAME"]
password = file[sys]["PASSWORD"]
ip_address = file[sys]["IP_ADDRESS"]
port = file[sys]["PORT"]
dir = file[sys]["DIR"]
computer = file[sys]["COMPUTER"]
return f"rtsp://{username}:{password}@{ip_address}:{port}/{dir}/{computer}"
def request_type(args):
"""
:param args: - Pass a variable number of arguments to a function. camera:ON/video:local path/url:rtsp path
:return:
camera: The capturing device connects only if you have given permission by writing 'ON'
video: The video file will be launched if you specify the correct directory.
If you want to specify full directory on the command line, you need to overwrite:
file_open(args['video'], args['video'], None)
url: You can use the .ini file with the following parameters,
.ini file filling example: rtsp://admin:12345@192.168.1.210:554/Streaming/Channels/101
[10]
USERNAME = admin
PASSWORD = 12345
IP_ADDRESS = 192.168.1.210
PORT = 554
DIR = Streaming/Channels
COMPUTER = 101
If you want to specify full directory on the command line, you need to overwrite:
file_open('rtsp://admin:12345@192.168.1.210:554/Streaming/Channels/101', sys, api_preferences)
"""
if args["camera"] is not None and args["camera"] == "true":
print("[INFO] Opening Web Cam.")
CaptureThread(0, "Camera", None).start()
elif args["video"] is not None:
print("[INFO] Opening Video from path.")
CaptureThread(config.PATH_TO_VIDEO + args["video"], args["video"], None).start()
elif args["url"] is not None:
if args["url"] == "all":
print("[INFO] Opening URL of Real-Time Streaming Protocol.")
for sys in config.COMPUTERS:
rtsp_url = url_gen(sys)
print(rtsp_url)
CaptureThread(rtsp_url, sys, api_preferences).start()
elif args["url"] in config.COMPUTERS:
print("[INFO] Opening URL of Real-Time Streaming Protocol.")
rtsp_url = url_gen(args["url"])
print(rtsp_url)
CaptureThread(rtsp_url, args["url"], api_preferences).start()
def argsParser():
"""
camera: Use your local capturing device. Write ON to run camera.
video: Use local video file path. Make sure that you have entered the correct directory for the video folder.
url: Use IP video stream with given .ini file. Choose one computer(camera).
"""
arg_parse = argparse.ArgumentParser()
arg_parse.add_argument("-v", "--video", type=str, default=None,
help=f"Path to the local video file (select one video from default path "
f"\"{config.PATH_TO_VIDEO}\"")
arg_parse.add_argument("-u", "--url", type=str, default=None,
help="URL address of RTSP (select one computer from .ini file")
arg_parse.add_argument("-c", "--camera", type=str, default=None,
help="Local Camera (write true/false to use/cancel camera)")
args = vars(arg_parse.parse_args())
return args
if __name__ == "__main__":
args = argsParser()
request_type(args)