Giter VIP home page Giter VIP logo

laserguntargetcaster's Introduction

"Laser" Gun Target Caster

Purpose

Detect a red laser pointer on a surface and sends the picture to a Chromecast device on change.

More elaborately, this allows you to set up a target and "shoot" at it using a red laser pointer and view the resulting "impact point" on a Chromecast device, or old Android phone/tablet running something like AirScreen.

This allows me to do target practice with a modified airsoft gun with a laser pointer in it, from 10m away, in silence, and not have to get up to see where I hit, and not waste ammo or paper targets wastefully.

Also, friggin' laser beams!

How It's Made

  • A thread is started to detect as close as possible to the first appearance of a laser bead on a surface, using OpenCV
  • A thread is started to act as a webserver for Chromecast content. This server always returns the contents of a file named latest.jpg, no matter what is asked for. The Chromecast device doesn't seem to refresh a file if it's told to show the same URL twice within a period of time.
  • When a point has been detected, the frame gets written to disk as latest.jpg, also a signal is set
  • When the signal is set, the main thread tells the Chromecast to show a new random image from the webserver started locally
  • The Chromecast asks for the "new" uncached file, and gets served the latest impact capture

Example

Install dependencies once: pip install numpy opencv-contrib-python-headless pychromecast OR if you want local preview functionality: pip install numpy opencv-contrib-python pychromecast

python lasertarget.py --address 192.168.0.2 --port 8080 --index 2 --castto "Target Monitor" --display

  • address/adapter and port of local webserver that will be created on the same computer this script is running on, has to be on the same network as Chromecast device (the device will pull content from this address).
  • index of camera device in OpenCV list, trial and error for now
  • castto the Chromecast device with this name
  • display the debug windows

python lasertarget.py

  • starts a webserver using the default IP of the device being run on
  • uses the first camera device
  • will cast to the first device it finds, or just shows the preview window if none are found

Running Headless

You may wish to run this on a Raspberry Pi 3 without X installed, on Raspbian Lite. If so, you will need the following dependencies

sudo apt install libhdf5-100
sudo apt install libharfbuzz0b
sudo apt install libwebp6
sudo apt install libjasper1
sudo apt install libilmbase12
sudo apt install libopenexr22
sudo apt install libgstreamer1.0-0
sudo apt install libavcodec-extra57
sudo apt install libavformat57
sudo apt install libswscale4
sudo apt install libgtk-3
sudo apt install libgtk-3-0
sudo apt install libqtgui4
sudo apt install libqt4-test

and you can run it without the display command line:

python lasertarget.py

Tech Used

  • Modified version of this OpenCV project for detecting the laser pointer (scalable window; trigger on change; only show first laser hit, not trail)
    • pip install numpy opencv-contrib-python
  • HTTPServer to serve the latest image regardless of client caching settings
  • PyChromecast to display the latest image on a Chromecast device
    • pip install pychromecast

laserguntargetcaster's People

Contributors

noshbar avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.