-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLpr_capture.py
41 lines (34 loc) · 1.32 KB
/
Lpr_capture.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
import cv2
import os, datetime
class capture():
def __init__(self,ip,id,pw,rport,):
self.ip = ip
self.id = id
self.pw = pw
self.rport = rport
self.url = f'rtsp://{id}:{pw}@{ip}:{rport}/cam0_0'
# self.url = f'rtsp://{self.id}:{self.pw}@{self.ip}:{self.rport}/profile2/media.smp'
def video(self):
cap = cv2.VideoCapture(self.url)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = 15
print(width,height,fps)
t = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') + '.avi'
if not os.path.isdir('C:\Video') : os.mkdir('C:\Video')
path = os.path.join('C:\Video',t)
out = cv2.VideoWriter(path, fourcc, fps, (width,height))
while True:
_, frame = cap.read()
out.write(frame)
frame = cv2.resize(frame, dsize=(0,0), fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
cv2.imshow('recoding',frame)
k = cv2.waitKey(1) & 0xff
if k == 27: break
cap.release()
out.release()
cv2.destroyAllWindows()
test = capture('192.168.0.48','root','root','554')
# test = capture('192.168.0.45','admin','goback2022','554')
test.video()