<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Calibration | Étienne Peillard</title><link>https://www.etiennepeillard.com/tag/calibration/</link><atom:link href="https://www.etiennepeillard.com/tag/calibration/index.xml" rel="self" type="application/rss+xml"/><description>Calibration</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Thu, 19 Feb 2026 00:00:00 +0000</lastBuildDate><image><url>https://www.etiennepeillard.com/media/sharing.png</url><title>Calibration</title><link>https://www.etiennepeillard.com/tag/calibration/</link></image><item><title>Lab — Projective augmented reality</title><link>https://www.etiennepeillard.com/teaching/lab/projective-ar/</link><pubDate>Thu, 19 Feb 2026 00:00:00 +0000</pubDate><guid>https://www.etiennepeillard.com/teaching/lab/projective-ar/</guid><description>&lt;h2 id="projective-augmented-reality">Projective Augmented Reality&lt;/h2>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="alt text" srcset="
/teaching/lab/projective-ar/image_hua7e3aa278d0be464fd894aab44259ad1_320305_0eeaf679062a2a085457c0452d37f088.webp 400w,
/teaching/lab/projective-ar/image_hua7e3aa278d0be464fd894aab44259ad1_320305_5ca371ff073ff534a10f2a375116c17d.webp 760w,
/teaching/lab/projective-ar/image_hua7e3aa278d0be464fd894aab44259ad1_320305_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://www.etiennepeillard.com/teaching/lab/projective-ar/image_hua7e3aa278d0be464fd894aab44259ad1_320305_0eeaf679062a2a085457c0452d37f088.webp"
width="760"
height="328"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>&lt;strong>▶ &lt;a href="code.zip">Base Code&lt;/a>&lt;/strong>&lt;/p>
&lt;h3 id="objectives">Objectives&lt;/h3>
&lt;p>This tutorial introduces the fundamentals of &lt;strong>projective augmented reality (AR)&lt;/strong>, from camera-based event detection to spatial augmentation using a projector.&lt;/p>
&lt;p>The reference application is a &lt;strong>tic-tac-toe game&lt;/strong>, but the architecture can be reused for any surface augmentation scenario (e.g., augmented board games, scientific visualization, research experiments).&lt;/p>
&lt;p>You will learn how to:&lt;/p>
&lt;ul>
&lt;li>Calibrate camera, projector, and physical surface&lt;/li>
&lt;li>Compute transition (homography) matrices between spaces&lt;/li>
&lt;li>Detect surface modifications&lt;/li>
&lt;li>Project consistent augmentations in real time&lt;/li>
&lt;/ul>
&lt;h3 id="system-overview">System Overview&lt;/h3>
&lt;p>We work in three different spaces:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Camera image space&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Projector image space&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Physical board space&lt;/strong>&lt;/li>
&lt;/ol>
&lt;p>These spaces are not aligned. Calibration is required to compute the transformations between them.&lt;/p>
&lt;p>The main goal is:&lt;/p>
&lt;ul>
&lt;li>Convert a detected move (camera space) into board coordinates&lt;/li>
&lt;li>Convert a board coordinate into projector coordinates&lt;/li>
&lt;/ul>
&lt;h3 id="installation">Installation&lt;/h3>
&lt;p>Make sure Python and &lt;code>pip&lt;/code> are installed.&lt;/p>
&lt;blockquote>
&lt;p>The tutorial has been tested with Python 3.12 and 3.13. Other versions may work, but adjustments might be necessary.&lt;/p>
&lt;/blockquote>
&lt;p>Install required dependencies:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">pip install &lt;span class="nv">numpy&lt;/span>&lt;span class="o">==&lt;/span>1.26.4
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">pip install opencv-python&lt;span class="o">==&lt;/span>4.10.0.84
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">pip install opencv-contrib-python&lt;span class="o">==&lt;/span>4.6.0.66
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>&lt;strong>OpenCV&lt;/strong>: Computer vision library&lt;/li>
&lt;li>&lt;strong>Aruco&lt;/strong>: Marker generation and detection module (included in opencv-contrib)&lt;/li>
&lt;/ul>
&lt;p>Documentation: &lt;a href="https://docs.opencv.org/4.x/index.html" target="_blank" rel="noopener">https://docs.opencv.org/4.x/index.html&lt;/a>&lt;/p>
&lt;h3 id="marker-generation">Marker Generation&lt;/h3>
&lt;p>Run:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">python generateMarkers.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If correctly installed, four markers defining the playing area will be generated.&lt;/p>
&lt;p>Print and place them on the board.&lt;/p>
&lt;h3 id="coordinate-conventions">Coordinate Conventions&lt;/h3>
&lt;h4 id="matrix-representation-images">Matrix Representation (Images)&lt;/h4>
&lt;p>Images are NumPy matrices in &lt;strong>row-major order&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>First index → row (vertical, downward)&lt;/li>
&lt;li>Second index → column (horizontal, rightward)&lt;/li>
&lt;li>(0,0) is top-left&lt;/li>
&lt;/ul>
&lt;h4 id="point-representation">Point Representation&lt;/h4>
&lt;p>Points follow image convention:&lt;/p>
&lt;ul>
&lt;li>Origin: top-left&lt;/li>
&lt;li>X → right&lt;/li>
&lt;li>Y → down&lt;/li>
&lt;/ul>
&lt;p>Coordinate system:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">(0,0) - X →
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Y
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Be extremely careful when switching between matrix indexing and geometric coordinates.&lt;/p>
&lt;h2 id="code-structure">Code Structure&lt;/h2>
&lt;p>Four main components:&lt;/p>
&lt;ul>
&lt;li>&lt;code>Camera&lt;/code>&lt;/li>
&lt;li>&lt;code>Projector&lt;/code>&lt;/li>
&lt;li>&lt;code>CoreAR&lt;/code>&lt;/li>
&lt;li>&lt;code>TicTacToe&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>All missing parts are marked with:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">### TODO&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="1-initialization">1️⃣ Initialization&lt;/h2>
&lt;h3 id="camera">Camera&lt;/h3>
&lt;ul>
&lt;li>Automatically searches for available camera&lt;/li>
&lt;li>Exposure configurable&lt;/li>
&lt;li>Must release using:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">camera&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">release&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Complete all &lt;code>TODO&lt;/code> sections.&lt;/p>
&lt;h3 id="projector">Projector&lt;/h3>
&lt;p>Constructor: no modification required.&lt;/p>
&lt;p>Implement:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">drawBlack&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Understand how drawing works in projector space.&lt;/p>
&lt;h3 id="corear">CoreAR&lt;/h3>
&lt;p>Constructor only stores references.&lt;/p>
&lt;p>No modification required.&lt;/p>
&lt;h2 id="2-calibration">2️⃣ Calibration&lt;/h2>
&lt;h3 id="camera-calibration">Camera Calibration&lt;/h3>
&lt;p>Goal:&lt;/p>
&lt;ul>
&lt;li>Detect the four ArUco markers&lt;/li>
&lt;li>Match detected corners with board coordinates&lt;/li>
&lt;li>Compute homography between board and camera&lt;/li>
&lt;/ul>
&lt;p>Complete all &lt;code>TODO&lt;/code> sections in:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">calibrateCamera&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="projector-calibration">Projector Calibration&lt;/h3>
&lt;p>Principle:&lt;/p>
&lt;ol>
&lt;li>Project markers at known projector positions&lt;/li>
&lt;li>Detect them with camera&lt;/li>
&lt;li>Convert camera detections to board coordinates&lt;/li>
&lt;li>Compute projector → board homography&lt;/li>
&lt;/ol>
&lt;p>Complete:&lt;/p>
&lt;ul>
&lt;li>&lt;code>drawMarkers()&lt;/code> in projector&lt;/li>
&lt;li>&lt;code>calibrateProjector()&lt;/code> in CoreAR&lt;/li>
&lt;/ul>
&lt;h2 id="3-drawing-in-projector-space">3️⃣ Drawing in Projector Space&lt;/h2>
&lt;p>Implement:&lt;/p>
&lt;ul>
&lt;li>&lt;code>draw()&lt;/code>&lt;/li>
&lt;li>&lt;code>checkCalibration()&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>This allows:&lt;/p>
&lt;ul>
&lt;li>Displaying the game board&lt;/li>
&lt;li>Validating calibration visually&lt;/li>
&lt;/ul>
&lt;p>Test full calibration pipeline.&lt;/p>
&lt;h2 id="4-game-logic">4️⃣ Game Logic&lt;/h2>
&lt;p>The &lt;code>ticTacToe&lt;/code> class is already implemented.&lt;/p>
&lt;p>You now focus on detecting moves.&lt;/p>
&lt;h2 id="5-move-detection">5️⃣ Move Detection&lt;/h2>
&lt;p>Strategy:&lt;/p>
&lt;ol>
&lt;li>Capture reference frame&lt;/li>
&lt;li>Compare current frame with reference&lt;/li>
&lt;li>Compute difference image&lt;/li>
&lt;li>Apply threshold&lt;/li>
&lt;li>Apply morphological opening&lt;/li>
&lt;li>Extract blob position&lt;/li>
&lt;li>Validate stability over time&lt;/li>
&lt;li>Update reference frame&lt;/li>
&lt;/ol>
&lt;p>Complete all &lt;code>TODO&lt;/code> sections in:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">findMove&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Intermediate &lt;code>imshow()&lt;/code> lines can be uncommented to debug.&lt;/p>
&lt;h2 id="image-processing-pipeline">Image Processing Pipeline&lt;/h2>
&lt;ul>
&lt;li>Frame subtraction&lt;/li>
&lt;li>Thresholding&lt;/li>
&lt;li>Morphological opening&lt;/li>
&lt;li>Contour extraction&lt;/li>
&lt;/ul>
&lt;p>This isolates new moves placed on the board.&lt;/p>
&lt;h2 id="improvements--tuning">Improvements &amp;amp; Tuning&lt;/h2>
&lt;p>You may adjust:&lt;/p>
&lt;ul>
&lt;li>Camera exposure&lt;/li>
&lt;li>Projector brightness&lt;/li>
&lt;li>Threshold value&lt;/li>
&lt;/ul>
&lt;p>Fine-tuning greatly impacts detection robustness.&lt;/p>
&lt;h2 id="what-you-have-built">What You Have Built&lt;/h2>
&lt;p>At the end of this tutorial, you have implemented:&lt;/p>
&lt;ul>
&lt;li>Camera-projector calibration&lt;/li>
&lt;li>Multi-space homography estimation&lt;/li>
&lt;li>Real-time surface augmentation&lt;/li>
&lt;li>Basic event detection&lt;/li>
&lt;/ul>
&lt;p>This architecture can be reused for:&lt;/p>
&lt;ul>
&lt;li>Augmented board games&lt;/li>
&lt;li>Interactive surfaces&lt;/li>
&lt;li>Experimental setups&lt;/li>
&lt;li>Scientific visualization&lt;/li>
&lt;/ul>
&lt;h2 id="deliverables">Deliverables&lt;/h2>
&lt;ul>
&lt;li>Completed code (all TODOs filled)&lt;/li>
&lt;li>Functional calibration&lt;/li>
&lt;li>Fully working augmented tic-tac-toe&lt;/li>
&lt;/ul>
&lt;p>Optional:&lt;/p>
&lt;ul>
&lt;li>Detection improvements&lt;/li>
&lt;li>Graphical enhancements&lt;/li>
&lt;li>Additional gameplay features&lt;/li>
&lt;/ul>
&lt;h2 id="clarifications-based-on-student-questions">Clarifications (Based on Student Questions)&lt;/h2>
&lt;h3 id="opencv-installation-with-conda">OpenCV Installation with Conda&lt;/h3>
&lt;p>If &lt;code>pip&lt;/code> is not available, use:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">conda install -c conda-forge opencv
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>In most cases, &lt;strong>Aruco&lt;/strong> is installed automatically with this command.&lt;/p>
&lt;p>If not, try:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">conda install -c conda-forge aruco
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If ArUco is still missing, you may need to install &lt;code>pip&lt;/code> and use the &lt;code>opencv-contrib-python&lt;/code> package.&lt;/p>
&lt;h3 id="camera--projector-projection-matrix-r2p">Camera → Projector Projection Matrix (R2P)&lt;/h3>
&lt;p>The projection matrix from the real board to the projector space (&lt;strong>R2P&lt;/strong>) is:&lt;/p>
&lt;ul>
&lt;li>Computed inside &lt;code>CoreAR&lt;/code>&lt;/li>
&lt;li>Assigned in &lt;code>main.py&lt;/code> via:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">proj&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">R2P&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">core&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">R2P&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>There is no encapsulation mechanism here. The attribute is dynamically added to the &lt;code>Projector&lt;/code> instance.&lt;/p>
&lt;p>Inside the &lt;code>Projector&lt;/code> class, you simply use:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">R2P&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This works because &lt;code>draw()&lt;/code> is only called &lt;em>after&lt;/em> the attribute has been defined.&lt;/p>
&lt;h3 id="calibration-functions-and-transition-matrices">Calibration Functions and Transition Matrices&lt;/h3>
&lt;h4 id="calibratecamera">&lt;code>calibrateCamera()&lt;/code>&lt;/h4>
&lt;ul>
&lt;li>Detects &lt;strong>physical ArUco markers&lt;/strong> placed on the board&lt;/li>
&lt;li>⚠ Do &lt;strong>not&lt;/strong> place markers on a black background&lt;/li>
&lt;li>Computes the transformation matrix:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">R2C (Real → Camera)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="calibrateprojector">&lt;code>calibrateProjector()&lt;/code>&lt;/h4>
&lt;ol>
&lt;li>
&lt;p>The projector displays virtual markers&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The camera detects those projected markers&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Matching is performed between:&lt;/p>
&lt;ul>
&lt;li>Known projected marker positions&lt;/li>
&lt;li>Detected marker positions in camera space&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>A Camera → Projector transformation is computed&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>From this, we deduce:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">R2P (Real → Projector)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>So the full transformation chain is:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Real → Camera → Projector
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>And finally:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">R2P = (C2P) ∘ (R2C)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>End of tutorial.&lt;/strong>&lt;/p></description></item></channel></rss>