Compare commits

...

3 Commits

Author SHA1 Message Date
6e7192d157 YACWC 2025-07-14 17:57:59 -04:00
abb61f9f88 YACWC 2025-07-14 12:52:32 -04:00
cc5f670374 bump 2025-07-14 12:52:30 -04:00
3 changed files with 221 additions and 3 deletions

6
.gitignore vendored
View File

@@ -139,9 +139,9 @@ venv.bak/
# mkdocs documentation
/site
.mp4
.m4v
.mkv
*.mp4
*.m4v
*.mkv
# mypy
.mypy_cache/
.dmypy.json

View File

@@ -0,0 +1,150 @@
import os
dir_scan = '/srv/ftp/hummingbird/2025/07/14'
species_match = {'Archilochus colubris'}
import json
json_to_load = list()
for cwd, dirs, files in os.walk(dir_scan):
for x in files:
if x.endswith('.json'):
cpath = os.path.join(cwd, x)
with open(cpath,'r') as ff:
json_to_load.append(json.load(ff))
pass
# %%
fr_detections = dict()
for js in json_to_load:
js_path = js['json']['path']
fr_detections[js_path] = list()
w = js['video']['w']
h = js['video']['h']
for frame in js['scores']:
fr_num = frame['frame']
for det in frame['detections']:
if det['name'] in species_match:
det['fr_num'] = fr_num
fr_detections[js_path].append(det)
to_delete = list()
for key, vals in fr_detections.items():
if len(vals) == 0:
to_delete.append(key)
for x in to_delete:
fr_detections.pop(x)
# %%
import cv2
c_key = c_key.rsplit('/',1)[0] + '/hummingbird_00_20250714103229.json'
c_vid = c_key.replace('.json','.mp4')
cap = cv2.VideoCapture(c_vid)
# %%
rt_dir = '/home/thebears/Source/video_montages/hummingbird_choice/'
files = os.listdir(rt_dir)
cnnum = [x.replace('output_','').replace('.mp4','') for x in files if x.endswith('.mp4')]
nums = list()
for x in cnnum:
try:
nums.append(int(x))
except:
pass
if len(nums) == 0:
s_num = 1
else:
s_num = max(nums)+1
f_name = 'output_{0:03g}.mp4'.format(s_num)
c_sec = [0, 0]
output_vid_path = os.path.join('/home/thebears/Source/video_montages/hummingbird_choice/',f_name)
video_out = cv2.VideoWriter(output_vid_path, cv2.VideoWriter_fourcc(*'mpeg'),30,[1280,720])
import cv2
c_len = 0
total_len = len(list(fr_detections))
for c_key in sorted(list(fr_detections)):
c_len +=1
print(c_len, total_len)
c_kk = fr_detections[c_key]
c_vid = c_key.replace('.json','.mp4')
cap = cv2.VideoCapture(c_vid)
fr_nums = [c['fr_num'] for c in c_kk]
min_fr = min(fr_nums)
max_fr = max(fr_nums)
for x in range(min_fr):
cap.read();
coords_vec = [x['coords'] for x in c_kk]
cvec = {x['fr_num']:x['coords'] for x in c_kk}
c_frame = min(fr_nums)
color = (255, 0, 0)
thickness = 2
for x in range(min(fr_nums) ,max(fr_nums)):
is_ok, fr_data = cap.read();
if is_ok:
resz = cv2.resize(fr_data, (1280,720))
if x in cvec:
cp = cvec[x]
start_point = (int(cp[0]),int(cp[1]-24))
end_point = (int(0*cp[0]+cp[2]), int(0*cp[1]+cp[3]-24))
if start_point[0] < (1280/2):
c_sec[0]+=1
else:
c_sec[1]+=1
resz = cv2.rectangle(resz, start_point, end_point, color, thickness)
szz_left = '{0:2.2f}s'.format(c_sec[0]/30)
szz_right = '{0:2.2f}s'.format(c_sec[1]/30)
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 4
thickness = 2
cv2.putText(resz, szz_left, (0, 100), font, fontScale,(0,255,0),thickness,cv2.LINE_AA)
text_width, text_height = cv2.getTextSize(szz_right, font, fontScale, thickness)[0]
cv2.putText(resz, szz_right, (1280-text_width, 100), font, fontScale,(0,0,255),thickness,cv2.LINE_AA)
#), 1, (255, 0, 0), 2.0, cv2.LINE_AA)
video_out.write(resz)
cap.release()
video_out.release()
# %%
import cv2
c_kk = fr_detections[c_key]
fr_nums = [c['fr_num'] for c in c_kk]
min_fr = min(fr_nums)
max_fr = max(fr_nums)
coords_vec = [x['coords'] for x in c_kk]
if False:
import matplotlib.pyplot as plt
plt.ion()
plt.plot(fr_nums, coords_vec)
plt.legend(['x','y','w','h'])
# %%

View File

@@ -0,0 +1,68 @@
frigate_root = '/home/thebears/Videos/frigate/recordings'
output_vid_path = '/home/thebears/Source/frigate_video_create/video.mp4'
valid_cameras = {'nestcam3pb4'}
import os, sys
paths_add = list()
for dir_path, sub_dirs, files in os.walk(frigate_root):
camera = os.path.split(dir_path)[-1]
if camera in valid_cameras:
for f in files:
paths_add.append(os.path.join(dir_path, f))
# %%
import datetime as dt
import pytz
gmt = pytz.timezone('GMT')
est = pytz.timezone('US/Eastern')
dt_videos = dict()
for c_file in paths_add:
split_c_file = c_file.split('/')
c_date = split_c_file[-4]
c_hour = split_c_file[-3]
c_min_sec = split_c_file[-1]
date_str = c_date + " " + c_hour +"." + c_min_sec.replace('.mp4','') + ' GMT'
dc = dt.datetime.strptime(date_str, '%Y-%m-%d %H.%M.%S %Z')
c_datetime = gmt.localize(dc).astimezone(est)
dt_videos[c_datetime] = c_file
# %%
skp = 100
import cv2
video_out = cv2.VideoWriter(output_vid_path, cv2.VideoWriter_fourcc(*'mpeg'),30,[3840, 2160])
paths_write = list()
for i, x in enumerate(sorted(dt_videos)):
if ((i%100) != 0):
continue
vid_path = dt_videos[x]
paths_write.append(vid_path)
from tqdm import tqdm
idx = 0
for vid_path in tqdm(paths_write):
cap = cv2.VideoCaptvid
ure(vid_path)
_, fr = cap.read()
cap.release()
video_out.write(fr)
idx +=1
video_out.release()