-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_opencv.py
86 lines (75 loc) · 2.37 KB
/
camera_opencv.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
import os
import cv2
from base_camera import BaseCamera
import time
import numpy as np
# class Camera1(BaseCamera):
# video_source = 0
#
# @staticmethod
# def set_video_source(source):
# Camera1.video_source = source[0]
#
# @staticmethod
# def frames():
# camera = cv2.VideoCapture(Camera1.video_source)
# if not camera.isOpened():
# raise RuntimeError('Could not start camera.')
#
# while True:
# # read current frame
# _, img1 = camera.read()
#
# # encode as a jpeg image and return it
# yield cv2.imencode('.jpg', img1)[1].tobytes()
#
#
# class Camera2(BaseCamera):
# video_source = 1
#
# @staticmethod
# def set_video_source(source):
# Camera2.video_source = source[1]
#
# @staticmethod
# def frames():
# camera = cv2.VideoCapture(Camera2.video_source)
# if not camera.isOpened():
# raise RuntimeError('Could not start camera.')
#
# while True:
# # read current frame
# _, img2 = camera.read()
#
# # encode as a jpeg image and return it
# yield cv2.imencode('.jpg', img2)[1].tobytes()
class Camera(BaseCamera):
video_source1 = 0
#video_source2 = 1
@staticmethod
def set_video_source(source):
Camera.video_source1 = source[0]
#Camera.video_source2 = source[1]
@staticmethod
def frames():
camera1 = cv2.VideoCapture(Camera.video_source1)
#camera2 = cv2.VideoCapture(Camera.video_source2)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(str(1)+'output.avi', fourcc, 10.0, (640, 480))
#out1 = cv2.VideoWriter('output1.avi', fourcc, 10.0, (640, 480))
if not (camera1.isOpened() ):
raise RuntimeError('Could not start camera.')
while True:
# read current frame
_, img1 = camera1.read()
#_, img2 = camera2.read()
img1 = cv2.resize(img1, (704, 396))
#img2 = cv2.resize(img2, (704, 396))
#img = np.hstack((img1, img2))
# encode as a jpeg image and return it
yield cv2.imencode('.jpg', img1)[1].tobytes()
ret, frame = camera1.read()
#ret, frame1 = camera2.read()
# output the frame
out.write(frame)
#out1.write(frame1)