This project demonstrates real-time 3D pose estimation of a QR code using a webcam, jsQR
, and opencv.js
. The goal is to detect the QR code, estimate its 3D pose relative to the camera, and apply a 3D CSS transformation.
- Real-time QR code detection from a webcam
- 3D pose estimation using OpenCV's Perspective-n-Point (PnP) algorithm
- Visualization using a 3D CSS transformation
- Node.js (version 14 or later)
- NPM (Node Package Manager)
- Clone the repository:
git clone https://github.com/your-username/qr-code-pose-estimation.git
- Change directory to the project folder:
cd qr-code-pose-estimation
npm install
To start a development server:
npm run start
This will open the project in your default browser.
Start json-server
json-server --port 5000 markerLinks.json
Start the json editor UI
yarn manage
Build a pdf from the json editor UI
ruby tracks.rb
To create a production build:
npm run build
This will generate the optimized output in the dist folder.
To serve the production build, use a simple HTTP server or include the build files in your preferred web server.
To manually test the pose estimation:
Point your webcam at a QR code with known dimensions (e.g., a square of 40mm wide). Adjust the focal length or QR code dimensions in the code if needed.
project/
│
├── public/
│ └── index.html
├── src/
│ └── main.js
├── .babelrc
└── package.json
The project assumes a focal length of 300 and an optical center at the center of the image. You can change the focalLength variable and adjust the position of the optical center in the main.js file:
const focalLength = 300;
The project assumes that the QR code is a square of 40mm wide. You can modify the markerSize variable in main.js if using a different size:
const markerSize = 40;
Contains the structure and styling for the webcam feed, canvas, and 3D CSS transformation. main.js Uses jsQR for QR code detection and opencv.js for pose estimation.
- QR Code Detection: Detects the QR code using jsQR and extracts corner points.
- 3D Pose Estimation: Corresponds detected QR code corners to 3D points. Estimates the pose using OpenCV's PnP algorithm.
- Applies a 3D CSS transformation.
### Problem: parcel watch error:
Expected content key 2d39cdf7c618ab5b to exist. Solution: rm -rf .parcel-cache
.
Currently in Parcel github issue tracker: parcel-bundler/parcel#8874
On the projector, open the page calib.html
. Adjust the sliders and hit the save button.
Open FFT.html and adjust the sliders to match the calibration, record the video and save the locations.
- ChatGPT
- jsQR
- opencv.js
- Parcel
MIT License