<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Edward Obar Cabigting on Medium]]></title>
        <description><![CDATA[Stories by Edward Obar Cabigting on Medium]]></description>
        <link>https://medium.com/@eocabigting?source=rss-6633df3a7ff7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Edward Obar Cabigting on Medium</title>
            <link>https://medium.com/@eocabigting?source=rss-6633df3a7ff7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:36:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eocabigting/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a License Plate Recognition Engine in C++ — Part 2: Grayscale Image Preprocessing and…]]></title>
            <link>https://medium.com/@eocabigting/building-a-license-plate-recognition-engine-in-c-part-2-grayscale-image-preprocessing-and-fa88ecfb9113?source=rss-6633df3a7ff7------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa88ecfb9113</guid>
            <category><![CDATA[ocr]]></category>
            <category><![CDATA[cplusplus]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[lpr]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Edward Obar Cabigting]]></dc:creator>
            <pubDate>Sat, 16 May 2026 17:16:43 GMT</pubDate>
            <atom:updated>2026-05-16T17:16:43.445Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a License Plate Recognition Engine in C++ — Part 2: Grayscale Image Preprocessing and Local Contrast Edge Detection</h3><p>In the previous article, we loaded an image, converted it into grayscale, and introduced the core data structures used by the recognition engine.</p><p>In this part, we begin building the preprocessing stage of the LPR pipeline.</p><p>The goal of preprocessing is to enhance image regions that are likely to contain license plate characters.</p><p>We will implement:</p><p>- Integral image generation<br>- Local contrast analysis<br>- Edge map extraction<br>- Ternary edge image conversion</p><p>These operations are designed for high-speed processing and are suitable for real-time systems.</p><p>**Why preprocessing matters in LPR**</p><p>License plates typically contain:</p><p>- High-contrast characters<br>- Dense vertical and horizontal transitions<br>- Repetitive edge structures</p><p>Instead of applying expensive operations across the entire image, preprocessing helps emphasize candidate regions before plate detection begins.</p><p>The pipeline implemented in this article focuses on local intensity differences.</p><p>**Integral Image**</p><p>The first optimization step is building an integral image.</p><p>An integral image allows us to compute the sum of any rectangular region in constant time.</p><p>Without an integral image:</p><p>```plaintext<br>Region Sum = O(width × height)<br>```</p><p>With an integral image:</p><p>```plaintext<br>Region Sum = O(1)<br>```</p><p>This becomes extremely important when processing every pixel in large images.</p><p>Computing the integral image</p><p>```cpp<br>void CImageProc::ComputeIntegralImage(<br> unsigned char* pbGray,<br> int nWidth,<br> int nHeight,<br> int* pnSum)<br>{<br> int nW = nWidth + 1;<br> int nH = nHeight + 1;</p><p>int partialsum;</p><p>memset(pnSum, 0, nH * nW * sizeof(int));</p><p>for (int y = 1; y &lt; nH; y++)<br> {<br> pnSum[y * nW] = 0;<br> partialsum = 0;</p><p>for (int x = 1; x &lt; nW; x++)<br> {<br> partialsum +=<br> (int)pbGray[<br> (y — 1) * nWidth + (x — 1)];</p><p>pnSum[y * nW + x] =<br> pnSum[(y — 1) * nW + x]<br> + partialsum;<br> }<br> }<br>}<br>```<br>**Fast local contrast edge map**</p><p>```cpp<br>void CImageProc::ComputeLocalContrastEdgeMap(<br> unsigned char* pbGray, <br> int* pnSum, <br> int* pnEdge, <br> int nWidth, <br> int nHeight)<br>{<br> if (!pbGray || !pnSum || !pnEdge || nWidth &lt;= 0 || nHeight &lt;= 0)<br> return;</p><p>const int rw = 3;<br> const int rh = 3;<br> const int nW = nWidth + 1;</p><p>const int centerCount = 5;<br> const int windowCount = (rw * 2 + 1) * (rh * 2 + 1);<br> const int surroundCount = windowCount — centerCount;</p><p>if (nWidth &lt;= rw * 2 || nHeight &lt;= rh * 2)<br> return;</p><p>for (int y = rh; y &lt; nHeight — rh; y++)<br> {<br> const int row = y * nWidth;<br> const int prevRow = (y — 1) * nWidth;<br> const int nextRow = (y + 1) * nWidth;</p><p>const int top = y — rh;<br> const int bottom = y + rh + 1;<br> for (int x = (rw + 1); x &lt; nWidth — rw; x++)<br> {<br> const int left = x — rw;<br> const int right = x + rw + 1;</p><p>int centerSum =<br> pbGray[prevRow + x] +<br> pbGray[row + x — 1] +<br> pbGray[row + x] +<br> pbGray[row + x + 1] +<br> pbGray[nextRow + x];</p><p>int windowSum =<br> pnSum[bottom * nW + right]<br> — pnSum[top * nW + right]<br> — pnSum[bottom * nW + left]<br> + pnSum[top * nW + left];</p><p>int surroundSum = windowSum — centerSum;</p><p>double centerAvg = (double)centerSum / centerCount;<br> double surroundAvg = (double)surroundSum / surroundCount;</p><p>pnEdge[row + x] = (int)(surroundAvg — centerAvg);<br> }<br> }<br> ComputeBorderLocalContrast(pbGray, pnSum, pnEdge, nWidth, nHeight, 0, nWidth — 1, 0, rh — 1, rw, rh);<br> ComputeBorderLocalContrast(pbGray, pnSum, pnEdge, nWidth, nHeight, 0, nWidth — 1, nHeight — rh, nHeight — 1, rw, rh);<br> ComputeBorderLocalContrast(pbGray, pnSum, pnEdge, nWidth, nHeight, 0, rw, rh, nHeight — rh, rw, rh);<br> ComputeBorderLocalContrast(pbGray, pnSum, pnEdge, nWidth, nHeight, nWidth — rw, nWidth — 1, rh, nHeight — rh, rw, rh);<br>}</p><p>void CImageProc::ComputeBorderLocalContrast(<br> unsigned char* pbGray, <br> int* pnSum, <br> int* lpOut, <br> int nWidth, <br> int nHeight, <br> int x0, <br> int x1, <br> int y0, <br> int y1, <br> int rw, <br> int rh)<br>{<br> if (!pbGray || !pnSum || !lpOut || nWidth &lt;= 0 || nHeight &lt;= 0)<br> return;</p><p>int nW = nWidth + 1;</p><p>if (x0 &lt; 0) x0 = 0;<br> if (y0 &lt; 0) y0 = 0;<br> if (x1 &gt;= nWidth) x1 = nWidth — 1;<br> if (y1 &gt;= nHeight) y1 = nHeight — 1;</p><p>for (int y = y0; y &lt;= y1; y++)<br> {<br> int row = y * nWidth;</p><p>for (int x = x0; x &lt;= x1; x++)<br> {<br> int left = x — rw;<br> int right = x + rw;<br> int top = y — rh;<br> int bottom = y + rh;</p><p>if (left &lt; 0) left = 0;<br> if (top &lt; 0) top = 0;<br> if (right &gt;= nWidth) right = nWidth — 1;<br> if (bottom &gt;= nHeight) bottom = nHeight — 1;</p><p>int surroundCount = (right — left + 1) * (bottom — top + 1);<br> int surroundSum = <br> pnSum[(bottom + 1) * nW + (right + 1)] <br> — pnSum[top * nW + (right + 1)] <br> — pnSum[(bottom + 1) * nW + left] <br> + pnSum[top * nW + left];</p><p>int centerSum = 0;<br> int centerCount = 0;<br> <br> // Center pixel<br> centerSum += pbGray[row + x];<br> surroundSum -= pbGray[row + x];<br> centerCount++;<br> surroundCount — ;</p><p>// Left<br> if (x — 1 &gt;= 0)<br> {<br> centerSum += pbGray[row + (x — 1)];<br> surroundSum -= pbGray[row + (x — 1)];<br> centerCount++;<br> surroundCount — ;<br> }</p><p>// Right<br> if (x + 1 &lt; nWidth)<br> {<br> centerSum += pbGray[row + (x + 1)];<br> surroundSum -= pbGray[row + (x + 1)];<br> centerCount++;<br> surroundCount — ;<br> }</p><p>// Top<br> if (y — 1 &gt;= 0)<br> {<br> centerSum += pbGray[(y — 1) * nWidth + x];<br> surroundSum -= pbGray[(y — 1) * nWidth + x];<br> centerCount++;<br> surroundCount — ;<br> }</p><p>// Bottom<br> if (y + 1 &lt; nHeight)<br> {<br> centerSum += pbGray[(y + 1) * nWidth + x];<br> surroundSum -= pbGray[(y + 1) * nWidth + x];<br> centerCount++;<br> surroundCount — ;<br> }</p><p>if (centerCount == 0 || surroundCount &lt;= 0)<br> {<br> lpOut[row + x] = 0;<br> continue;<br> }</p><p>double centerAvg = (double)centerSum / centerCount;<br> double surroundAvg = (double)surroundSum / surroundCount;<br> lpOut[row + x] = (int)(surroundAvg — centerAvg);<br> }<br> }<br>}<br>```</p><p>The algorithm performs:</p><p>1. Local neighborhood extraction<br>2. Center intensity averaging<br>3. Surrounding intensity averaging<br>4. Difference calculation</p><p>Result:</p><p>```plaintext<br>Strong intensity transitions<br> ↓<br>High edge responses<br>```<br>This is particularly effective for license plate characters because they contain strong contrast boundaries.</p><p>**Current preprocessing pipeline**<br>Our LPR engine now performs:</p><p>```plaintext<br>Input Image<br> ↓<br>Grayscale Conversion<br> ↓<br>Integral Image<br> ↓<br>Local Contrast Analysis<br> ↓<br>Edge Map Generation<br> ↓<br>Ternary Edge Image<br>```</p><p>At this point, the engine can already highlight regions containing dense character-like structures.</p><p>In the next article, we will begin locating candidate license plate regions using the generated edge information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa88ecfb9113" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a License Plate Recognition Engine in C++ — Part 1: Image Loading and Core LPR Data…]]></title>
            <link>https://medium.com/@eocabigting/building-a-license-plate-recognition-engine-in-c-part-1-image-loading-and-core-lpr-data-9969297a5cc3?source=rss-6633df3a7ff7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9969297a5cc3</guid>
            <category><![CDATA[license-plates]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cplusplus]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Edward Obar Cabigting]]></dc:creator>
            <pubDate>Thu, 14 May 2026 11:39:21 GMT</pubDate>
            <atom:updated>2026-05-14T11:39:21.729Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a License Plate Recognition Engine in C++ — Part 1: Image Loading and Core LPR Data Structures</h3><p>In this series, I’ll build a License Plate Recognition (LPR) engine step by step in C++. The goal is not only to recognize license plates but also to understand the internal mechanics behind image processing and recognition systems.</p><p>In this first part we will:</p><p>- Load an image using OpenCV<br>- Convert the image into grayscale<br>- Introduce the core data structures used by the recognition engine</p><p>Future parts will cover:</p><p>- Image preprocessing<br>- Noise reduction<br>- Edge detection<br>- Plate localization<br>- Character segmentation<br>- Character recognition<br>- Performance optimization</p><p>**Loading an image**</p><p>The first step of any vision system is acquiring image data.</p><p>We read the image path from command-line arguments:</p><p>```cpp<br>#include &lt;iostream&gt;<br>#include “opencv2/opencv.hpp”<br>#include “RecogEngine.h”</p><p>int main(int argc, char* argv[])<br>{<br> if (argc &lt; 2)<br> {<br> std::cout &lt;&lt; “Usage: app.exe &lt;image_path&gt;\n”;<br> return -1;<br> }</p><p>const char* imagePath = argv[1];</p><p>cv::Mat image = cv::imread(imagePath);</p><p>if (image.empty())<br> {<br> std::cout &lt;&lt; “Failed to load image: “ &lt;&lt; imagePath &lt;&lt; “\n”;<br> return -1;<br> }</p><p>cv::Mat gray;<br> cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);</p><p>LPRResult carData;</p><p>CRecogEngine recogEngine;</p><p>int nPlate = recogEngine.Recognition(<br> gray.data,<br> gray.cols,<br> gray.rows,<br> &amp;carData);</p><p>std::cout &lt;&lt; “Recognition completed.\n”;</p><p>return 0;<br>}<br>```</p><p>Why convert to grayscale?</p><p>Most early image-processing stages do not require color information.</p><p>Using grayscale provides several advantages:</p><p>- Reduces memory usage<br>- Simplifies calculations<br>- Improves processing speed<br>- Keeps intensity information needed for edge and pattern analysis</p><p>Instead of processing three channels (BGR), we process a single intensity channel.</p><p>**Designing core LPR data structures**</p><p>Recognition systems need a structured way to store results.</p><p>The following structures define the fundamental objects used by our engine:</p><p>```cpp<br>#pragma once</p><p>#define MULTIRESULT 10</p><p>typedef struct LPRRect<br>{<br> long left;<br> long top;<br> long right;<br> long bottom;<br>} Rect;</p><p>typedef struct LPRPoint<br>{<br> int x;<br> int y;<br>} Point;</p><p>typedef struct LPRSize<br>{<br> int width;<br> int height;<br>} Size;</p><p>typedef struct PlateCandidate<br>{<br> int characterCount;<br> char licenseText[20];<br> float confidenceDistance;<br> int confidenceScore;<br> Rect plateRegion; <br> Rect characterRegions[20];<br>} LICENSE, * LPLICENSE;</p><p>struct LPRResult<br>{<br> int nPlate;<br> LICENSE pPlate[MULTIRESULT];<br> int nProcTime;<br>};<br>```</p><p>These structures serve different purposes:</p><p>LPRRect</p><p>- Stores coordinate information</p><p>PlateCandidate</p><p>- Stores recognized text<br>- Stores confidence values<br>- Stores plate position<br>- Stores character locations</p><p>LPRResult</p><p>- Stores all recognition outputs<br>- Supports multiple detected plates</p><p>**Data flow of our engine**</p><p>The recognition pipeline currently looks like this:</p><p>```plaintext<br>Input Image<br> ↓<br>Image Loading<br> ↓<br>Grayscale Conversion<br> ↓<br>Recognition Engine<br> ↓<br>LPRResult<br>```</p><p>At this point, the system can load an image and pass grayscale pixel data into the recognition engine.</p><p>In the next article, we’ll begin preprocessing the image to prepare it for plate detection.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9969297a5cc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>