-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
53 lines (43 loc) · 1.38 KB
/
camera.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
# Created by Alex Pereira
# Imports
import cv2 as cv
# Variables
HIGH_VALUE = 10000
# Creates the USBCamera Class
class USBCamera:
# Constructor
def __init__(self, camNum) -> None:
"""
Constructor for USBCamera.
@param camNumber
"""
# Sets camera properties
self.camNum = camNum
# Auto Resize
self.autoResize()
def autoResize(self):
"""
Autmatically resizes the capture to the highest resolution.
"""
# Creates a capture
self.cap = cv.VideoCapture(self.camNum)
# Set the values too high
self.cap.set(cv.CAP_PROP_FRAME_WIDTH, HIGH_VALUE)
self.cap.set(cv.CAP_PROP_FRAME_HEIGHT, HIGH_VALUE)
self.cap.set(cv.CAP_PROP_FPS, HIGH_VALUE)
# Gets the highest value they go to
width = int(self.cap.get(cv.CAP_PROP_FRAME_WIDTH))
height = int(self.cap.get(cv.CAP_PROP_FRAME_HEIGHT))
fps = int(self.cap.get(cv.CAP_PROP_FPS))
# Set the capture to be MJPG format
self.cap.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*'MJPG'))
# Prints telemetry
print("Max Resolution:", str(width) + "x" + str(height))
print("Max FPS:", fps)
def getCapture(self):
"""
Returns the created capture.
@return createdCapture
"""
# Returns the capture
return self.cap