Skip to content

Commit

Permalink
c_detectMarkers and makeVideo: further deal with broken frames. Of co…
Browse files Browse the repository at this point in the history
…urse these can't be processed, so need to either skip (c_detectMarkers), or replace with a black frame (makeVideo). Also aligned frame counting between these two files, and moved where we print what frame we're on so all that handling is in just one place.
  • Loading branch information
dcnieho committed Aug 24, 2023
1 parent d409783 commit 4570506
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/glassesValidator/process/c_detectMarkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ def do_the_work(working_dir, config_dir, gui, show_rejected_markers):
# process frame-by-frame
ret, frame = cap.read()
frame_idx += 1

# check if we're done. Can't trust ret==False to indicate we're at end of video, as it may also return false for some frames when video has errors in the middle that we can just read past
if (not ret and (frame_idx==0 or frame_idx/nframes>.99)) or (hasAnalyzeFrames and frame_idx > analyzeFrames[-1]):
# done
break
if frame_idx%100==0:
print(' frame {}'.format(frame_idx))
if not ret or frame is None:
# we don't have a valid frame, continue to next
continue

if show_visualization:
keys = gui.get_key_presses()
Expand Down Expand Up @@ -192,9 +198,6 @@ def do_the_work(working_dir, config_dir, gui, show_rejected_markers):
stopAllProcessing = True
break

if frame_idx%100==0:
print(' frame {}'.format(frame_idx))

csv_file.close()
cap.release()
if show_visualization:
Expand Down
13 changes: 8 additions & 5 deletions src/glassesValidator/utils/makeVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,24 @@ def do_the_work(working_dir, config_dir, gui, main_win_id, show_rejected_markers
if analyzeFrames is None:
analyzeFrames = []

frame_idx = 0
frame_idx = -1
armLength = poster.markerSize/2 # arms of axis are half a marker long
subPixelFac = 8 # for sub-pixel positioning
stopAllProcessing = False
hasRequestedFocus = not isMacOS # False only if on Mac OS, else True since its a no-op
while True:
# process frame-by-frame
ret, frame = vidIn.read()
frame_idx += 1

# check if we're done. Can't trust ret==False to indicate we're at end of video, as it may also return false for some frames when video has errors in the middle that we can just read past
if not ret and (frame_idx==0 or frame_idx/nframes>.99):
break
if not show_visualization and frame_idx%100==0:
print(' frame {}'.format(frame_idx))
if not ret or frame is None:
# we don't have a valid frame, use a fully black frame
frame = np.zeros((int(height),int(width),3), np.uint8) # black image
refImg = poster.getImgCopy()

# detect markers, undistort
Expand Down Expand Up @@ -233,10 +240,6 @@ def do_the_work(working_dir, config_dir, gui, main_win_id, show_rejected_markers
if closed:
stopAllProcessing = True
break
elif (frame_idx+1)%100==0:
print(' frame {}'.format(frame_idx+1))

frame_idx += 1

vidIn.release()
vidOutScene.close()
Expand Down

0 comments on commit 4570506

Please sign in to comment.