mvp
This commit is contained in:
parent
60890fc2af
commit
2bafb798da
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
videos/*.mp4
|
@ -1,7 +0,0 @@
|
|||||||
from datetime import datetime, date, time
|
|
||||||
|
|
||||||
print(datetime.now())
|
|
||||||
|
|
||||||
def five_minute_segment_from(the_time, actually_do_five_seconds=False):
|
|
||||||
minute = the_time.replace(second=0, microsecond=0)
|
|
||||||
return minute.replace(minute=(minute.minute // 5)*5)
|
|
51
webcam.py
51
webcam.py
@ -1,7 +1,14 @@
|
|||||||
|
from datetime import datetime, date, time, timedelta
|
||||||
# import the opencv library
|
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
|
def five_minute_segment_from(the_time):
|
||||||
|
return the_time.replace(second=(the_time.second // 5)*5, microsecond=0)
|
||||||
|
#minute = the_time.replace(second=0, microsecond=0)
|
||||||
|
#return minute.replace(minute=(minute.minute // 5)*5)
|
||||||
|
|
||||||
|
def video_address_for(time_stamp):
|
||||||
|
return 'videos/' + str(time_stamp) + '.mp4'
|
||||||
|
|
||||||
# define a video capture object
|
# define a video capture object
|
||||||
camera = cv2.VideoCapture(0)
|
camera = cv2.VideoCapture(0)
|
||||||
@ -11,15 +18,31 @@ if not camera.isOpened():
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
queue = [(False, None)] * 100
|
queue = [(False, None)] * 100
|
||||||
|
|
||||||
|
last_time_stamp = five_minute_segment_from(datetime.now())
|
||||||
|
|
||||||
|
old_time = cv2.VideoCapture(video_address_for(last_time_stamp))
|
||||||
|
|
||||||
# Define the codec and create VideoWriter object
|
# Define the codec and create VideoWriter object
|
||||||
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
||||||
#out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (int(camera.get(3)),int(camera.get(4))))
|
out = cv2.VideoWriter("videos/" + str(last_time_stamp) + ".mp4", fourcc, camera.get(cv2.CAP_PROP_FPS), (int(camera.get(3)),int(camera.get(4))))
|
||||||
|
|
||||||
idx = 0
|
idx = 0
|
||||||
offset = 0
|
offset = 0
|
||||||
|
longterm = False
|
||||||
while(True):
|
while(True):
|
||||||
|
if last_time_stamp != five_minute_segment_from(datetime.now()):
|
||||||
|
out.release()
|
||||||
|
out = cv2.VideoWriter(video_address_for(last_time_stamp),
|
||||||
|
fourcc,
|
||||||
|
camera.get(cv2.CAP_PROP_FPS),
|
||||||
|
(int(camera.get(3)), int(camera.get(4)))
|
||||||
|
)
|
||||||
|
if old_time.isOpened():
|
||||||
|
old_time.release()
|
||||||
|
old_time = cv2.VideoCapture(video_address_for(five_minute_segment_from(datetime.now() - timedelta(seconds=30))))
|
||||||
|
|
||||||
|
last_time_stamp = five_minute_segment_from(datetime.now())
|
||||||
# Capture the video frame
|
# Capture the video frame
|
||||||
# by frame
|
# by frame
|
||||||
ret, frame = camera.read()
|
ret, frame = camera.read()
|
||||||
@ -27,27 +50,33 @@ while(True):
|
|||||||
frame = cv2.flip(frame, 1)
|
frame = cv2.flip(frame, 1)
|
||||||
|
|
||||||
#recod the frame
|
#recod the frame
|
||||||
#out.write(frame)
|
out.write(frame)
|
||||||
queue[idx] = ret, frame
|
queue[idx] = ret, frame
|
||||||
|
|
||||||
|
|
||||||
showo, fr = queue[(idx - offset) % len(queue)]
|
showo, fr = queue[(idx - offset) % len(queue)]
|
||||||
if showo:
|
if longterm:
|
||||||
|
ret2, frame2 = old_time.read()
|
||||||
|
if ret2:
|
||||||
|
cv2.imshow('vid', frame2)
|
||||||
|
elif showo:
|
||||||
cv2.imshow('vid', fr)
|
cv2.imshow('vid', fr)
|
||||||
|
|
||||||
# the 'q' button is set as the quitting button you may use any desired button of your choice
|
# the 'q' button is set as the quitting button you may use any desired button of your choice
|
||||||
key = cv2.waitKey(1) & 0xFF
|
key = cv2.waitKey(1) & 0xFF
|
||||||
if key == ord('q'):
|
if key == ord('q'):
|
||||||
break
|
break
|
||||||
|
|
||||||
if key == ord('a'):
|
if key == ord('a'):
|
||||||
offset += 1
|
offset += 1
|
||||||
if key == ord('d'):
|
if key == ord('d'):
|
||||||
offset -= 1
|
offset -= 1
|
||||||
|
if key == ord('z'):
|
||||||
|
longterm = not longterm
|
||||||
|
|
||||||
idx = (idx + 1) % len(queue)
|
idx = (idx + 1) % len(queue)
|
||||||
|
|
||||||
# After the loop release the cap object
|
# After the loop release the cap object
|
||||||
camera.release()
|
camera.release()
|
||||||
#out.release()
|
out.release()
|
||||||
# Destroy all the windows
|
# Destroy all the windows
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
Loading…
Reference in New Issue
Block a user