Use OpenCV and Python to display the webcam video in a Godot Scene.
Godot is a cross-platform, free and open-source game engine released under the permissive MIT license.
OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly for real-time computer vision.
PyInstaller bundles a Python application and all its dependencies into a single package.
- Clone this repo.
- Import project.godot using Godot
- Edit the project
- Or, skip the next step and press "Run" instead
- Press "Run Project (F5)"
When you make changes to the Python script, you'll need to tell the Godot application not to start the webcam server.
- To activate the virtual environment, run
- [macOS]
source venv/bin/activate
- [Windows]
venv\Scripts\activate
- [macOS]
- Run the webcam software,
python webcam_server.py
- Edit the GDScript so that it doesn't try to start the server by commenting out
webcam_server_start()
- Start the scene (see "Testing the Webcam Server", above)
- The scene should connect automatically; when
_ready()
callswebcam_server_connect()
- The scene should connect automatically; when
- To exit the server, press [Ctrl]+[C]
- To exit the virtual environment, run
deactivate
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller is tested against Windows, MacOS X, and Linux. However, it is not a cross-compiler; to make a Windows app you run PyInstaller on Windows, and to make a Linux app you run it on Linux. etc. NOTE: Whenever you make changes to the Python code, you must regenerate this executable.
- Run
pyinstaller webcam_server.spec
- This will create a dist folder containing the executable.
- The executeable is called in texture_rect.gd by
webcam_server_start()
- Open the root folder using VS Code
- If you use GitHub Desktop, select the "Open in Visual Studio" button
- Open the integrated terminal
- To create a virtual environment, run
python -m venv venv
- This creates a folder called "venv" that contains a local copy of Python and its package manager, "pip".
- To activate the virtual environment, run
- [macOS]
source .venv/bin/activate
- [Windows]
.venv\Scripts\activate
- [macOS]
- To install required packages, run
pip install opencv-python websockets numpy pyinstaller
- Verify package installation by running
pip list
- To exit the venv, run
deactivate