-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicVideo.py
120 lines (97 loc) · 4.1 KB
/
BasicVideo.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# MIT LICENSE
#
# Copyright 2024 Michael J. Reale
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
# IMPORTS
###############################################################################
import sys
import numpy as np
import torch
import cv2
import pandas
import sklearn
###############################################################################
# MAIN
###############################################################################
def main():
###############################################################################
# PYTORCH
###############################################################################
b = torch.rand(5,3)
print(b)
print("Torch CUDA?:", torch.cuda.is_available())
###############################################################################
# PRINT OUT VERSIONS
###############################################################################
print("Torch:", torch.__version__)
print("Numpy:", np.__version__)
print("OpenCV:", cv2.__version__)
print("Pandas:", pandas.__version__)
print("Scikit-Learn:", sklearn.__version__)
###############################################################################
# OPENCV
###############################################################################
if len(sys.argv) <= 1:
# Webcam
print("Opening webcam...")
# Linux/Mac (or native Windows) with direct webcam connection
capture = cv2.VideoCapture(0, cv2.CAP_DSHOW) # CAP_DSHOW recommended on Windows
# WSL: Use Yawcam to stream webcam on webserver
# https://www.yawcam.com/download.php
# Get local IP address and replace
#IP_ADDRESS = "192.168.0.7"
#capture = cv2.VideoCapture("http://" + IP_ADDRESS + ":8081/video.mjpg")
# Did we get it?
if not capture.isOpened():
print("ERROR: Cannot open capture!")
exit(1)
# Set window name
windowName = "Webcam"
else:
# Trying to load video from argument
# Get filename
filename = sys.argv[1]
# Load video
capture = cv2.VideoCapture(filename)
# Check if data is invalid
if not capture.isOpened():
print("ERROR: Could not open or find the video!")
exit(1)
# Set window name
windowName = "Video"
# Create window ahead of time
cv2.namedWindow(windowName)
# While not closed...
key = -1
while key == -1:
# Get next frame from capture
ret, frame = capture.read()
if ret == True:
# Show the image
cv2.imshow(windowName, frame)
else:
break
# Wait 30 milliseconds, and grab any key presses
key = cv2.waitKey(30)
# Release the capture and destroy the window
capture.release()
cv2.destroyAllWindows()
# Close down...
print("Closing application...")
if __name__ == "__main__":
main()
# The end