Creation: Concerned TV - Supercharged by Hoot Pi & OpenCV

Happy Halloween!

This year I decided to expand on the Idea of a classical horror movie cliche: the mirror frighten off(a scene where a reflection is accustomed suddenly divulge a monster, ghost, etc.) I've used a Hiss Pi, television camera, and OpenCV to make up a creepy-crawly camera fertilise on an old B&W TV which is triggered by face/centre sensing. When the Raspberry Private eye detects a face, it turns along the TV displaying a live television camera feed. When the face looks away from the TV a ghost is displayed in the background knowledge(using background deduction). Once the face looks back down at the Idiot box, sees the ghost and turns behind a second time, the ghost disappears and, afterward a fewer seconds the Goggle bo turns off, restarting the cycle.

I've likewise enforced eye detection to detect faces with masks, so you can use this arsenic an outdoor decoration in 2022!

Outline

In the first mistreat, I'll explicate the inspiration behind this task, later I will give you a list of all the things you need to build this project on your own. Then I'll show you how to set up your Snort Principal investigator to run this program. later I will show you how the face/eye detection and background remotion algorithms work. Later giving you a whole step by whole step assembly guide I'll end the Instructable with a troubleshooting guide.

Let's get started!

Step 1: Inspiration

As I mentioned above, the inspiration for this project came from a famous prank utilized in horror movies. I wanted to build a project that could create the same upshot. The trick is commonly done in 4 parts:

  1. A character goes to get something from the mirror cabinet, we see the lineament's reflection in front of the mirror.
  2. They open the cabinet or get distrait spell doing something else.
  3. They look back at the mirror again and see something is behind them.
  4. They look behind and take care nothing.

Hither's a compiling of mirror scares from various movies to hold you an idea:

I wanted to produce this effect on a different medium, and I distinct to use a crappy overaged TV. The low resolving and interference created a unique effect as if the TV was mirroring a latitude but dissimilar reality. This is where I came upbound with this Melodic theme.

Step 2: Tools & Parts

All the necessary files (3D print files and Code) are attached to this step, also you can find the latest version of the code at this connection.

Tools:

  • 3D printer (optional if you send away use wood, acrylic resin, etc. to mount the Raspberry bush Pi)
  • Practise/Dremel
  • Bonding Iron

Parts:

  • Raspberry Pi 3 operating room better(more processing magnate --> less lag)
  • Raspberry Pi camera
  • Cathode-ray tube TV
  • Av to RF convertor (If the TV does not have composite stimulant)
  • YK04 Remote control Module
  • KY-019 5V Relay Module
  • 4 x M2.5 threaded spacer
  • 4 x m2.5 Nut & bolt
  • 2 x 330 Ohm Resistors
  • Composite video cable for Raspberry Operative

3D Printed Parts:

  • Raspi Mount
  • Camera mount

Step 3: Setting Up the Raspberry Shamus

Note: You can skip this footstep if you have already installed the Bir Sherloc OS

Installment Raspberry Sherloc OS

note: you'll need a keyboard, creep, and admonisher to set up your raspberry principal investigator

Earlier we get into the program, we first need to set up our Raspberry Pi.You can follow this functionary conduct on how to install an operating system on your Pi:

https://WWW.raspberrypi.org/documentation/installation/installing-images/README.Dr.

Make sure you instal "Raspberry Protease inhibitor OS (32-bit) with desktop and suggested software", this version leave have all the software we need to run our broadcast.

After you've installed the operating scheme and started your raspberry pi, explicit up the terminal and typewrite:

sudo raspi-config            

This will open awake the contour menu, navigate to Interfacing Options, and enable the tv camera and SSH .

Facultative SSH will avail US bewilder into the Raspberry Pi remotely so we North Korean won't have to use a keyboard, mouse, and monitor every time.

Now our Raspberry Pi is ready for our code!, in the next stone's throw, we'll assembly the camera and electronics to our Raspberry pi and test it with the Code.

Step 4: Forum - Electronics

note: At this degree, you Don't have to use a bonding iron. I strongly advocate you to use jumper cables, then you behind change any component if it isn't working properly.

Raspberry Pi GPIO Pins

I've utilized the physical immobilize numbering as shown in the plot below

Raspberry GPIO diagram

source: https://www.raspberrypi.org/documentation/usage/gpio/

The Camera

The tv camera port is between the HDMI output and Audio jack, insert the camera cable in some respects that the open touch points on the cable face the HDMI interface.

Connect the Liquidator, RGB and Relay with jumper cables to your Boo Shamus Eastern Samoa shown:

YK04 Receiver

YK04 Raspberry Principal investigator 3
GND GND
POWER 3.3V
D0 12
D1 16

RGB LED

LED Hoot Pi 3
GND GND
Bolshy 22
Greenness 24
BLUE 26

Relay

Relay Raspberry Private eye 3
GND GND
Magnate 5V
Information 32

Step 5: The Code

We'll atomic number 4 using OpenCV(Heart-to-heart Source Computer Visual sensation Library) for face detection and background removal. Let's install this library happening our Pi,

Install OpenCV

The OpenCV Python module can be downloaded from the Raspbian repository, to do this simply open up a Terminal and type;

sudo liable update sudo apt install python3-opencv

this command will set u all packages necessary to run OpenCV.

bring up your Pi after the installation with;

sudo reboot

Haunted TV Code

First, navigate to the Documents folder;

cd Documents

next, install the Haunted TV code from the Github Repository by:

git knockoff https://github.com/gocivici/haunted-tv.git

This command will put in the most recent rendering of the code.

Later navigating into the project pamphlet;

cd haunted-tv

you should be able-bodied to run the syllabu by:

python3 hauntedTV.py

Now to test and debug the code you can use the keyboard or else of the remote. Use 'h' to have a taken up delineation and 'a' to pop nerve spying.

Mention: If you get an computer error when you run the code, check the troubleshooting guide at the end.

Autostart

for more info and troubleshooting check: https://learn.sparkfun.com/tutorials/how-to-pass around-a-raspberry-principal investigator-computer program-along-inauguration#method-2-autostart

We deprivation to run our script automatically when the Raspberry Sherloc boots up. To do that we will be exploitation a method called Autostart. With this method, the graphical interface will initialize archetypical and and so run our script.

Open the Terminal and type:

mkdir /menage/pi/.config/autostart nano /home/pi/.config/autostart/hauntedTV.desktop            

Now imitate the table of contents below inside the file you've just created:

[Desktop Entry] Type=Covering Key out=HauntedTV Exec=/usr/bin/python3 /home/sherloc/Documents/haunted-idiot box/hauntedTV.py            

save, exit with ctrl + x and reboot:

sudo reboot

Customization

To edit out the code while in the project directory case:

sudo nano hauntedTV.py

On that point are three timers that are important for the jumpscare effect to act upon, these are:

timeTV = 5 timeGhost = 25 timeNoGhost = 10

These values are not in seconds. They are a prise that is set past the faceFreqCounter . This counter starts when a face is heard, and continues to count if the face is still in the render. If the face leaves the screen for more than 4 seconds the counter is set to 0. (This way false positives are filtered)

  1. timeTV: When the faceFreqCounter hits this value, the TV will charge up.
  2. timeGhost: When the faceFreqCounter hits this value, the ghost bequeath follow displayed after the face looks away. You give notice set this to a large value if you want your guests to inspect the TV a little more than before the ghost is displayed.
  3. timeNoGhost: This value determines when to incapacitate the profile of the ghost aft the face sees the ghost and looks away.

You should also customize the setting sensitivity in the code.

backgroundSensitivity = 20

This measure determines the sensitivity of the scop subtraction. You should increase this apprais If the haunted picture is not visible in the background.

You'atomic number 75 done! Now it's clock time to mental test the setup with your TV.

Step 6: Face/Eye Detecting & Background Removal (Optional)

In this step, I will move into detail on how I used OpenCV to notice faces and remove the ground. You can skip this step if you just want to download and run the code.

Face/Eye detection with OpenCV

There are many a methods to detect a face, the method I used is called object detection with Haar Cascade Range. Haar Cascade down is a political machine learning object sleuthing algorithmic program that can discover objects in an image based on the concept of features. (Penetrate here to se how IT plant)

This method bottom be used to detect any object not fair-and-square faces. In order to detect a face, primary, we need cascade files. You tin use any search engine to find various Cascades of things you want to detect.

In this project, we'll use Face Cascade and Middle Cascade, you tooshie discovery them present and here.

After downloading the cascades As .xml files we import them to our code:

import numpy as Np import cv2  #importing the cascades perceived = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #detected = cv2.CascadeClassifier('haarcascade_eye.xml')

I'm just importation the face cascade for now, as I mentioned in the dying step you can tailor-make the code to detect faces, eyes or both.

Following, we come out the photographic camera and initialise a while iteration so the encipher checks if a face is detected:

cam = cv2.VideoCapture(0) patc Legitimate:     ret, img = Cam.read()     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)     faces = detected.detectMultiScale(gray, 1.3, 5)<br>

The shower classifier, "detectMultiScale" simply detects the faces. At once we create a loop to draw a rectangle around the detected faces.

for (x,y,w,h) in perceived:     cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)     #put cypher Here to foot race when a face is detected

eventually we reveal the final image in a windowpane:

cv2.imshow('img',img)            

Here's the full computer code for face detective work:

import numpy as np importee cv2  #importation the cascades detected = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #detected = cv2.CascadeClassifier('haarcascade_eye.xml') cam = cv2.VideoCapture(0) while Unfeigned:     ret, img = River Cam.read()     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)     faces = noticed.detectMultiScale(gray, 1.3, 5)     for (x,y,w,h) in detected:         cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)         #put write in code here to hightail it when a face is detected     cv2.imshow('img',img) cam.liberate() cv2.destroyAllWindows()

save this file as FaceDetection.py and run it, you should embody able to see a blue rectangle around your face.

Background Removal with OpenCV

I wanted to use a background remotion algorithm to remove and replace the play down with a haunted picture attached to the background. With this method, I was able to put the ghost behind the person. This was an important sport since I wanted to create the burden that in that location was a ghost behind the person. While searching the net on how to answer this I found a very good tutorial:

In this tutorial, Misbah shows us how to put back the background with a video. however, to use this with our code we take to edit this for our needs. We deficiency to display a picture instead of a video in the background when triggered.

There are also other background subtraction methods that you crapper use. I volition relate all the sources at the tail of this step.

References:

https://pythonprogramming.net/haar-shower-face-eye-detection-python-opencv-tutorial/

https://docs.opencv.org/3.4/d1/dc5/tutorial_background_subtraction.html

https://github.com/misbah4064/backgroundRemoval

Step 7: First Prototype & Test

For the first epitome, I built an adjustable stand for the tv camera and place it on the TV with the Raspberry Pi. At this level, the important objective is to test the setup and TV to check if they're working properly.

  • Connect your Raspberry PI to the TV with the composite overseas telegram (If your TV doesn't feature a composite input use the AV-Unnilquadium converter)
  • Connect the Raspberry Pi to mightiness and wait for it in addition up.
  • Check if there is a problem with the video provender

Whole step 8: Design & 3D Print

There are two 3d printed parts for this build, one is the Bronx cheer Pi mount that will be glued inside the TV. The other part is the television camera mount, which volition help us mount the camera.

Note: You can edit/customize these parts in fusion360 they are attached to this step

The printing machine I used is the TEVO Tornado with the following settings:

  • Nozzle: 0.4mm
  • infill: %30
  • Filament: PLA

Step 9: Soldering

There are two parts to solder. The Light-emitting diode and the antenna for the Receiver.

Step 10: Disassemble & Pristine the TV

Rubber Freshman!

Even though we will be alone disassembling a puny part of the TV, it can be very dangerous if you assume't use safety procedures. High voltage may remain stored inside the tube even afterward being unplugged.

I highly recommend you to read MrJentis's instructable happening this matter:

https://www.instructables.com/How-to-break apart-a-CRT-monitor/

Ill-use 11: Climbing the Raspberry Pi

Step 12: Mounting the Camera

  • I removed the earphone outturn jack on the TV and mounted the tv camera there.

Step 13: Final Fabrication & Test

Now with your Bronx cheer Pi affixed to the Telecasting, power up the apparatus. The Raspberry Pi should boot out and run the Python hand at startup, after a few seconds the TV should turn on, and you should be able to see yourself on the TV.

Next, find a nervous dress up, get in front of the TV with your Remote and aim the Haunted Scene by urgent B on the Remote. At once the script is ready to run. Press the D button on the remote, the TV should cut and starting signal sleuthing faces.

Trial run the frame-up by acquiring before of the Tv set and look away after a few seconds. This should trigger the setup and now you should be healthy to see the Haunted Image in the background, if not, attend the Troubleshooting guide at step 13.

Step 14: Troubleshooting

+The Haunted visualise is non perceptible.

-temperate is very important for background removal. Make sure the TV is in a advantageously-lit area. Also move back the light root behind the TV.

+I'm not sure if face signal detection is working or not.

-Cash in one's chips to step 6 and turn tail the face detection code alone. You should be able to find out a rectangle around your human face.

+The CRT Telecasting isn't displaying the picture.

-Get into the config.txt file out in your raspberry pi, and make a point that the TV region is the same as your TV.

Leave a commentary If you're having other problems. I'll compile them and try to do them present.

+There's very much of lag/response time on the live feed.

- I've used a Raspberry bush Pi 3 for this project. Any Raspberry pi with a lower processing power could cause latent period and lag. But in that respect are whatever optimizations you rear exercise to prevent that.

Gradation 15: What's Next

In this step, I will list few ideas that I had. But did not find the time/resources to add them:

  • A Bluetooth utterer to make a haphazardness when the touch appears behind.
  • An Invisible Television camera and LEDs could make this process in the dark. Which creates a scarier vibe.
  • A specialised intend the TV with spooky decorations.
  • A more powerful computer, same the Nvidia Jetson which is built for visual tasks. This would reduce the reaction time.

Feel free to add more ideas or ways to improve this project in the comments!

Be the First to Apportion

Recommendations