<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Feature Detection | Étienne Peillard</title><link>https://www.etiennepeillard.com/tag/feature-detection/</link><atom:link href="https://www.etiennepeillard.com/tag/feature-detection/index.xml" rel="self" type="application/rss+xml"/><description>Feature Detection</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Thu, 12 Feb 2026 00:00:00 +0000</lastBuildDate><image><url>https://www.etiennepeillard.com/media/sharing.png</url><title>Feature Detection</title><link>https://www.etiennepeillard.com/tag/feature-detection/</link></image><item><title>Lab — Marker tracking with OpenCV</title><link>https://www.etiennepeillard.com/teaching/lab/tp-tracking/</link><pubDate>Thu, 12 Feb 2026 00:00:00 +0000</pubDate><guid>https://www.etiennepeillard.com/teaching/lab/tp-tracking/</guid><description>&lt;h1 id="marker-tracking">Marker Tracking&lt;/h1>
&lt;p>&lt;strong>▶ &lt;a href="base-code.zip">Base Code&lt;/a>&lt;/strong>&lt;/p>
&lt;p>&lt;strong>Requirements&lt;/strong>:&lt;/p>
&lt;p>&lt;code>pip install opencv-python&lt;/code>&lt;/p>
&lt;p>&lt;code>pip install numpy&lt;/code>&lt;/p>
&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>The goal of this lab session is to introduce you to several fundamental concepts in computer vision through a concrete application: detecting and localizing a planar marker in a video stream.&lt;/p>
&lt;p>You will work on:&lt;/p>
&lt;ul>
&lt;li>detecting feature points (interest points),&lt;/li>
&lt;li>describing these points (local descriptors),&lt;/li>
&lt;li>matching points detected in two images,&lt;/li>
&lt;li>computing a homography (projective transformation),&lt;/li>
&lt;li>augmenting a video stream based on marker localization.&lt;/li>
&lt;/ul>
&lt;p>By the end of the lab, you will have a program that, given:&lt;/p>
&lt;ul>
&lt;li>a reference image (the marker),&lt;/li>
&lt;li>a video stream (webcam or video file),&lt;/li>
&lt;/ul>
&lt;p>automatically detects the presence of the marker in the scene and masks the marker area by replacing it with a white polygon (to visually validate detection).&lt;/p>
&lt;hr>
&lt;h2 id="application-principle">Application Principle&lt;/h2>
&lt;p>The overall idea of the system is the following:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Load the marker image (reference image).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Open a video stream (webcam or video file).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Detect a set of feature points in the marker image (FP_M).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Compute descriptors for these points (FD_M).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>For each frame I_t of the video stream:&lt;/p>
&lt;ul>
&lt;li>detect a set of feature points (FP_t),&lt;/li>
&lt;li>compute descriptors (FD_t),&lt;/li>
&lt;li>match FD_M and FD_t to obtain correspondences,&lt;/li>
&lt;li>filter these correspondences to retain only “good matches”.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Estimate the geometric transformation relating the marker plane to the frame: a homography H_{M-&amp;gt;t} robustly computed using RANSAC.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Use H_{M-&amp;gt;t} to:&lt;/p>
&lt;ul>
&lt;li>project the 4 corners of the marker into image I_t,&lt;/li>
&lt;li>mask the detected region by filling it in white.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;p>Important note: this lab performs localization via &amp;ldquo;re-detection + matching&amp;rdquo; at each frame. It is not a temporal tracking approach (e.g., KLT/optical flow), but rather a robust and simple method to implement.&lt;/p>
&lt;hr>
&lt;h2 id="feature-detection">Feature Detection&lt;/h2>
&lt;p>The objective of feature detection (or more generally &amp;ldquo;interest regions&amp;rdquo;) is to automatically select image elements that exhibit distinctive properties: corners, textured regions, high-contrast areas, etc.&lt;/p>
&lt;p>A feature detector takes an image as input and outputs a set of pixel coordinates corresponding to points considered &amp;ldquo;interesting&amp;rdquo; by the algorithm.&lt;/p>
&lt;p>Important: a detector provides positions (and sometimes scale/orientation) but not a descriptive signature.&lt;/p>
&lt;p>Examples of detectors: Harris, FAST, Shi-Tomasi, ORB, AKAZE, SIFT, etc.&lt;/p>
&lt;p>Resources (to read after the lab):&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://fr.wikipedia.org/wiki/D%C3%A9tection_de_zones_d%27int%C3%A9r%C3%AAt" target="_blank" rel="noopener">https://fr.wikipedia.org/wiki/D%C3%A9tection_de_zones_d%27int%C3%A9r%C3%AAt&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Feature_detection_%28computer_vision%29" target="_blank" rel="noopener">https://en.wikipedia.org/wiki/Feature_detection_(computer_vision)&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="feature-description">Feature Description&lt;/h2>
&lt;p>A feature descriptor aims to numerically characterize the local appearance around an interest point.&lt;/p>
&lt;p>It takes as input:&lt;/p>
&lt;ul>
&lt;li>an image,&lt;/li>
&lt;li>a list of feature points,&lt;/li>
&lt;/ul>
&lt;p>and outputs a vector (or matrix) of descriptors, one per point.&lt;/p>
&lt;p>These descriptors represent a local “fingerprint” that enables comparison of points detected in different images.&lt;/p>
&lt;p>Desirable properties of a descriptor:&lt;/p>
&lt;ul>
&lt;li>invariance (or robustness) to rotation,&lt;/li>
&lt;li>invariance (or robustness) to scale changes,&lt;/li>
&lt;li>robustness to photometric variations (lighting),&lt;/li>
&lt;li>robustness to moderate geometric transformations.&lt;/li>
&lt;/ul>
&lt;p>Examples: ORB, AKAZE, BRISK, SIFT (detector + descriptor), etc.&lt;/p>
&lt;p>Resources (to read after the lab):&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://fr.wikipedia.org/wiki/Extraction_de_caract%C3%A9ristique_en_vision_par_ordinateur" target="_blank" rel="noopener">https://fr.wikipedia.org/wiki/Extraction_de_caract%C3%A9ristique_en_vision_par_ordinateur&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Visual_descriptor" target="_blank" rel="noopener">https://en.wikipedia.org/wiki/Visual_descriptor&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Scale-invariant_feature_transform" target="_blank" rel="noopener">https://en.wikipedia.org/wiki/Scale-invariant_feature_transform&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="matching">Matching&lt;/h2>
&lt;p>Matching addresses the following question:&lt;/p>
&lt;blockquote>
&lt;p>Given a feature in the marker image, how can we find the most similar feature in the current video frame?&lt;/p>
&lt;/blockquote>
&lt;p>The general idea is:&lt;/p>
&lt;ol>
&lt;li>Define a distance or similarity measure between descriptors.&lt;/li>
&lt;li>For each descriptor of the marker, find the closest descriptor in the frame.&lt;/li>
&lt;/ol>
&lt;p>Possible measures: L1, L2, Hamming (for binary descriptors), ratio test, etc.&lt;/p>
&lt;p>Matching methods:&lt;/p>
&lt;ul>
&lt;li>Brute force: compares all descriptors pairwise (simple, potentially costly).&lt;/li>
&lt;li>FLANN: approximate nearest neighbors (faster for large datasets).&lt;/li>
&lt;/ul>
&lt;p>After matching, a filtering rule must be defined to retain only relevant correspondences. A classical approach (used in the provided base code) consists of using a threshold based on the minimum observed distance:&lt;/p>
&lt;p>threshold = alpha * minDist&lt;/p>
&lt;p>where alpha is a coefficient (typically between 3 and 20 depending on the method and expected quality).&lt;/p>
&lt;p>Resources (to read after the lab):&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://docs.google.com/presentation/d/1_HFh3SdmdyZ_j-sFS4Tw17DmhKfjmYZqvSp7TmfdD_M/edit?slide=id.p#slide=id.p" target="_blank" rel="noopener">https://docs.google.com/presentation/d/1_HFh3SdmdyZ_j-sFS4Tw17DmhKfjmYZqvSp7TmfdD_M/edit?slide=id.p#slide=id.p&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.cs.toronto.edu/~urtasun/courses/CV/lecture04.pdf" target="_blank" rel="noopener">https://www.cs.toronto.edu/~urtasun/courses/CV/lecture04.pdf&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="homography-and-projection">Homography and Projection&lt;/h2>
&lt;p>Once correspondences between the marker (planar object) and the frame (image) have been established, we estimate the geometric transformation relating these two sets of points.&lt;/p>
&lt;p>For a planar object, this transformation is a homography (3x3 matrix). It models perspective effects and relates two views of the same plane.&lt;/p>
&lt;p>We estimate a matrix H from the good matches (after filtering). The estimation must be robust to outliers: we use RANSAC.&lt;/p>
&lt;p>Resources (to read after the lab):&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Homography_%28computer_vision%29" target="_blank" rel="noopener">https://en.wikipedia.org/wiki/Homography_(computer_vision)&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://fr.wikipedia.org/wiki/Application_projective" target="_blank" rel="noopener">https://fr.wikipedia.org/wiki/Application_projective&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h1 id="implementation-in-opencv">Implementation in OpenCV&lt;/h1>
&lt;p>The objective of the lab is to implement the previous steps in OpenCV starting from a provided code skeleton.&lt;/p>
&lt;h2 id="provided-base-code">Provided Base Code&lt;/h2>
&lt;p>You are given the following files:&lt;/p>
&lt;ul>
&lt;li>&lt;code>main.py&lt;/code>&lt;/li>
&lt;li>&lt;code>MyFeatureDetector.py&lt;/code>&lt;/li>
&lt;li>&lt;code>MyDescriptorExtractor.py&lt;/code>&lt;/li>
&lt;li>&lt;code>MyDescriptorMatcher.py&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>These files contain TODO sections guiding your implementation.&lt;/p>
&lt;p>Important: the current base code loads two static images. You must adapt it to handle:&lt;/p>
&lt;ul>
&lt;li>a reference image &lt;code>marker.jpg&lt;/code>,&lt;/li>
&lt;li>a video stream (webcam or file).&lt;/li>
&lt;/ul>
&lt;p>You will remove the final warped image generation part and replace it with an augmentation step (masking the marker) based on projected corners.&lt;/p>
&lt;hr>
&lt;h2 id="questions">Questions&lt;/h2>
&lt;h3 id="question-1-reading-and-understanding-the-provided-code">Question 1: Reading and Understanding the Provided Code&lt;/h3>
&lt;p>Read the provided code and identify:&lt;/p>
&lt;ul>
&lt;li>where images are loaded,&lt;/li>
&lt;li>where the detector, extractor, and matcher are instantiated,&lt;/li>
&lt;li>where detected points and descriptors are stored,&lt;/li>
&lt;li>how the list of best matches is built,&lt;/li>
&lt;li>how the homography is computed.&lt;/li>
&lt;/ul>
&lt;p>Explain in a few lines the role of each file.&lt;/p>
&lt;hr>
&lt;h3 id="question-2-create-a-feature-detector-orb">Question 2: Create a Feature Detector (ORB)&lt;/h3>
&lt;p>In &lt;code>MyFeatureDetector.py&lt;/code>, complete the &lt;code>changeFeatureDetector&lt;/code> function to create an ORB detector.&lt;/p>
&lt;p>Objective: fill the &lt;code>myFeatureDetector&lt;/code> attribute by calling the appropriate OpenCV constructor (e.g., &lt;code>cv.ORB_create(...)&lt;/code>).&lt;/p>
&lt;hr>
&lt;h3 id="question-3-display-detected-points">Question 3: Display Detected Points&lt;/h3>
&lt;p>In &lt;code>main.py&lt;/code>, display detected feature points:&lt;/p>
&lt;ul>
&lt;li>on the image &lt;code>marker.jpg&lt;/code>,&lt;/li>
&lt;li>on a video frame.&lt;/li>
&lt;/ul>
&lt;p>Hint: use the &lt;code>displayFeatures&lt;/code> method and the existing TODO sections in the skeleton.&lt;/p>
&lt;p>To do: add a screenshot showing results on the marker and on a frame.&lt;/p>
&lt;p>Optional: add parameters to &lt;code>cv.ORB_create(...)&lt;/code> (number of points, threshold, etc.) and comment on their impact.&lt;/p>
&lt;hr>
&lt;h3 id="question-4-instantiate-a-descriptor-extractor-orb">Question 4: Instantiate a Descriptor Extractor (ORB)&lt;/h3>
&lt;p>In &lt;code>MyDescriptorExtractor.py&lt;/code>, complete &lt;code>changeDescriptorExtractor&lt;/code> to create an ORB descriptor extractor.&lt;/p>
&lt;hr>
&lt;h3 id="question-5-compute-descriptors">Question 5: Compute Descriptors&lt;/h3>
&lt;p>Complete &lt;code>computeDescriptors()&lt;/code> in &lt;code>MyDescriptorExtractor.py&lt;/code> and complete the corresponding calls in &lt;code>main.py&lt;/code> to:&lt;/p>
&lt;ul>
&lt;li>compute descriptors for the marker,&lt;/li>
&lt;li>compute descriptors for a frame.&lt;/li>
&lt;/ul>
&lt;p>Verify that descriptors are properly computed (consistent dimensions, non-empty).&lt;/p>
&lt;hr>
&lt;h3 id="question-6-perform-matching">Question 6: Perform Matching&lt;/h3>
&lt;p>In &lt;code>MyDescriptorMatcher.py&lt;/code>, complete the &lt;code>match&lt;/code> method to retain only correspondences whose distance is below a threshold:&lt;/p>
&lt;p>threshold = alpha * minDist&lt;/p>
&lt;p>Selected matches must be stored in &lt;code>bestMatches&lt;/code>.&lt;/p>
&lt;hr>
&lt;h3 id="question-7-display-matching-results">Question 7: Display Matching Results&lt;/h3>
&lt;p>In &lt;code>main.py&lt;/code>, call &lt;code>drawMatchingResults()&lt;/code> and display the resulting image.&lt;/p>
&lt;p>To do: illustrate this result with a screenshot in your report.&lt;/p>
&lt;hr>
&lt;h3 id="question-8-understand-and-compute-the-homography">Question 8: Understand and Compute the Homography&lt;/h3>
&lt;p>From the best matches, build two lists of 2D points:&lt;/p>
&lt;ul>
&lt;li>points in the marker image,&lt;/li>
&lt;li>points in the video frame.&lt;/li>
&lt;/ul>
&lt;p>Then compute the homography using &lt;code>cv.findHomography(..., cv.RANSAC, epsilon)&lt;/code>.&lt;/p>
&lt;p>Explain briefly what this computation does and why RANSAC is necessary.&lt;/p>
&lt;hr>
&lt;h3 id="question-9-augmentation--mask-the-marker">Question 9: Augmentation — Mask the Marker&lt;/h3>
&lt;p>Once homography H is estimated, project the 4 marker corners into the frame.&lt;/p>
&lt;p>Expected steps:&lt;/p>
&lt;ol>
&lt;li>Define the 4 marker corners in its image coordinate system.&lt;/li>
&lt;li>Project them using &lt;code>cv.perspectiveTransform&lt;/code>.&lt;/li>
&lt;li>Draw the contour (recommended for debugging).&lt;/li>
&lt;li>Fill the projected polygon in white using &lt;code>cv.fillConvexPoly&lt;/code>.&lt;/li>
&lt;/ol>
&lt;p>Condition: perform augmentation only if H is valid and if the number of inliers is sufficient (threshold to define and justify).&lt;/p>
&lt;p>To do: provide a screenshot where the marker is effectively masked.&lt;/p>
&lt;hr>
&lt;h3 id="question-10-test-on-other-sequences">Question 10: Test on Other Sequences&lt;/h3>
&lt;p>Test your program with:&lt;/p>
&lt;ul>
&lt;li>another video (or another webcam scene),&lt;/li>
&lt;li>another marker (different reference image).&lt;/li>
&lt;/ul>
&lt;p>To do: illustrate at least one additional test and comment on robustness.&lt;/p>
&lt;hr>
&lt;h3 id="question-11-change-detectordescriptor-optional">Question 11: Change Detector/Descriptor (Optional)&lt;/h3>
&lt;p>Try another detector/descriptor combination (e.g., AKAZE) and compare:&lt;/p>
&lt;ul>
&lt;li>number of detected points,&lt;/li>
&lt;li>matching stability,&lt;/li>
&lt;li>number of inliers,&lt;/li>
&lt;li>robustness to scale/lighting variations,&lt;/li>
&lt;li>computational cost.&lt;/li>
&lt;/ul>
&lt;p>To do: illustrate and comment.&lt;/p>
&lt;hr>
&lt;h1 id="deliverables">Deliverables&lt;/h1>
&lt;p>You must submit:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>The completed code.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>A short report (PDF or Markdown) containing:&lt;/p>
&lt;ul>
&lt;li>the requested screenshots,&lt;/li>
&lt;li>your parameter choices (alpha, inlier threshold, etc.),&lt;/li>
&lt;li>a robustness analysis (tests, failure cases).&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol></description></item></channel></rss>