I need to setup a Windows 10 PC with a Webcam to automatically play a video when it detects a person, ideally face detection or motion detection.

Are there any Windows apps available that do this or an application that will detect motion and allow me to send commands to another program like VLC or XBMC?

This is not for recording video or surveillance, this is just to play a video for each person that walks up to the PC.

  • Is motion detection good enough, or do you need facial recognition? – Daniel Oct 22 '15 at 22:30
  • Because honestly you don't need Win10 for this, just a RasPi – Daniel Oct 22 '15 at 22:31
  • @Daniel It's a 27" All-In-One Touchscreen with Windows 10 - what linux software were you going to recommend for the RasPi? – Tim B Oct 23 '15 at 1:23
  • 1
    @TimB see raspberrypi.org/blog/… – Daniel Oct 23 '15 at 3:50
  • You would just write a script to fire off the video for each face. – Daniel Oct 23 '15 at 3:50

You can use OpenCV2 and python together to do this sort of thing in about 100 lines of code as can be seen from the example of face detection or the sample file.

  • Free, Gratis & Open Source
  • Cross Platform - works on Windows, OS-X, Linux, Android, iOS, even Raspberry-Pi with a camera module.

The sample file which connects to the camera and displays a window with the view from the camera with the face and eyes marked when they are detected could easily be modified to play, or trigger the playing of, a specific video file when a face is detected, (you could even tweak it to only play when the face detection is over a given size). The sample file:

#!/usr/bin/env python

import numpy as np
import cv2

# local modules
from video import create_capture
from common import clock, draw_str

help_message = '''
USAGE: facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]

def detect(img, cascade):
    rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30), flags = cv2.CASCADE_SCALE_IMAGE)
    if len(rects) == 0:
        return []
    rects[:,2:] += rects[:,:2]
    return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv2.rectangle(img, (x1, y1), (x2, y2), color, 2)

if __name__ == '__main__':
    import sys, getopt
    print help_message

    args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
        video_src = video_src[0]
        video_src = 0
    args = dict(args)
    cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
    nested_fn  = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")

    cascade = cv2.CascadeClassifier(cascade_fn)
    nested = cv2.CascadeClassifier(nested_fn)

    cam = create_capture(video_src, fallback='synth:bg=../data/lena.jpg:noise=0.05')

    while True:
        ret, img = cam.read()
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        gray = cv2.equalizeHist(gray)

        t = clock()
        rects = detect(gray, cascade)
        vis = img.copy()
        draw_rects(vis, rects, (0, 255, 0))
        if not nested.empty():
            for x1, y1, x2, y2 in rects:
                roi = gray[y1:y2, x1:x2]
                vis_roi = vis[y1:y2, x1:x2]
                subrects = detect(roi.copy(), nested)
                draw_rects(vis_roi, subrects, (255, 0, 0))
        dt = clock() - t

        draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000))
        cv2.imshow('facedetect', vis)

        if 0xFF & cv2.waitKey(5) == 27:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy