Adding Spooky Visual Effects to a TV with a Raspberry Pi and OpenCV

Use OpenCV facial tracking and a Raspberry Pi to display hidden ghosts on this haunted TV.

Although Halloween has passed on already this year, it is still nice to look back at some impressive projects that makers were able to come up with. One of these is a haunted TV, which expands on the idea of the mirror scare that is used in horror films where a ghost suddenly appears behind the person.

Hardware

To achieve this spooky effect, Instructables user gocivici gathered the components he needed for his TV. The first is a Raspberry Pi, and it runs the software that detects faces, adds the ghost, and automatically turns off the TV after the cycle is complete. Video is taken with a Raspberry Pi Camera Module, and power is provided to the TV through a relay module. To get that creepy old television vibe, he opted for a CRT which has prominent glitches and scanlines at times. An AV-to-RF converter can be used if the television does not support the native composite video from the Pi.

Assembling the Electronics

Gocivici started constructing this project by attaching several of the components to the Raspberry Pi with jumper wires. The YK04 remote control module gets connected to GPIO pins 18 and 23, the RGB LED (which displays the TV's current state) goes to pins 25, 8, and 7, and finally, the relay module is attached to pin 12. It's job is to switch power going to the television on and off for an added "spooky" effect when a person gets close.

The Raspberry Pi is mounted to a plate that is placed inside of the TV to hide it, and the camera module is cleverly concealed where the headphone jack normally is.

Using OpenCV

Just like in a horror film, the TV turns on when a person looks at it, then shows a ghost when the person looks away, and finally turns off the TV once they look back at it. In order to detect faces, the Raspberry Pi first reads in an image from the Pi Camera Module. This is then converted into grayscale and passed to a Haar Cascades Classifier, which detects any faces and eyes within the image and stores their bounding boxes in an array.

The Program

The program has four states:

  • Off and looking for a face.
  • Face found, TV on.
  • Looking away and displaying a ghost.
  • Looking back at the TV and hiding the ghost.

This cycle continues indefinitely, which is great for greeting trick-or-treaters or as a fun toy. But then there is the question of how to place a ghost in the background without covering up the user, just like how a mirror would operate. For this challenge, the project's creator used a background removal algorithm, and it works by generating a mask of the foreground (in this case it's the person looking at the TV) and then replacing the area not covered by the mask with a ghost.

Getting Spooked

A few seconds after applying power to the whole setup, the TV turns on and shows an image, complete with all of the artifacting and glitches from the composite source. Pressing the B button on the remote takes a picture of the haunted scene to be displayed in the background, and pressing D runs the program.

This project is a great way to scare unsuspecting people, and it is an implementation of a cliched horror movie idea done right. I look forward to seeing what other scary scenes can be recreated by makers in the coming years.

Arduino “having11” Guy
19 year-old IoT and embedded systems enthusiast. Also an interned at Hackster.io and love working on projects and sharing knowledge.
Related articles
Sponsored articles
Related articles