<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zack</title>
    <description>The latest articles on DEV Community by Zack (@zack_building).</description>
    <link>https://dev.to/zack_building</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3821287%2F10fbadd0-07dc-4802-89a8-c393fc8ae902.jpg</url>
      <title>DEV Community: Zack</title>
      <link>https://dev.to/zack_building</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zack_building"/>
    <language>en</language>
    <item>
      <title>Building a Web-based Document Scanner: Tackling Perspective and Shadows with OpenCV</title>
      <dc:creator>Zack</dc:creator>
      <pubDate>Sat, 28 Mar 2026 13:30:59 +0000</pubDate>
      <link>https://dev.to/zack_building/building-a-web-based-document-scanner-tackling-perspective-and-shadows-with-opencv-2677</link>
      <guid>https://dev.to/zack_building/building-a-web-based-document-scanner-tackling-perspective-and-shadows-with-opencv-2677</guid>
      <description>&lt;p&gt;We've all been there: you need to scan a receipt or a signed document, but all you have is your phone. You take a photo, but it's skewed, shadowy, and looks nothing like a real "scan."&lt;/p&gt;

&lt;p&gt;I decided to solve this by building DocuScanPro, a web-based document scanner that focuses on high-fidelity image enhancement directly in the browser.&lt;/p&gt;

&lt;p&gt;The Problem: Perspective and Lighting&lt;br&gt;
Standard mobile photos suffer from two major issues:&lt;/p&gt;

&lt;p&gt;Perspective Distortion: When you don't take the photo perfectly from above.&lt;br&gt;
Uneven Lighting: Shadows from your hand or environmental lighting that make the text hard to read.&lt;br&gt;
The Solution: A Python + OpenCV Pipeline&lt;br&gt;
To tackle this, I built a backend processing engine using FastAPI and OpenCV. Here’s a high-level look at the pipeline:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finding the Document
We use Canny edge detection followed by contour approximation to identify the four corners of the document.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;h1&gt;
  
  
  Simple example of findContours in OpenCV
&lt;/h1&gt;

&lt;p&gt;contours, _ = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)&lt;/p&gt;

&lt;h1&gt;
  
  
  ... find the largest 4-point contour
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Perspective Transform&lt;br&gt;
Once we have the corners, we apply a warp perspective transform to "flatten" the document into a perfect rectangle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shadow Removal &amp;amp; Enhancement&lt;br&gt;
This is where the magic happens. Instead of a simple global threshold, I implemented Adaptive Thresholding. This calculates a threshold for small regions of the image, which helps eliminate shadows while keeping the text sharp and the background a clean, "paper" white.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Results (Before &amp;amp; After)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxwr4n7wm791wsz618kj4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxwr4n7wm791wsz618kj4.jpg" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febuwj2stfv1j0gz2b5eh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febuwj2stfv1j0gz2b5eh.jpg" alt=" " width="800" height="1097"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try it out!&lt;br&gt;
I’ve just launched the initial version and I’m looking for feedback on the algorithm performance—especially for edge cases like white paper on light tables.&lt;/p&gt;

&lt;p&gt;Check out the live tool here: &lt;a href="https://www.docuscan.pro/" rel="noopener noreferrer"&gt;https://www.docuscan.pro/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your thoughts on the image processing logic or any libraries you recommend.&lt;/p&gt;

</description>
      <category>python</category>
      <category>productivity</category>
      <category>react</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
