from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import util

with Database() as db:
    print('Ingesting video into Scanner ...')
    [input_table], _ = db.ingest_videos(
        [('example', util.download_video())], force=True)

    print('Detecting faces...')
    bboxes_table = pipelines.detect_faces(
        db, input_table, lambda t: t.all(), 'example_bboxes')

    print('Drawing faces onto video...')
    frame = input_table.as_op().all()
    bboxes = bboxes_table.as_op().all()
    out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
    job = Job(columns = [out_frame], name = 'example_bboxes_overlay')
    out_table = db.run(job, force=True)
    out_table.column('frame').save_mp4('example_faces')

    print('Successfully generated example_faces.mp4')

from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import util

movie_path = util.download_video() if len(sys.argv) <= 1 else sys.argv[1]
print('Detecting faces in movie {}'.format(movie_path))
movie_name = os.path.splitext(os.path.basename(movie_path))[0]

with Database() as db:
    print('Ingesting video into Scanner ...')
    [input_table], _ = db.ingest_videos(
        [(movie_name, movie_path)], force=True)

    print('Detecting faces...')
    bboxes_table = pipelines.detect_faces(
        db, input_table, lambda t: t.all(),
        movie_name + '_bboxes')

    print('Drawing faces onto video...')
    frame = input_table.as_op().all()
    bboxes = bboxes_table.as_op().all()
    out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
    job = Job(columns = [out_frame], name = movie_name + '_bboxes_overlay')
    out_table = db.run(job, force=True)
    out_table.column('frame').save_mp4(movie_name + '_faces')

    print('Successfully generated {:s}_faces.mp4'.format(movie_name))

Update face detect example to take a path argument
Update face detect example to take a path argument

  from scannerpy import Database, DeviceType, Job
  from scannerpy.stdlib import pipelines
  import subprocess
  import cv2
  import sys
  import os.path
  sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
  import util
  
+ movie_path = util.download_video() if len(sys.argv) <= 1 else sys.argv[1]
+ print('Detecting faces in movie {}'.format(movie_path))
+ movie_name = os.path.splitext(os.path.basename(movie_path))[0]
+ 
  with Database() as db:
      print('Ingesting video into Scanner ...')
      [input_table], _ = db.ingest_videos(
-         [('example', util.download_video())], force=True)
+         [(movie_name, movie_path)], force=True)
  
      print('Detecting faces...')
      bboxes_table = pipelines.detect_faces(
-         db, input_table, lambda t: t.all(), 'example_bboxes')
+         db, input_table, lambda t: t.all(),
+         movie_name + '_bboxes')
  
      print('Drawing faces onto video...')
      frame = input_table.as_op().all()
      bboxes = bboxes_table.as_op().all()
      out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
-     job = Job(columns = [out_frame], name = 'example_bboxes_overlay')
+     job = Job(columns = [out_frame], name = movie_name + '_bboxes_overlay')
      out_table = db.run(job, force=True)
-     out_table.column('frame').save_mp4('example_faces')
+     out_table.column('frame').save_mp4(movie_name + '_faces')
  
-     print('Successfully generated example_faces.mp4')
+     print('Successfully generated {:s}_faces.mp4'.format(movie_name))
  
Update face detect example to take a path argument
## Code Before:
from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import util

with Database() as db:
    print('Ingesting video into Scanner ...')
    [input_table], _ = db.ingest_videos(
        [('example', util.download_video())], force=True)

    print('Detecting faces...')
    bboxes_table = pipelines.detect_faces(
        db, input_table, lambda t: t.all(), 'example_bboxes')

    print('Drawing faces onto video...')
    frame = input_table.as_op().all()
    bboxes = bboxes_table.as_op().all()
    out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
    job = Job(columns = [out_frame], name = 'example_bboxes_overlay')
    out_table = db.run(job, force=True)
    out_table.column('frame').save_mp4('example_faces')

    print('Successfully generated example_faces.mp4')

## Instruction:
Update face detect example to take a path argument
## Code After:
from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
import util

movie_path = util.download_video() if len(sys.argv) <= 1 else sys.argv[1]
print('Detecting faces in movie {}'.format(movie_path))
movie_name = os.path.splitext(os.path.basename(movie_path))[0]

with Database() as db:
    print('Ingesting video into Scanner ...')
    [input_table], _ = db.ingest_videos(
        [(movie_name, movie_path)], force=True)

    print('Detecting faces...')
    bboxes_table = pipelines.detect_faces(
        db, input_table, lambda t: t.all(),
        movie_name + '_bboxes')

    print('Drawing faces onto video...')
    frame = input_table.as_op().all()
    bboxes = bboxes_table.as_op().all()
    out_frame = db.ops.DrawBox(frame = frame, bboxes = bboxes)
    job = Job(columns = [out_frame], name = movie_name + '_bboxes_overlay')
    out_table = db.run(job, force=True)
    out_table.column('frame').save_mp4(movie_name + '_faces')

    print('Successfully generated {:s}_faces.mp4'.format(movie_name))
