cleaning up a bit i don't remember whatever
This commit is contained in:
parent
a70949804b
commit
0d43c980af
1
Pipfile
1
Pipfile
@ -5,7 +5,6 @@ name = "pypi"
|
|||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
opencv-python = "*"
|
opencv-python = "*"
|
||||||
python-ffmpeg = "*"
|
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
27
Pipfile.lock
generated
27
Pipfile.lock
generated
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "96b4a3ab781c5962dc20f7beaae76ca7d30cf6dd4e193b0b04e985235aabc5cb"
|
"sha256": "9cd65918174126dae7310623cabe06ec6e5ce3f1bb0e255262749a78a55d3839"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
@ -80,31 +80,6 @@
|
|||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"markers": "python_version >= '3.6'",
|
"markers": "python_version >= '3.6'",
|
||||||
"version": "==4.10.0.84"
|
"version": "==4.10.0.84"
|
||||||
},
|
|
||||||
"pyee": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:5d346a7d0f861a4b2e6c47960295bd895f816725b27d656181947346be98d7c1",
|
|
||||||
"sha256:b53af98f6990c810edd9b56b87791021a8f54fd13db4edd1142438d44ba2263f"
|
|
||||||
],
|
|
||||||
"markers": "python_version >= '3.8'",
|
|
||||||
"version": "==11.1.0"
|
|
||||||
},
|
|
||||||
"python-ffmpeg": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:19ac80af5a064a2f53c245af1a909b2d7648ea045500d96d3bcd507b88d43dc7",
|
|
||||||
"sha256:d86697da8dfb39335183e336d31baf42fb217468adf5ac97fd743898240faae3"
|
|
||||||
],
|
|
||||||
"index": "pypi",
|
|
||||||
"markers": "python_version >= '3.7'",
|
|
||||||
"version": "==2.0.12"
|
|
||||||
},
|
|
||||||
"typing-extensions": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d",
|
|
||||||
"sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"
|
|
||||||
],
|
|
||||||
"markers": "python_version >= '3.8'",
|
|
||||||
"version": "==4.12.2"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"develop": {}
|
"develop": {}
|
||||||
|
@ -1 +1,7 @@
|
|||||||
run it in python3 after `pipenv install opencv-python`
|
run it with python3 after `pipenv install opencv-python`
|
||||||
|
|
||||||
|
this progrram opens a fullscreen window showing a feed from camera 0 with a delay.
|
||||||
|
it will collect a lot of video files in the videos/ folder, and use them for showing a long (multiple minutes) delay
|
||||||
|
it also holds ontoo a buffer of a couple hundred frames to show shorter delays (like 5 oor 30 seconds)
|
||||||
|
it doesn't currently do anything to handle missing files, but it would be nice to give it a "default" swirly portal looking video to show
|
||||||
|
hopefully this'll run on a raspberry pi in the desert.
|
55
webcam.py
55
webcam.py
@ -1,72 +1,83 @@
|
|||||||
from datetime import datetime, date, time, timedelta
|
from datetime import datetime, date, time, timedelta
|
||||||
|
import os
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
def five_minute_segment_from(the_time):
|
def five_minute_segment_from(the_time):
|
||||||
return the_time.replace(minute=(the_time.minute // 1)*1, second=0, microsecond=0)
|
return the_time.replace(minute=(the_time.minute // 1)*1, second=0, microsecond=0)
|
||||||
|
|
||||||
def video_address_for(time_stamp):
|
def path_to_video_at(time_stamp):
|
||||||
return 'videos/' + str(time_stamp) + '.mkv'
|
return 'videos/' + str(time_stamp) + '.mkv'
|
||||||
|
|
||||||
|
#delay for long delay
|
||||||
|
long_delay = timedelta(hours=1)
|
||||||
|
|
||||||
|
|
||||||
queue = [(False, None)] * 100 #queue of recent frames
|
queue = [(False, None)] * 100 #queue of recent frames
|
||||||
last_time_stamp = five_minute_segment_from(datetime.now())
|
last_time_stamp = five_minute_segment_from(datetime.now())
|
||||||
|
|
||||||
# live webcam feed
|
# live webcam feed
|
||||||
camera = cv2.VideoCapture(0)
|
camera = cv2.VideoCapture(0)
|
||||||
camera.set(cv2.CAP_PROP_FPS, 30.0)
|
|
||||||
if not camera.isOpened():
|
if not camera.isOpened():
|
||||||
print("Cannot open camera")
|
print("Cannot open camera")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# video writer
|
# video writer
|
||||||
fourcc = cv2.VideoWriter_fourcc(*'H264')
|
fourcc = cv2.VideoWriter_fourcc(*'H264')
|
||||||
out = cv2.VideoWriter(video_address_for(last_time_stamp), fourcc, camera.get(cv2.CAP_PROP_FPS), (int(camera.get(3)),int(camera.get(4))))
|
out = cv2.VideoWriter(path_to_video_at(last_time_stamp), fourcc, camera.get(cv2.CAP_PROP_FPS), (int(camera.get(3)),int(camera.get(4))))
|
||||||
|
|
||||||
# video feed from previously captured video
|
# video feed from previously captured video
|
||||||
old_time = cv2.VideoCapture(video_address_for(last_time_stamp))
|
old_time = cv2.VideoCapture(path_to_video_at(last_time_stamp))
|
||||||
|
|
||||||
|
cv2.namedWindow("mirror", cv2.WINDOW_NORMAL)
|
||||||
|
cv2.setWindowProperty("mirror", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
||||||
|
|
||||||
idx = 0
|
idx = 0
|
||||||
offset = 0
|
offset = 0
|
||||||
longterm = False
|
longterm = False
|
||||||
while(True):
|
while(True):
|
||||||
if last_time_stamp != five_minute_segment_from(datetime.now()):
|
if last_time_stamp != five_minute_segment_from(datetime.now()):
|
||||||
|
# find file older than our long delay
|
||||||
|
old_file = path_to_video_at(five_minute_segment_from(datetime.now() - long_delay - timedelta(minutes=5)))
|
||||||
|
print(f"deleting old file {old_file}")
|
||||||
|
os.remove(old_file)
|
||||||
|
|
||||||
out.release()
|
out.release()
|
||||||
out = cv2.VideoWriter(video_address_for(last_time_stamp),
|
out = cv2.VideoWriter(path_to_video_at(last_time_stamp),
|
||||||
fourcc,
|
fourcc,
|
||||||
camera.get(cv2.CAP_PROP_FPS),
|
camera.get(cv2.CAP_PROP_FPS),
|
||||||
(int(camera.get(3)), int(camera.get(4)))
|
(int(camera.get(3)), int(camera.get(4)))
|
||||||
)
|
)
|
||||||
if old_time.isOpened():
|
if old_time.isOpened():
|
||||||
old_time.release()
|
old_time.release()
|
||||||
old_time = cv2.VideoCapture(video_address_for(five_minute_segment_from(datetime.now() - timedelta(minutes=10))))
|
|
||||||
|
new_file = path_to_video_at(five_minute_segment_from(datetime.now() - timedelta(minutes=10)))
|
||||||
|
pint(f"opening the previously recorded file {new_file} to read from for long mirror")
|
||||||
|
old_time = cv2.VideoCapture(new_file)
|
||||||
|
|
||||||
last_time_stamp = five_minute_segment_from(datetime.now())
|
last_time_stamp = five_minute_segment_from(datetime.now())
|
||||||
|
|
||||||
ret, frame = camera.read()
|
ret, frame = camera.read()
|
||||||
frame = cv2.flip(frame, 1)
|
frame = cv2.flip(frame, 1)
|
||||||
|
|
||||||
#recod the frame
|
# record the frame to the appropriate file, and also to the short term buffer
|
||||||
out.write(frame)
|
out.write(frame)
|
||||||
queue[idx] = ret, frame
|
queue[idx] = ret, frame
|
||||||
|
|
||||||
|
prev_frame_valid, prev_frame = queue[(idx - offset) % len(queue)]
|
||||||
|
old_frame_valid, old_frame = old_time.read()
|
||||||
|
if not longterm and prev_frame_valid:
|
||||||
|
cv2.imshow('mirror', prev_frame)
|
||||||
|
elif longterm and old_frame_valid:
|
||||||
|
cv2.imshow('mirror', old_frame)
|
||||||
|
|
||||||
showo, fr = queue[(idx - offset) % len(queue)]
|
key = cv2.waitKey(16) # listen for keyprress for some number of ms
|
||||||
if longterm:
|
if key & 0xFF == ord('q') or key == 27: # q or esc
|
||||||
ret2, frame2 = old_time.read()
|
|
||||||
if ret2:
|
|
||||||
cv2.imshow('vid', frame2)
|
|
||||||
elif showo:
|
|
||||||
cv2.imshow('vid', fr)
|
|
||||||
|
|
||||||
# the 'q' button is set as the quitting button you may use any desired button of your choice
|
|
||||||
key = cv2.waitKey(1) & 0xFF
|
|
||||||
if key == ord('q'):
|
|
||||||
break
|
break
|
||||||
if key == ord('a'):
|
if key & 0xFF == ord('a'):
|
||||||
offset += 1
|
offset += 1
|
||||||
if key == ord('d'):
|
if key & 0xFF == ord('d'):
|
||||||
offset -= 1
|
offset -= 1
|
||||||
if key == ord('z'):
|
if key & 0xFF == ord('z'):
|
||||||
longterm = not longterm
|
longterm = not longterm
|
||||||
|
|
||||||
idx = (idx + 1) % len(queue)
|
idx = (idx + 1) % len(queue)
|
||||||
|
Loading…
Reference in New Issue
Block a user