A real-time 3D window effect application that creates an immersive perspective illusion based on Johnny Chung Lee's experiments (2008). The screen acts as a fixed window through which a 3D scene is viewed, and the perspective changes dynamically as you move your head and body.
You can see the application in action by viewing the demo video included in this repository.
- Real-time head tracking using MediaPipe Face Landmarker
- Body position estimation for enhanced perspective control
- Dynamic 3D perspective that responds to your movements
- Smooth motion tracking with configurable smoothing factors
- FPS counter and detection status display
- Camera preview window in the bottom right corner
- Python 3.8 or higher
- Webcam/camera connected to your computer
- MediaPipe Face Landmarker model file (
face_landmarker.task)
git clone <repository-url>
cd 3dppip install -r requirements.txtThis will install:
opencv-python(>=4.8.0) - For camera and image processingnumpy(>=1.24.0) - For numerical computationsmediapipe(>=0.10.0) - For face and pose tracking
The application requires the MediaPipe Face Landmarker model file. You need to download it manually:
- Visit the MediaPipe Solutions page
- Download the face landmarker model file
- Place the file named
face_landmarker.taskin the project root directory
Alternatively, you can download it directly using:
- Direct download link: Face Landmarker Model
Important: The model file must be named exactly face_landmarker.task and placed in the same directory as 3dp.py.
python 3dp.pyThe application will:
- Open your default camera (camera ID 0)
- Create a full-screen window showing the 3D perspective effect
- Track your face and body movements in real-time
- Display FPS and detection status in the window title
Controls:
- Press
ESCto exit the application
For a simpler static 3D box visualization (without tracking):
python box.pyControls:
- Press
ESCto exit
3dp/
├── 3dp.py # Main application with head/body tracking
├── box.py # Simple 3D box visualization demo
├── face_landmarker.task # MediaPipe Face Landmarker model (download required)
├── requirements.txt # Python dependencies
└── README.md # This file
By default, the application uses a resolution of 1920x1080. You can modify this in 3dp.py:
screen_width = 1920 # Adjust according to your screen
screen_height = 1080 # Adjust according to your screenThe application uses camera ID 0 by default. To use a different camera, modify:
camera_id = 0 # Change to 1, 2, etc. for other camerasYou can adjust the smoothing factors for more or less responsive tracking:
smoothing_factor = 0.85 # General smoothing (0.0 = no smoothing, 1.0 = fully smooth)
body_smoothing_factor = 0.90 # Body position smoothing (higher = more stable)Adjust how much the 3D rectangle moves in response to your movements:
rectangle_sensitivity_x = 0.15 # Horizontal sensitivity (15% of movement)
rectangle_sensitivity_y = 0.12 # Vertical sensitivity (12% of movement)- Error:
ERROR: Could not open camera 0! - Solution:
- Check that your camera is connected and not being used by another application
- Try changing
camera_idto 1 or 2 if you have multiple cameras - On Linux, you may need to install
v4l-utilsor grant camera permissions
- Error: FileNotFoundError or similar when starting
- Solution:
- Ensure
face_landmarker.taskis in the same directory as3dp.py - Verify the file name is exactly
face_landmarker.task(case-sensitive) - Re-download the model file if corrupted
- Ensure
- Solutions:
- Reduce screen resolution in the code
- Close other applications using the camera
- Lower the smoothing factors for more responsive (but potentially jittery) tracking
- Ensure you have a good lighting environment for better face detection
- Solutions:
- Ensure good lighting conditions
- Position yourself in front of the camera
- Check that your face is clearly visible
- The window title will show "Body: NO" or "Face: NO" if detection fails
- Error:
ModuleNotFoundError: No module named 'cv2'or similar - Solution:
Or install packages individually:
pip install -r requirements.txt
pip install opencv-python numpy mediapipe
The application implements a 3D window effect inspired by Johnny Chung Lee's research:
- Face Detection: Uses MediaPipe Face Landmarker to detect facial landmarks and head pose
- Body Position Estimation: Estimates body position based on face position (using nose landmark as reference)
- Perspective Calculation: Calculates 3D perspective transformations based on head rotation (yaw, pitch, roll)
- Rectangle Transformation: Moves and scales the central 3D rectangle inversely to your movements, creating the window effect
- Line Rendering: Draws perspective lines that extend from the rectangle to screen edges
The effect creates an illusion that you're looking through a fixed window, with the scene moving in the opposite direction of your head movements.
Josep Santos Pujol
- LinkedIn: https://www.linkedin.com/in/josepsantos/
- Based on research by Johnny Chung Lee (2008) on head tracking for 3D displays
- Uses MediaPipe by Google for face and pose tracking
- Built with OpenCV and NumPy
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License is one of the most permissive open-source licenses, allowing:
- Commercial use
- Modification
- Distribution
- Private use
- Sublicensing
The only requirement is to include the original copyright notice and license text.
Contributions are welcome! Please feel free to submit a Pull Request.
- Studio Joanie Lemercier [https://www.facebook.com/studiojoanielemercier][https://www.linkedin.com/in/joanie-lemercier-98153757/]. Your idea was a true inspiration to me. Thank you for sharing it.
- Johnny Chung Lee for the original research on head tracking
- Google MediaPipe team for the excellent tracking library
- OpenCV community for computer vision tools