<?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 Kunal chaugule  on Medium]]></title>
        <description><![CDATA[Stories by Kunal chaugule  on Medium]]></description>
        <link>https://medium.com/@kunalchaugule.2003?source=rss-2ff591cd1bb5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ust_Cmb5kJqGzAeaaQcUYg.jpeg</url>
            <title>Stories by Kunal chaugule  on Medium</title>
            <link>https://medium.com/@kunalchaugule.2003?source=rss-2ff591cd1bb5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:29:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kunalchaugule.2003/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[WHAT IS Intrinsic and Extrinsic Camera Calibration]]></title>
            <link>https://medium.com/@kunalchaugule.2003/what-is-intrinsic-and-extrinsic-camera-calibration-bff27160acf7?source=rss-2ff591cd1bb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bff27160acf7</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[stereo-vision]]></category>
            <category><![CDATA[camera-calibration]]></category>
            <dc:creator><![CDATA[Kunal chaugule ]]></dc:creator>
            <pubDate>Mon, 01 Dec 2025 13:13:35 GMT</pubDate>
            <atom:updated>2025-12-01T13:13:35.783Z</atom:updated>
            <content:encoded><![CDATA[<p>Camera calibration is one of the foundational steps in computer vision. Whether the goal is stereo depth estimation, augmented reality, robotics, or 3D reconstruction, the first question a system must answer is: <strong><em>How does the camera see the world, and where is the camera located in that world?</em></strong><br> This is exactly what intrinsic and extrinsic calibration provide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkarJrPWMXYMOgEjijPVMw.png" /></figure><h3>1. Intrinsic Calibration: The Internal Model of the Camera</h3><p>Intrinsic calibration defines the internal characteristics of the camera properties that describe how 3D points are projected onto the 2D image plane. These parameters are fixed for a given camera unless the lens or resolution changes.</p><h3>1.1 Focal Length (fx, fy)</h3><p>The focal length determines how strongly the lens focuses incoming light. In the image, it controls the degree of zoom: larger values give a zoomed-in view, while smaller values produce a wider field of view. Because pixel dimensions may differ in the horizontal and vertical directions, the focal length is represented separately as fx and fy.</p><h3>1.2 Principal Point (cx, cy)</h3><p>The principal point is the pixel location where the optical axis intersects the image sensor. In theory this is the center of the image, but real cameras exhibit slight deviations due to manufacturing imperfections or lens placement.</p><h3>1.3 Lens Distortion</h3><p>Real lenses distort light, causing straight lines to curve or corners to stretch. Intrinsic calibration estimates distortion coefficients that allow software to correct (undistort) the captured image.</p><p>All intrinsic parameters are organized into the <strong>intrinsic matrix K</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/111/1*rox9KhWp9RX053kr4ph1GQ.png" /></figure><p>This matrix maps 3D camera-coordinate points to pixel coordinates. In short, intrinsic calibration provides a mathematical description of how the camera forms an image.</p><h3>2. Extrinsic Calibration: Position and Orientation of the Camera</h3><p>Extrinsic calibration describes <em>where the camera is</em> and <em>how it is oriented</em> in the world. Unlike intrinsics, these parameters depend entirely on the camera’s placement in the physical environment.</p><h3>2.1 Rotation (R)</h3><p>The rotation matrix describes how the camera is oriented — whether it is looking forward, upward, or sideways. It aligns the world’s coordinate axes with the camera’s axes.</p><h3>2.2 Translation (T)</h3><p>The translation vector specifies the position of the camera in the world. It indicates how far the camera is shifted relative to the world origin or another camera.</p><p>Together, rotation and translation form the <strong>extrinsic matrix [R | T]</strong>, which transforms coordinates from the world coordinate frame to the camera coordinate frame.</p><p>Extrinsic calibration is especially critical in multi-camera setups, such as stereo vision, where the relative positions of the cameras directly influence depth estimation.</p><h3>3. Intrinsics vs. Extrinsics: A Clear Distinction</h3><p>Although both are essential, each describes a different aspect of the imaging process:</p><ul><li><strong>Intrinsic parameters</strong> define how the camera converts light into a digital image.</li><li><strong>Extrinsic parameters</strong> define where the camera is physically located and which direction it is facing.</li></ul><p>Together, they provide the full mathematical model needed to understand how the camera observes the world.</p><h3>4. Why Calibration Matters</h3><p>Accurate calibration enables:</p><ul><li>Depth estimation in stereo vision</li><li>3D reconstruction</li><li>Camera pose estimation</li><li>Augmented reality alignment</li><li>Robotics navigation</li><li>Distortion-free imaging</li><li>Reliable measurement from images</li></ul><p>Errors in intrinsics lead to distorted or inaccurately scaled projections.<br> Errors in extrinsics cause incorrect alignment of 3D points, poor depth maps, or miscalibrated multi-camera systems.</p><h3>5. Practical Example: Stereo Vision Setup</h3><p>In a stereo system with two cameras:</p><ol><li><strong>Intrinsic calibration</strong> is performed separately for each camera to estimate fx, fy, cx, cy, and distortion.</li><li><strong>Extrinsic calibration</strong> determines the rotation and translation between the cameras.</li><li>Once both are known, image rectification aligns epipolar lines.</li><li>Disparity calculation becomes possible.</li><li>Depth is computed using</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/106/1*YH7_OG7sc6caNN8k-NUEjA.png" /></figure><blockquote>where <em>f</em> is the focal length, <em>B</em> is the baseline distance between cameras, and <em>d</em> is the disparity.</blockquote><p>Without accurate intrinsics and extrinsics, the depth map becomes unreliable.</p><blockquote>Intrinsic and extrinsic calibration together form the mathematical backbone of computer vision systems. Intrinsics describe the internal optical behavior of the camera, while extrinsics define its position and orientation in the world. Understanding and accurately estimating these parameters is essential for any application involving 3D geometry, stereo depth, or real-world measurements.</blockquote><blockquote>Camera calibration transforms raw images into accurate, measurable representations of the environmentunlocking everything from autonomous navigation to 3D reconstruction and beyond.</blockquote><p>Here are some practical projects using camera calibration <br><a href="https://github.com/kunal0230">https://github.com/kunal0230</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bff27160acf7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW TO ACHIEVE STEREO VISION WITH ESP32 cams]]></title>
            <link>https://medium.com/@kunalchaugule.2003/how-to-achieve-stereo-vision-with-esp32-cams-f7edc4322c4c?source=rss-2ff591cd1bb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7edc4322c4c</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[depth-estimation]]></category>
            <category><![CDATA[esp32-tutorial]]></category>
            <category><![CDATA[camera-calibration]]></category>
            <category><![CDATA[stereo-vision]]></category>
            <dc:creator><![CDATA[Kunal chaugule ]]></dc:creator>
            <pubDate>Wed, 26 Nov 2025 07:49:49 GMT</pubDate>
            <atom:updated>2025-11-26T07:49:49.179Z</atom:updated>
            <content:encoded><![CDATA[<p>Stereo Vision with Two ESP32-CAMs: Building a Low-Cost Depth Camera from Scratch</p><h4><a href="https://github.com/kunal0230/Distance_Estimation_Using_Stereo_ESP32-CAM"><strong>GITHUB LINK</strong></a></h4><h4><a href="https://docs.google.com/document/d/1aA7EkF1-pRbDs6riaXGG7GqMdybUk7y9RdcNjg_Zues/edit?usp=sharing"><strong>Technical paper written on this topic. </strong></a><strong>Click</strong></h4><p>I’ll go through:</p><ul><li>How stereo vision actually works (from geometry to equations)</li><li>How to physically build a stereo rig with two ESP32-CAMs</li><li>How to get synchronized image pairs into a host machine</li><li>How to calibrate the cameras, rectify images, compute disparity, and estimate depth</li><li>What works, what breaks, and where the real limitations are</li></ul><p>No magic, no black boxes — just geometry, code, and a lot of small details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4URBrmXgOlC4b1h6t7abA.png" /><figcaption>Things to remember all the time</figcaption></figure><h3>1. What Stereo Vision Actually Does</h3><p>At its core, stereo vision is just triangulation.</p><p>Imagine a point in the world, P, seen by two cameras: left and right. Each camera sees P at a different horizontal position in its image. That shift is called <em>disparity</em>. The closer the object is, the bigger the disparity; the farther it is, the smaller the disparity.</p><p>The classic stereo depth formula is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/78/1*0NcQ4ABj0TFl5-feuW90HQ.png" /></figure><p>Where:</p><ul><li><strong><em>Z </em></strong>: depth (distance from cameras to the point)</li><li><strong><em>f </em></strong>: focal length of the camera (in pixels)</li><li><strong><em>B </em></strong>: baseline (distance between the two camera centers)</li><li><strong><em>d</em></strong> : disparity (difference in x-coordinate between left and right images)</li></ul><p>This is not just a formula to memorize. It comes directly from similar triangles.</p><p>Stereo vision is a simple idea at its core: two cameras look at the same scene from slightly different positions, just like a pair of eyes. Because of that separation, a 3D point shows up at different horizontal positions in the two images. That difference is called disparity, and it’s the key to depth. Close objects create a bigger shift between the images, while far objects create a smaller one. Depth is basically encoded in that shift.</p><p>Three things control how depth behaves in a stereo setup:</p><p>• the focal length of the camera,<br> • the distance between the two cameras (the baseline),<br> • and the disparity you measure between the two images.</p><p>All the practical steps — calibration, rectification, and feature matching — exist for one purpose: to measure disparity accurately. Once you have a reliable disparity map, the depth of the entire scene can be recovered. Everything else is just the machinery that makes that measurement possible.</p><h3>2. Why Use ESP32-CAMs for Stereo?</h3><p>ESP32-CAM modules are not “vision research” devices. They’re tiny IoT boards with:</p><ul><li>OV2640 camera (typically up to 1600×1200)</li><li>ESP32 SoC (dual-core microcontroller with Wi-Fi)</li><li>MicroSD slot</li><li>Very low cost</li></ul><h4><strong>So why use them?</strong></h4><ul><li><strong>Cost:</strong> You can build a stereo rig for a fraction of the price of a LiDAR or industrial stereo camera.</li><li><strong>Accessibility:</strong> This makes stereo vision and depth estimation accessible to students and hobbyists.</li><li><strong>Wi-Fi &amp; Embedded angle:</strong> They’re perfect to test ideas that might later move into embedded or edge devices.</li></ul><h4><strong>But they come with hard constraints:</strong></h4><ul><li>Limited processing power (no heavy deep learning models on-board)</li><li>Limited control over shutter synchronization</li><li>Limited resolution and optics quality</li><li>JPEG-compressed output by default (lossy)</li></ul><p>So the strategy I follow is:</p><blockquote><em>Let the ESP32-CAMs act as “dumb eyes” and do the heavy thinking (calibration, rectification, disparity, depth) on a host machine like a laptop or a Raspberry Pi.</em></blockquote><h3>3. Designing the Stereo Rig: Hardware Matters More Than It Looks</h3><p>Before touching any code, the physical setup must be solid. Stereo vision is brutally sensitive to geometry.</p><h4>3.1 Baseline Selection</h4><p>I used a baseline of around <strong>10 cm</strong>. Choosing this distance is a trade-off:</p><ul><li>Larger baseline → better depth accuracy at longer distances, but more difficult matching and more sensitivity to calibration errors.</li><li>Smaller baseline → better for near objects but poor accuracy far away.</li></ul><p>For indoor experiments (0.5–3 m), ~6–12 cm is a nice range. I measured the distance between the optical centers (approximately the center of the lens) with a caliper and recorded it carefully, since that baseline BBB goes directly into the depth formula.</p><h4>3.2 Building the Stereo Rig: Hardware Setup and Mounting</h4><p>Before I could explore calibration, disparity, or depth, I had to solve a more fundamental problem — how to physically build a stereo camera system that behaves like a single, rigid sensing unit. With stereo vision, even a millimeter of mechanical drift can break the geometry, so I treated the build process almost like constructing a lab instrument rather than a hobby project.</p><p>Components I Used</p><ol><li><strong>CP2102 6-Pin USB 2.0 to TTL UART Serial Converter Module</strong><br> (for programming and stable power input)</li><li><strong>Two ESP32-CAM Development Boards with OV2640 Sensors</strong></li><li><strong>Male–Female Jumper Wires</strong></li><li><strong>9 × 15 cm Single-Sided Universal PCB Prototype Board (2.54 mm pitch)</strong></li><li><strong>10-pin, 11 mm tall stackable female headers</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSfe5lihJXhNfEjCy61j-A.jpeg" /><figcaption>Components used for the project ( ignore the sg90 servo those are for a different project )</figcaption></figure><h4>1. Mounting the Cameras on a Rigid Platform</h4><p>I started with the 9×15 cm PCB prototype board. The goal was simple: keep both cameras at the <strong>same height, same plane, and constant baseline</strong>. Stereo vision assumes the two cameras are fixed in space relative to each other, so I treated this step as the foundation of the entire system.</p><p>To achieve this:</p><ul><li>I glued four <strong>10-pin, 11 mm tall stackable female headers</strong> onto the PCB.</li><li>Two headers supported each ESP32-CAM, allowing me to mount the boards at the same height.</li><li>The header mounts gave me two advantages: The cameras remained fixed and parallel. I could remove or remount the ESP32 boards without damaging the rig.</li></ul><p>Once mounted, the two camera lenses formed a clean, horizontal baseline measured carefully to 10 cm. This distance later became the baseline BBB in the depth equation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faNOnv2M7NNb4Tzl-Xkpig.jpeg" /><figcaption>This is how the setup looks once you complete the mounting of esp32 cam on the pcb board</figcaption></figure><h4>2. Wiring and Powering the System</h4><p>The ESP32-CAM doesn’t have a native USB port, so I connected it to the CP2102 TTL converter using jumper wires. The wiring was minimal:</p><ul><li><strong>5V → 5V</strong></li><li><strong>GND → GND</strong></li></ul><p>Once I confirmed one camera was working, I replicated the exact wiring for the second ESP32-CAM. Both modules shared the same power rail and ground reference, ensuring electrical stability.</p><p>Because the goal at this stage wasn’t synchronization but live streaming, I programmed each ESP32-CAM individually through the TTL converter using the Arduino IDE. I uploaded the standard example sketch for Wi-Fi video streaming.</p><p>As soon as both boards were powered and connected to the same Wi-Fi network as my laptop, each ESP32-CAM appeared on the network with its own unique IP address. That gave me two independent live video feeds — left and right.</p><p>In other words, at this stage, <strong>the ESP32-CAMs were acting as two independent “eyes” streaming frames over Wi-Fi.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRtQatIsg53uCgiyDbOb6w.png" /><figcaption>circuit diagram for powering the ESP32 cams</figcaption></figure><h4>3. Bringing the Streams into the Host System</h4><p>Once both streams were live, I could request images from each IP address directly on my laptop and pull them into Python. This step confirmed the</p><blockquote><strong><em>First milestone: Two cameras, mounted rigidly, streaming independent views of the same scene.</em></strong></blockquote><p>At this point, the setup wasn’t a stereo camera yet — it was just two cameras. The transformation into a stereo system begins only when we pair corresponding frames, calibrate both cameras, and mathematically relate one viewpoint to the other. But having clean, repeatable, stable image feeds made the next phase possible.</p><h3>4. Calibration Procedure in Detail</h3><p>Calibration is the stage where the stereo system transitions from two independent cameras to a single geometric sensor. The goal is to determine how each camera maps 3D points in space to 2D pixel coordinates, and then to define the exact spatial relationship between the two cameras.</p><p>The calibration procedure consists of <strong>data acquisition</strong>, <strong>intrinsic calibration</strong>, <strong>stereo (extrinsic) calibration</strong>, and <strong>validation</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOje3jZ2mlJzK3hJMWIa8w.png" /><figcaption>checkerboard patter 9*6</figcaption></figure><h4>1. Calibration Image Acquisition</h4><p><strong>Calibration Target</strong></p><p>A standard printed checkerboard pattern with known square dimensions was used. The physical size of each square (e.g., 25 mm × 25 mm) serves as the metric reference. The real-world 3D coordinates of the checkerboard corners lie on a plane, typically defined as Z = 0 .</p><h4>Capture Requirements</h4><ul><li>Each calibration pose must be captured as a <strong>pair</strong>: one image from the left camera and the corresponding image from the right camera.</li><li>The checkerboard must be placed at multiple:</li></ul><pre>Distances (near, mid-range, far)<br>Orientations (tilted about x-, y-, and z-axes)<br>Positions within the field of view (center, corners, edges)</pre><p>This variation ensures that the calibration algorithm observes enough parallax and distortion to solve the camera parameters accurately.</p><h4>Number of Image Pairs</h4><p>A minimum of 10–15 usable image pairs is required. More pairs generally improve robustness. All images must be captured without changing the physical mounting of the cameras.</p><h4>Corner Detection</h4><p>For each image:</p><ul><li>The 2D pixel coordinates of checkerboard intersections are extracted using cv2.findChessboardCorners().</li><li>These detected points are refined using sub-pixel optimization (cv2.cornerSubPix()).</li></ul><p>Each detected 2D point corresponds to a 3D coordinate on the calibration plane. For example, if the checkerboard has m×nm \times nm×n inner corners and each square has side length sss, the real-world coordinates are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*4VS4X8ADaKJ-tf9lgU9g7w.png" /></figure><p>for integer grid indices <em>i,j</em>.</p><p>This establishes the 2D–to–3D correspondence necessary for solving the projection model.</p><h4>2. Intrinsic Calibration (Per Camera)</h4><p>For each ESP32-CAM independently, OpenCV’s calibrateCamera() estimates:</p><ul><li><strong>Focal lengths</strong>: fx,fy​</li><li><strong>Principal point:</strong> cx,cy</li><li><strong>Lens distortion coefficients:</strong> k1,k2,p1,p2,k3</li></ul><p>These form the <strong>intrinsic matrix</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/143/1*MPWEcc0hitszo4_0CxmUFw.png" /></figure><p>Intrinsic calibration establishes how the camera projects 3D points onto its image sensor.</p><p>Distortion coefficients are later used to correct radial and tangential distortions caused by the OV2640 lens.</p><h4>3. Stereo (Extrinsic) Calibration</h4><p>After intrinsic parameters are known, cv2.stereoCalibrate() computes the relative pose between the left and right cameras:</p><ul><li><strong>Rotation matrix</strong> <strong><em>R</em></strong></li><li><strong>Translation vector</strong> <strong><em>T</em></strong></li></ul><p>The magnitude of <strong><em>T</em></strong> corresponds to the baseline <strong><em>B</em></strong>, which should match the physical measurement taken between lens centers.</p><p>These parameters define how the coordinate system of the left camera maps to that of the right camera. Together, they form the stereo camera model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*xGAy20r3FYAh3IOO4gzuuA.png" /></figure><p>This equation formalizes the transformation from a 3D world point to its 2D projection in each camera.</p><h4>4. Calibration Validation</h4><p>Two key checks:</p><ul><li><strong>Reprojection Error</strong><br> The calibration process minimizes the difference between observed corner positions and the positions predicted by the camera model.<br> Typical acceptable RMS error: <strong>&lt; 0.5 pixels</strong>.</li><li><strong>Consistency Across Pairs</strong><br> The extrinsic parameters must remain consistent across all image pairs, confirming that the stereo rig has not shifted mechanically.</li></ul><p>Calibration results are then saved for use in all subsequent processing.</p><h3>5. Post-Calibration Processing Pipeline</h3><p>Once calibration is complete, the system can transform raw image pairs into quantitative depth information.</p><p><strong>The pipeline consists of:</strong></p><ol><li>Undistortion</li><li>Rectification</li><li>Disparity computation</li><li>Depth map computation</li><li>Object distance estimation</li></ol><h4>1. Undistortion</h4><p>Using the intrinsic matrix and distortion coefficients, each captured image is corrected to remove lens distortion. This ensures straight lines in the real-world map to straight lines in the image.</p><p>OpenCV function:<br> cv2.undistort()</p><h4>2. Stereo Rectification</h4><p>Even with perfect calibration, corresponding points in the left and right images will not lie on the same horizontal line. Rectification warps both images so that:</p><ul><li>Epipolar lines become horizontal</li><li>Correspondence search becomes 1-dimensional</li></ul><p>OpenCV functions:</p><ul><li>cv2.stereoRectify()</li><li>cv2.remap()</li></ul><p>After rectification:</p><ul><li>A point at row rrr in the left image will appear at row rrr in the right image.</li><li>Only horizontal displacement matters, simplifying disparity estimation.</li></ul><h4>3. Disparity Computation</h4><p>For each pixel in the left rectified image, the algorithm searches along the same row in the right image to find the best match. The horizontal shift is the disparity <strong><em>d</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/93/1*akPcYcrjy3PPpu-POylw_w.png" /></figure><p>OpenCV implementation:</p><ul><li>cv2.StereoSGBM_create()</li></ul><p>SGBM (Semi-Global Block Matching) balances accuracy and computational efficiency, producing dense disparity maps suitable for short-range depth estimation.</p><p>The output is a matrix where each pixel stores its disparity value in pixels.</p><h4>4. Depth Map Calculation</h4><p>The stereo depth formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/78/1*0NcQ4ABj0TFl5-feuW90HQ.png" /></figure><p>Where:</p><ul><li><strong><em>Z </em></strong>: depth (distance from cameras to the point)</li><li><strong><em>f </em></strong>: focal length of the camera (in pixels)</li><li><strong><em>B </em></strong>: baseline (distance between the two camera centers)</li><li><strong><em>d</em></strong> : disparity (difference in x-coordinate between left and right images)</li></ul><p>Key characteristics:</p><ul><li>Depth is inversely proportional to disparity.</li><li>Large disparity → object close.</li><li>Small disparity → object far.</li></ul><p>Depth cannot be computed where:</p><ul><li>d=0d = 0d=0</li><li>matching fails</li><li>occlusion occurs</li></ul><p>Such pixels are typically masked.</p><p>The depth map is a 2D matrix where each pixel contains its estimated physical distance.</p><h3>5. Measuring Object Distance</h3><p>To estimate the distance between the camera and a specific object:</p><ol><li>Detect or select the pixel(s) corresponding to the object.</li><li>Retrieve the disparity value(s).</li><li>Compute depth ZZZ using the formula above.</li><li>For larger objects, average disparity over a region to reduce noise.</li></ol><p>If the object occupies a pixel at disparity d=12 , with:</p><ul><li><strong><em>f</em></strong> =520 pixels</li><li><strong><em>B </em></strong>=0.10 m</li></ul><p>Then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*aPlVTY30NAQ-cDbX__Kvvw.png" /></figure><p>This provides a direct, metric estimate of object distance from the camera plane.</p><h3>Summary</h3><ul><li>Calibration defines the intrinsic and extrinsic parameters required for geometric correctness.</li><li>Rectification constrains correspondence to horizontal lines.</li><li>Disparity extraction quantifies pixel-level shifts between viewpoints.</li><li>The depth formula converts disparity into physical distance.</li><li>The resulting depth map enables distance measurement between the camera and any visible object.</li></ul><p>This sequence transforms two ESP32-CAM image streams into quantitative 3D information, completing the stereo vision pipeline.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7edc4322c4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Polyp Segmentation Using UNet 3+: A Practical Guide]]></title>
            <link>https://medium.com/@kunalchaugule.2003/polyp-segmentation-using-unet-3-a-practical-guide-8113365a6bb3?source=rss-2ff591cd1bb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8113365a6bb3</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[medical-imaging]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[ai-in-healthcare]]></category>
            <dc:creator><![CDATA[Kunal chaugule ]]></dc:creator>
            <pubDate>Tue, 07 Jan 2025 09:43:53 GMT</pubDate>
            <atom:updated>2025-01-07T09:43:53.056Z</atom:updated>
            <content:encoded><![CDATA[<p>Medical imaging is one of the most transformative areas for artificial intelligence (AI) and deep learning. Among its applications, <strong>polyp segmentation</strong> plays a crucial role in aiding clinicians to detect abnormalities in the gastrointestinal tract efficiently. In this article, I’ll explain the implementation of a deep learning model, <strong>UNet 3+</strong>, to address this problem. We’ll cover dataset preprocessing, model architecture, training process, and evaluation metrics like <strong>Intersection over Union (IoU)</strong> and <strong>Dice Coefficient</strong>.</p><h3>Why Polyp Segmentation?</h3><p>Polyps are abnormal growths in the colon or rectum and can be precursors to colorectal cancer. Timely detection through colonoscopy is critical, but manual review is labor-intensive and prone to error. Deep learning-based segmentation can assist clinicians by automating the detection and highlighting areas of interest, significantly improving efficiency and accuracy.</p><h3>Overview of UNet 3+</h3><p><strong>UNet 3+</strong> is an upgraded version of the classic UNet architecture designed for biomedical image segmentation. It enhances the feature representation by:</p><ol><li><strong>Deep Supervision:</strong> Including outputs from multiple levels of the network to improve prediction quality.</li><li><strong>Full-Scale Skip Connections:</strong> Integrating features from all scales to improve segmentation precision.</li><li><strong>Better Gradient Flow:</strong> Addressing vanishing gradients with improved connectivity.</li></ol><p>UNet 3+ is particularly well-suited for medical imaging tasks where fine-grained segmentation is required.</p><h3>Steps in the Implementation</h3><h4>1. Dataset Preprocessing</h4><p>For this project, I used the <strong>Kvasir-SEG dataset</strong>, a publicly available dataset for polyp segmentation. The dataset consists of images and corresponding ground truth masks.</p><p><strong>Image Augmentation:</strong></p><ul><li>Applied transformations like rotation, flipping, and brightness adjustment to increase data diversity.</li><li>Normalized pixel values to the range [0, 1] for faster model convergence.</li></ul><p><strong>Resizing:</strong></p><ul><li>Resized all images and masks to a fixed resolution (e.g., 256×256) to maintain uniformity and reduce computational overhead.</li></ul><h4>2. Model Architecture</h4><p>The UNet 3+ architecture consists of the following key components:</p><ul><li><strong>Encoder:</strong> Extracts hierarchical feature representations from input images using a convolutional backbone (e.g., ResNet).</li><li><strong>Decoder:</strong> Combines hierarchical features with fine-grained details from earlier layers to predict segmentation masks.</li><li><strong>Skip Connections:</strong> Bridges between encoder and decoder to retain spatial information.</li></ul><h4>3. Training Process</h4><p><strong>Loss Function:</strong></p><ul><li>Used a combination of <strong>Binary Cross-Entropy (BCE)</strong> and <strong>Dice Loss</strong> to handle class imbalance and improve segmentation accuracy.</li><li>Formula for Dice Loss:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*jI7c76C8P6mGtlbxYENeXQ.png" /></figure><p>Where <em>P</em> is the predicted mask and <em>G</em> is the ground truth mask.</p><p><strong>Optimizer:</strong></p><ul><li>Used <strong>Adam Optimizer</strong> with a learning rate scheduler to ensure stable convergence.</li></ul><p><strong>Training Pipeline:</strong></p><ul><li>Split the dataset into <strong>80% training</strong> and <strong>20% validation</strong>.</li><li>Trained for 50 epochs with batch size 16 using <strong>TensorFlow/Keras</strong>.</li></ul><h3>4. Evaluation Metrics</h3><p>The performance of the segmentation model was evaluated using:</p><ol><li><strong>Intersection over Union (IoU):</strong></li></ol><ul><li>Measures the overlap between the predicted mask and the ground truth.</li><li>Formula:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*qW4Pv_0PJsg8oN_AdMfkKQ.png" /></figure><p><strong>Dice Coefficient:</strong></p><ul><li>Similar to IoU but emphasizes true positives.</li><li>Formula:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/119/1*hUPTIS7WiU573eWxdlDN_g.png" /></figure><ol><li><strong>Accuracy and Loss Curves:</strong></li></ol><ul><li>Plotted training and validation accuracy/loss to ensure the model wasn’t overfitting.</li></ul><p>The final model achieved an <strong>IoU of 92%</strong> and a <strong>Dice Coefficient of 90%</strong>, showcasing excellent segmentation performance.</p><h3>Results</h3><p>Here’s an example of the model’s predictions:</p><ul><li><strong>Input Image:</strong> A colonoscopy frame with visible polyps.</li><li><strong>Ground Truth Mask:</strong> The manually annotated mask outlining the polyp.</li><li><strong>Predicted Mask:</strong> The model-generated segmentation, closely matching the ground truth.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*ymLBPLg58PHtzecsMjUpsA.png" /></figure><h3>Conclusion</h3><p>The <strong>UNet 3+</strong> model proved to be a powerful tool for polyp segmentation in medical imaging. By leveraging its advanced architecture and incorporating effective training techniques, it achieved state-of-the-art results. This project demonstrates the potential of AI to assist in medical diagnostics, saving time and potentially lives.</p><p>In the future, this model can be extended to:</p><ul><li>Handle real-time colonoscopy video streams.</li><li>Integrate with clinical workflows for practical deployment.</li></ul><p>If you’re interested in the code, you can check out my <a href="https://github.com/kunal0230/Polyp-Segmentation-Using-UNet-3-with-TensorFlow"><strong>GitHub Repository</strong></a> for details on the implementation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8113365a6bb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Deepfake Technology Works: A Deep Dive]]></title>
            <link>https://medium.com/@kunalchaugule.2003/how-deepfake-technology-works-a-deep-dive-5e03c4af4ead?source=rss-2ff591cd1bb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e03c4af4ead</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[deepfakes]]></category>
            <dc:creator><![CDATA[Kunal chaugule ]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 17:54:52 GMT</pubDate>
            <atom:updated>2024-12-10T17:55:41.788Z</atom:updated>
            <content:encoded><![CDATA[<p>In recent years, deepfake technology has emerged as one of the most fascinating yet controversial innovations in artificial intelligence (AI). It allows the creation of hyper-realistic images, videos, and audio that appear to be authentic but are entirely synthetic. From transforming actors’ faces in movies to raising ethical concerns about misinformation, deepfakes are reshaping our digital landscape. But how does this technology actually work? Let’s break it down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ILJS3C6bcnr66Ykf4TOuDw.jpeg" /></figure><h4>What Is a Deepfake?</h4><p>The term “deepfake” is a combination of “deep learning” and “fake.” It refers to media generated or manipulated using deep learning algorithms to mimic a person’s appearance, voice, or actions. While the term is often associated with malicious uses, deepfake technology also has legitimate applications in entertainment, education, and accessibility.</p><h4>The Technology Behind Deepfakes</h4><p>At the heart of deepfake technology lies <strong>deep learning</strong>, a subset of machine learning that mimics the workings of the human brain to process data. Specifically, deepfakes are powered by <strong>generative adversarial networks (GANs)</strong>, an advanced neural network architecture.</p><ol><li><strong>Generative Adversarial Networks (GANs)</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*d-eOM25fvsDObVi5Dir-Ug.jpeg" /></figure><p>A GAN consists of two neural networks:</p><ul><li><strong>Generator</strong>: This network creates synthetic data, such as fake images or videos.</li><li><strong>Discriminator</strong>: This network evaluates the generated data and determines whether it is real or fake.</li></ul><p>The generator and discriminator compete in a “cat-and-mouse” game. Over time, the generator learns to create increasingly realistic data that can fool the discriminator.</p><p>2. <strong>Training the Model</strong></p><p>Deepfake models require large datasets of images or videos of the target individual to train the GAN. For example:</p><ul><li>A dataset of a person’s face captured from various angles and lighting conditions is fed into the network.</li><li>The generator synthesizes images, and the discriminator critiques them until the generator produces highly convincing results.</li></ul><h4>Steps Involved in Creating a Deepfake</h4><ol><li><strong>Data Collection</strong>: Gather a large dataset of the target individual. This can include photos, videos, or audio recordings, depending on the type of deepfake.</li><li><strong>Preprocessing</strong>: Normalize the data by aligning faces, cropping images, and standardizing video formats to ensure consistency.</li><li><strong>Training the GAN</strong>: Train the GAN using the preprocessed data. The generator starts producing low-quality images or videos, but the quality improves as the GAN iterates.</li><li><strong>Face Swapping</strong>: In video-based deepfakes, the trained model maps the synthetic face onto a source actor’s face in a video. Techniques like <strong>face alignment</strong> and <strong>blending</strong> are used to make transitions seamless.</li><li><strong>Post-Processing</strong>: Tools like video editing software are used to fine-tune the output, adjusting lighting, shadows, and details to ensure realism.</li></ol><h4>Applications of Deepfakes</h4><ol><li><strong>Entertainment</strong>:</li></ol><ul><li>Creating realistic visual effects in movies.</li><li>Resurrecting deceased actors for performances.</li></ul><p>2. <strong>Education and Accessibility</strong>:</p><ul><li>Producing educational videos with dynamic visual aids.</li><li>Developing virtual avatars for accessibility tools.</li></ul><p>3. <strong>Advertising and Marketing</strong>: Personalized ads using a consumer’s likeness.</p><p><strong>4. Creative Arts</strong>: Artists use deepfake tools to create thought-provoking digital art</p><h4>Risks and Ethical Concerns</h4><p>Despite its potential, deepfake technology has significant ethical and societal implications:</p><ol><li><strong>Misinformation</strong>: Deepfakes can spread fake news or propaganda by portraying people saying or doing things they never did.</li><li><strong>Privacy Violations</strong>: Using someone’s likeness without their consent raises serious privacy concerns.</li><li><strong>Cybersecurity Threats</strong>: Deepfakes can be used for fraud, such as impersonating individuals in video calls.</li></ol><h4>Detecting and Mitigating Deepfakes</h4><p>As deepfakes become more sophisticated, detecting them is increasingly challenging. Researchers are developing AI tools to identify inconsistencies in:</p><ul><li>Facial movements or expressions.</li><li>Pixel-level anomalies.</li><li>Audio-visual mismatches.</li></ul><p>Additionally, organizations are advocating for policies to regulate the use of deepfake technology and educate the public about its potential misuse.</p><h4>Conclusion</h4><p>Deepfake technology is a testament to the incredible power of AI, showcasing both its creative potential and its capacity for harm. While it has legitimate applications in fields like entertainment and accessibility, its misuse poses significant challenges. As we continue to navigate the digital age, understanding how deepfakes work is crucial to harnessing their benefits while mitigating their risks.</p><ul><li>Creating realistic visual effects in movies.</li><li>Resurrecting deceased actors for performances.</li></ul><ol><li><strong>Education and Accessibility</strong>:</li></ol><ul><li>Producing educational videos with dynamic visual aids.</li><li>Developing virtual avatars for accessibility tools.</li></ul><ol><li><strong>Advertising and Marketing</strong>: Personalized ads using a consumer’s likeness.</li><li><strong>Creative Arts</strong>: Artists use deepfake tools to create thought-provoking digital art.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e03c4af4ead" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Human Background Remover Web App Using Python, Flask, OpenCV, and Mediapipe]]></title>
            <link>https://medium.com/@kunalchaugule.2003/build-a-human-background-remover-web-app-using-python-flask-opencv-and-mediapipe-6f763d91b186?source=rss-2ff591cd1bb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f763d91b186</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mediapipe]]></category>
            <category><![CDATA[2nd-year]]></category>
            <category><![CDATA[simple-project]]></category>
            <dc:creator><![CDATA[Kunal chaugule ]]></dc:creator>
            <pubDate>Sat, 12 Oct 2024 02:00:31 GMT</pubDate>
            <atom:updated>2024-10-12T02:00:31.404Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In today’s world of social media and virtual meetings, having a clean and professional-looking image with no background distractions is incredibly useful. Whether it’s for profile pictures, thumbnails, or personal projects, removing the background from an image has become a popular task. But instead of relying on paid software, why not build your own <strong>background remover</strong>?</p><p>In this article, we’ll walk through how I built a <strong>Human Background Remover Web App</strong> using <strong>Python</strong>, <strong>Flask</strong>, <strong>OpenCV</strong>, and <strong>Mediapipe</strong>. The web app allows users to upload an image, removes the background around the human subject, and provides a downloadable PNG file with a transparent background.</p><h3>What You’ll Learn:</h3><ul><li>How to use <strong>Mediapipe</strong> for human segmentation.</li><li>How to integrate <strong>Flask</strong> for building a simple web application.</li><li>How to use <strong>OpenCV</strong> to manipulate images and handle transparency.</li><li>How to add additional features like previewing images and downloading results.</li></ul><h3>Why Build This App?</h3><p>There are many tools out there that can remove image backgrounds, but building one yourself offers several advantages:</p><ul><li><strong>Customization</strong>: You can tweak it to meet your specific needs, whether it’s to add filters, replace backgrounds, or process videos.</li><li><strong>Learning Opportunity</strong>: This project gives you hands-on experience with key computer vision libraries, such as OpenCV and Mediapipe, as well as Flask for web development.</li><li><strong>Expandability</strong>: Once built, you can expand this project into more advanced tools like real-time background removal or video background processing.</li></ul><h3>Tools and Libraries</h3><p>We’ll be using the following tools and libraries to build the app:</p><ul><li><strong>Python</strong>: The language of choice for the app.</li><li><strong>Flask</strong>: A lightweight web framework for Python.</li><li><strong>Mediapipe</strong>: A powerful framework by Google, used here for human segmentation.</li><li><strong>OpenCV</strong>: A popular computer vision library for image processing.</li><li><strong>NumPy</strong>: For array and matrix operations.</li></ul><h3>Project Setup</h3><p>To get started, you’ll need to install the following dependencies. Here’s the requirements.txt file to use:</p><pre>Flask==2.3.2<br>opencv-python==4.8.0.74<br>mediapipe==0.10.0<br>numpy==1.23.5</pre><p>You can install the required packages with:</p><pre>pip install -r requirements.txt</pre><h3>Step 1: Building the Flask Web App</h3><p>We’ll start by setting up a basic Flask application. The home route will render an HTML form that allows users to upload an image.</p><p>Here’s how our Flask app (app.py) starts:</p><pre>from flask import Flask, render_template, request, redirect, url_for<br>import cv2<br>import numpy as np<br>import mediapipe as mp<br><br>app = Flask(__name__)<br><br># Initialize Mediapipe&#39;s segmentation model<br>mp_selfie_segmentation = mp.solutions.selfie_segmentation<br>segmenter = mp_selfie_segmentation.SelfieSegmentation(model_selection=1)<br><br>@app.route(&#39;/&#39;)<br>def home():<br>    return render_template(&#39;index.html&#39;)</pre><p>This sets up a basic Flask app with a home route that renders the index.html page, which we’ll cover later.</p><h3>Step 2: Uploading Images and Processing with Mediapipe</h3><p>After the user uploads an image, we need to process it using <strong>Mediapipe</strong> to detect the human subject and <strong>OpenCV</strong> to manipulate the image. Here’s how we handle image uploads and background removal:</p><pre>@app.route(&#39;/upload&#39;, methods=[&#39;POST&#39;])<br>def upload_image():<br>    file = request.files[&#39;file&#39;]<br>    if file:<br>        filepath = &#39;static/uploads/&#39; + file.filename<br>        file.save(filepath)<br>        result_image = remove_background(filepath)<br><br>        # Save the result with transparency<br>        output_filepath = &#39;static/uploads/transparent_&#39; + file.filename<br>        cv2.imwrite(output_filepath, result_image)<br><br>        return render_template(&#39;index.html&#39;, original_image=filepath, output_image=output_filepath)<br><br>def remove_background(image_path):<br>    image = cv2.imread(image_path)<br>    rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)<br><br>    # Perform segmentation<br>    result = segmenter.process(rgb_image)<br>    mask = result.segmentation_mask<br><br>    # Apply Gaussian blur to smooth edges<br>    blurred_mask = cv2.GaussianBlur(mask, (15, 15), 0)<br><br>    condition = blurred_mask &gt; 0.5<br>    transparent_image = np.zeros((image.shape[0], image.shape[1], 4), dtype=np.uint8)<br><br>    transparent_image[condition] = np.concatenate([image[condition], np.full((np.sum(condition), 1), 255)], axis=-1)<br>    return transparent_image</pre><p>In this function:</p><ul><li>We use <strong>Mediapipe</strong> to create a segmentation mask around the human figure.</li><li><strong>Gaussian blur</strong> is applied to smooth the edges of the mask.</li><li>Finally, we create a transparent PNG by adding an alpha channel to the original image.</li></ul><h3>How the Human Background Remover Works</h3><p>At the heart of this project lies the ability to detect and segment the human subject in an image and remove everything around it. We achieve this using a combination of <strong>Mediapipe</strong> and <strong>OpenCV</strong> — two powerful tools for computer vision and image processing.</p><p>Here’s a breakdown of how it works:</p><h4>1. Human Segmentation with Mediapipe</h4><p><a href="https://mediapipe.dev/">Mediapipe</a> is a machine learning framework developed by Google that provides efficient, pre-trained models for various tasks such as pose detection, facial recognition, and human segmentation. For this project, we use <strong>Mediapipe’s Selfie Segmentation Model</strong>.</p><ul><li><strong>Segmentation</strong> is the process of partitioning an image into multiple regions or objects. Here, we use it to identify the pixels that belong to the human subject and separate them from the background.</li><li>The model returns a <strong>segmentation mask</strong>, where each pixel in the image is classified as either part of the person or part of the background. The mask is essentially a black-and-white image where white pixels correspond to the human subject and black pixels to the background.</li></ul><h4>2. Image Processing with OpenCV</h4><p>Once we have the segmentation mask, we use <strong>OpenCV</strong> to manipulate the image and remove the background. OpenCV is a widely-used library for real-time computer vision and image processing tasks.</p><ul><li>We apply a <strong>Gaussian blur</strong> to smooth the edges of the segmentation mask. This reduces the harsh lines that often appear around the subject, making the final image look more natural.</li><li>We then create an <strong>alpha channel</strong> for the image, which defines the transparency of each pixel. The human subject’s pixels are fully opaque (alpha value of 255), while the background pixels are made completely transparent (alpha value of 0).</li></ul><h4>3. Creating a Transparent PNG</h4><p>Finally, we combine the original image with the processed segmentation mask to produce an image with a transparent background. By saving the image in the <strong>PNG format</strong>, we ensure that it retains its transparency when downloaded or used elsewhere.</p><p>In summary, the process looks like this:</p><ol><li><strong>Input</strong>: User uploads an image.</li><li><strong>Segmentation</strong>: Mediapipe identifies the human subject and generates a mask.</li><li><strong>Mask Processing</strong>: OpenCV smooths the mask edges and applies it to the image.</li><li><strong>Transparency</strong>: The background is removed, and the final image is saved as a transparent PNG.</li></ol><h3>Step 3: User Interface (HTML + CSS)</h3><p>Here’s the simple HTML form where users can upload their images (index.html):</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Background Removal Web App&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;style.css&#39;) }}&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div class=&quot;container&quot;&gt;<br>        &lt;h1&gt;Background Removal Web App&lt;/h1&gt;<br>        &lt;p&gt;Upload an image and remove its background using machine learning!&lt;/p&gt;<br><br>        &lt;div class=&quot;upload-box&quot;&gt;<br>            &lt;form action=&quot;/upload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;<br>                &lt;input type=&quot;file&quot; name=&quot;file&quot; class=&quot;upload-input&quot;&gt;<br>                &lt;input type=&quot;submit&quot; value=&quot;Upload Image&quot; class=&quot;upload-btn&quot;&gt;<br>            &lt;/form&gt;<br>        &lt;/div&gt;<br><br>        {% if original_image and output_image %}<br>        &lt;div id=&quot;preview-section&quot;&gt;<br>            &lt;div class=&quot;image-preview-container&quot;&gt;<br>                &lt;h3&gt;Original Image&lt;/h3&gt;<br>                &lt;img src=&quot;{{ original_image }}&quot; alt=&quot;Original Image&quot; class=&quot;image-preview&quot;&gt;<br>            &lt;/div&gt;<br>            &lt;div class=&quot;image-preview-container&quot;&gt;<br>                &lt;h3&gt;Background Removed&lt;/h3&gt;<br>                &lt;img src=&quot;{{ output_image }}&quot; alt=&quot;Processed Image&quot; class=&quot;image-preview&quot;&gt;<br>                &lt;br&gt;<br>                &lt;!-- Download button for the transparent PNG --&gt;<br>                &lt;a href=&quot;{{ output_image }}&quot; download class=&quot;download-btn&quot;&gt;Download PNG&lt;/a&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        {% endif %}<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><pre>body {<br>    font-family: Arial, sans-serif;<br>    background-color: #f0f0f5;<br>    color: #333;<br>    text-align: center;<br>    padding: 20px;<br>}<br><br>.container {<br>    max-width: 800px;<br>    margin: 0 auto;<br>    background-color: white;<br>    padding: 30px;<br>    border-radius: 8px;<br>    box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);<br>}<br><br>h1 {<br>    font-size: 2em;<br>    margin-bottom: 10px;<br>    color: #4CAF50;<br>}<br><br>p {<br>    font-size: 1.1em;<br>    margin-bottom: 20px;<br>}<br><br>.upload-box {<br>    margin: 20px 0;<br>}<br><br>.upload-input {<br>    margin: 10px 0;<br>}<br><br>.upload-btn {<br>    padding: 10px 20px;<br>    background-color: #4CAF50;<br>    border: none;<br>    color: white;<br>    font-size: 1em;<br>    border-radius: 5px;<br>    cursor: pointer;<br>    transition: background-color 0.3s ease;<br>}<br><br>.upload-btn:hover {<br>    background-color: #45a049;<br>}<br><br>#preview-section {<br>    display: flex;<br>    justify-content: space-between;<br>    margin-top: 30px;<br>    text-align: center;<br>}<br><br>.image-preview-container {<br>    width: 45%;<br>}<br><br>.image-preview {<br>    width: 100%;<br>    height: auto;<br>    border-radius: 8px;<br>    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);<br>}<br><br>h3 {<br>    color: #333;<br>}<br>.download-btn {<br>    display: inline-block;<br>    margin-top: 10px;<br>    padding: 10px 20px;<br>    background-color: #4CAF50;<br>    color: white;<br>    text-decoration: none;<br>    border-radius: 5px;<br>    font-size: 1em;<br>    transition: background-color 0.3s ease;<br>}<br><br>.download-btn:hover {<br>    background-color: #45a049;<br>}</pre><p>This simple form allows users to upload images and provides the option to download the processed image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQNf3YYhsUEsAHoTBOhAoA.png" /><figcaption>THE WEB APP</figcaption></figure><h3>Conclusion</h3><p>This project demonstrates how powerful and flexible Python libraries like <strong>Mediapipe</strong>, <strong>OpenCV</strong>, and <strong>Flask</strong> can be for building practical applications. The <strong>Human Background Remover</strong> project can be easily expanded with additional features and serves as a great introduction to web-based computer vision tasks.</p><p>Feel free to check out the <a href="https://github.com/kunal0230/human_background_remover">GitHub repository</a> for the complete code!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f763d91b186" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Edge Detection Web App with Python, Flask, and OpenCV]]></title>
            <link>https://medium.com/@kunalchaugule.2003/building-an-edge-detection-web-app-with-python-flask-and-opencv-3326714be13f?source=rss-2ff591cd1bb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3326714be13f</guid>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[edge-detection]]></category>
            <dc:creator><![CDATA[Kunal chaugule ]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 10:58:53 GMT</pubDate>
            <atom:updated>2024-10-05T10:58:53.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>Welcome to this tutorial! Today, we’re going to build a simple <strong>Edge Detection Web App</strong> using Python, Flask, and OpenCV. This project will allow users to upload an image, apply edge detection to that image, and then view or download the processed image.</h3><p><strong>Edge detection</strong> is a technique in computer vision that detects the boundaries of objects within an image. It’s used in applications like object detection, image segmentation, and computer vision systems.</p><p>In this guide, I’ll walk you through the process step by step, so even if you’re a beginner, you’ll be able to follow along and build this project from scratch.</p><p>By the end of this tutorial, you’ll have your own <strong>Edge Detection Web App</strong> running on your computer!</p><h3>What We’ll Build</h3><p>Our project will allow users to:</p><ul><li>Upload an image via a simple web interface.</li><li>Apply <strong>Canny edge detection</strong> to that image.</li><li>View the original and processed images side by side.</li><li>Download the processed image.</li></ul><p>Here’s an example of what the final app will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2mC7FbnWyCFM99OLTi2dw.png" /><figcaption>HOME PAGE</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UyK9A2OdEy7y7--FDhtXSA.png" /><figcaption>Home page_2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BdcqlpgAX6zQbmDPg_tM6w.png" /><figcaption>OutPut</figcaption></figure><p>Before we start, make sure you have the following installed on your computer:</p><ul><li><strong>Python 3</strong></li><li><strong>pip</strong> (Python package installer)</li><li><strong>Virtual environment</strong> (optional but recommended)</li></ul><p>If you don’t have these, you can <a href="https://www.python.org/downloads/">download Python here</a>, and pip is included with Python. Virtual environments are useful for keeping your projects organized, but they’re optional for this tutorial.</p><h3>Step 1: Setting Up the Project</h3><p>First, we need to create a folder for our project.</p><ol><li>Open a terminal or command prompt and navigate to a directory where you want to create your project folder.</li><li>Create a folder for your project and move into that folder:</li></ol><pre>mkdir edge-detection-web-app<br>cd edge-detection-web-app</pre><h3>Step 2: Setting Up the Virtual Environment (Optional but Recommended)</h3><p>A virtual environment helps keep your project’s dependencies isolated from other projects. Let’s set one up:</p><ol><li>Run the following command to create a virtual environment:</li></ol><pre>python3 -m venv venv</pre><p>Activate the virtual environment:</p><ul><li>On macOS/Linux:</li></ul><pre>source venv/bin/activate</pre><p>On Windows:</p><pre>venv\Scripts\activate</pre><p>You’ll know the virtual environment is active if you see (venv) at the beginning of your terminal prompt.</p><h3>Step 3: Installing Flask and OpenCV</h3><p>Now that we’re in our virtual environment, let’s install the necessary packages:</p><ol><li>Install Flask (our web framework) and OpenCV (our image processing library):</li></ol><pre>pip install Flask opencv-python</pre><p>These will be the core tools we use for this project.</p><h3>Step 4: Setting Up the Flask App</h3><p>Now let’s create the web app. Flask will be our web framework to handle requests and serve the front end.</p><ol><li>Create a new file called app.py and add the following code:</li></ol><pre>import os<br>import cv2<br>import numpy as np<br>from flask import Flask, render_template, request, redirect, url_for, send_from_directory<br><br>app = Flask(__name__)<br><br># Directory to save uploaded and processed images<br>UPLOAD_FOLDER = &#39;static/images&#39;<br>app.config[&#39;UPLOAD_FOLDER&#39;] = UPLOAD_FOLDER<br><br># Ensure the upload folder exists<br>if not os.path.exists(UPLOAD_FOLDER):<br>    os.makedirs(UPLOAD_FOLDER)<br><br>@app.route(&#39;/&#39;)<br>def index():<br>    return render_template(&#39;index.html&#39;)<br><br>@app.route(&#39;/edge-detection&#39;)<br>def edge_detection():<br>    return render_template(&#39;edge_detection.html&#39;)<br><br><br><br>@app.route(&#39;/upload&#39;, methods=[&#39;POST&#39;])<br>def upload_image():<br>    # Check if a file was uploaded<br>    if &#39;file&#39; not in request.files:<br>        return redirect(request.url)<br><br>    file = request.files[&#39;file&#39;]<br><br>    if file.filename == &#39;&#39;:<br>        return redirect(request.url)<br><br>    if file:<br>        # Save the uploaded image<br>        file_path = os.path.join(app.config[&#39;UPLOAD_FOLDER&#39;], &#39;original.jpg&#39;)<br>        file.save(file_path)<br><br>        # Process the image for edge detection<br>        process_image(file_path)<br><br>        return redirect(url_for(&#39;display_images&#39;))<br><br>def process_image(image_path):<br>    # Read the uploaded image<br>    image = cv2.imread(image_path)<br><br>    # Convert the image to grayscale<br>    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<br><br>    # Apply Gaussian Blur to reduce noise<br>    blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)<br><br>    # Perform Canny edge detection<br>    edges = cv2.Canny(blurred_image, 100, 200)<br><br>    # Save the edge-detected image<br>    edge_path = os.path.join(app.config[&#39;UPLOAD_FOLDER&#39;], &#39;edges.jpg&#39;)<br>    cv2.imwrite(edge_path, edges)<br><br>    # Create a comparison image (original and processed side by side)<br>    edges_bgr = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)<br>    comparison_image = np.hstack((image, edges_bgr))<br>    <br>    # Save the comparison image<br>    comparison_path = os.path.join(app.config[&#39;UPLOAD_FOLDER&#39;], &#39;comparison.jpg&#39;)<br>    cv2.imwrite(comparison_path, comparison_image)<br><br>@app.route(&#39;/display&#39;)<br>def display_images():<br>    # Render the page to display the images and allow download<br>    return render_template(&#39;display.html&#39;)<br><br>@app.route(&#39;/download/&lt;filename&gt;&#39;)<br>def download_file(filename):<br>    # Allow the user to download images<br>    return send_from_directory(app.config[&#39;UPLOAD_FOLDER&#39;], filename)<br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(debug=True)</pre><h3>Step 5: Creating the HTML Templates</h3><p>Next, we need to create the HTML templates that will serve the frontend. Create a folder called templates and add the following files:</p><ol><li>index.html (Homepage):</li></ol><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Edge Detection App&lt;/title&gt;<br>    &lt;!-- Bootstrap CSS --&gt;<br>    &lt;link href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;styles.css&#39;) }}&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;!-- Navigation bar --&gt;<br>    &lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-light&quot;&gt;<br>        &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;Edge Detection&lt;/a&gt;<br>        &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#navbarNav&quot; aria-controls=&quot;navbarNav&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;<br>            &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;<br>        &lt;/button&gt;<br>        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNav&quot;&gt;<br>            &lt;ul class=&quot;navbar-nav ml-auto&quot;&gt;<br>                &lt;li class=&quot;nav-item&quot;&gt;<br>                    &lt;a class=&quot;nav-link&quot; href=&quot;/&quot;&gt;Home&lt;/a&gt;<br>                &lt;/li&gt;<br>                &lt;li class=&quot;nav-item&quot;&gt;<br>                    &lt;a class=&quot;nav-link&quot; href=&quot;/edge-detection&quot;&gt;Try Edge Detection&lt;/a&gt;<br>                &lt;/li&gt;<br>            &lt;/ul&gt;<br>        &lt;/div&gt;<br>    &lt;/nav&gt;<br><br>    &lt;!-- Hero Section --&gt;<br><br>&lt;!-- Hero Section with Local Background Image --&gt;<br>&lt;section class=&quot;hero-section text-center text-white&quot; style=&quot;background-image: url(https://medium.com/&#39;{{%20url_for(&#39;static&#39;,%20filename=&#39;images/edge2-1.png&#39;) }}&#39;); background-size: cover; background-position: center; padding: 150px 20px;&quot;&gt;<br>    &lt;h1 class=&quot;display-4&quot;&gt;Welcome to the Edge Detection App&lt;/h1&gt;<br>    &lt;p class=&quot;lead&quot;&gt;Transform your images using edge detection technology, a powerful tool in computer vision.&lt;/p&gt;<br>    &lt;a href=&quot;/edge-detection&quot; class=&quot;btn btn-lg btn-primary mt-3&quot;&gt;Try Edge Detection&lt;/a&gt;<br>&lt;/section&gt;<br><br><br><br>    &lt;!-- How It Works Section --&gt;<br>    &lt;section class=&quot;container my-5&quot;&gt;<br>        &lt;h2 class=&quot;text-center mb-4&quot;&gt;How Edge Detection Works&lt;/h2&gt;<br>        &lt;div class=&quot;row&quot;&gt;<br>            &lt;div class=&quot;col-md-6&quot;&gt;<br>                &lt;p&gt;Edge detection is a technique in image processing that detects the boundaries of objects within an image. The most common algorithm is Canny edge detection, which works by:&lt;/p&gt;<br>                &lt;ul&gt;<br>                    &lt;li&gt;Converting the image to grayscale.&lt;/li&gt;<br>                    &lt;li&gt;Applying a Gaussian blur to reduce noise.&lt;/li&gt;<br>                    &lt;li&gt;Detecting edges using the gradient of intensity changes.&lt;/li&gt;<br>                    &lt;li&gt;Tracing edges based on the detected gradients.&lt;/li&gt;<br>                &lt;/ul&gt;<br>            &lt;/div&gt;<br>            &lt;div class=&quot;col-md-6&quot;&gt;<br>                &lt;img src=&quot;static/images/edge2-1.png&quot; class=&quot;img-fluid&quot; alt=&quot;Edge Detection&quot;&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;p class=&quot;text-center mt-4&quot;&gt;This technique is widely used in areas like computer vision, object detection, and image segmentation.&lt;/p&gt;<br>    &lt;/section&gt;<br><br>    &lt;!-- Footer --&gt;<br>    &lt;footer class=&quot;bg-dark text-white text-center py-4&quot;&gt;<br>        &lt;p&gt;&amp;copy; 2024 Edge Detection App by Kunal Chaugule&lt;/p&gt;<br>    &lt;/footer&gt;<br><br>    &lt;!-- Bootstrap JS and dependencies --&gt;<br>    &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.slim.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>2. edge_detection.html (Upload Page):</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Try Edge Detection&lt;/title&gt;<br>    &lt;!-- Bootstrap CSS --&gt;<br>    &lt;link href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;styles.css&#39;) }}&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;!-- Navigation bar --&gt;<br>    &lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-light&quot;&gt;<br>        &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;Edge Detection&lt;/a&gt;<br>        &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#navbarNav&quot; aria-controls=&quot;navbarNav&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;<br>            &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;<br>        &lt;/button&gt;<br>        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNav&quot;&gt;<br>            &lt;ul class=&quot;navbar-nav ml-auto&quot;&gt;<br>                &lt;li class=&quot;nav-item&quot;&gt;<br>                    &lt;a class=&quot;nav-link&quot; href=&quot;/&quot;&gt;Home&lt;/a&gt;<br>                &lt;/li&gt;<br>                &lt;li class=&quot;nav-item&quot;&gt;<br>                    &lt;a class=&quot;nav-link&quot; href=&quot;/edge-detection&quot;&gt;Try Edge Detection&lt;/a&gt;<br>                &lt;/li&gt;<br>            &lt;/ul&gt;<br>        &lt;/div&gt;<br>    &lt;/nav&gt;<br><br>    &lt;!-- Hero Section with Background Image --&gt;<br>    &lt;section class=&quot;hero-section text-center text-white&quot; style=&quot;background-image: url(https://medium.com/&#39;{{%20url_for(&#39;static&#39;,%20filename=&#39;images/banner.jpg&#39;) }}&#39;); background-size: cover; background-position: center; padding: 150px 20px;&quot;&gt;<br>        &lt;h1 class=&quot;display-4&quot;&gt;Try Edge Detection&lt;/h1&gt;<br>        &lt;p class=&quot;lead&quot;&gt;Upload an image to apply edge detection and download the results.&lt;/p&gt;<br>    &lt;/section&gt;<br><br>    &lt;!-- Image Upload Section --&gt;<br>    &lt;section class=&quot;container text-center my-5&quot;&gt;<br>        &lt;h2 class=&quot;mb-4&quot;&gt;Upload Your Image&lt;/h2&gt;<br>        &lt;form action=&quot;/upload&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot; class=&quot;mb-4&quot;&gt;<br>            &lt;div class=&quot;custom-file mb-3&quot;&gt;<br>                &lt;input type=&quot;file&quot; class=&quot;custom-file-input&quot; id=&quot;customFile&quot; name=&quot;file&quot; accept=&quot;image/*&quot; required&gt;<br>                &lt;label class=&quot;custom-file-label&quot; for=&quot;customFile&quot;&gt;Choose file&lt;/label&gt;<br>            &lt;/div&gt;<br>            &lt;button type=&quot;submit&quot; class=&quot;btn btn-lg btn-primary&quot;&gt;Upload and Process&lt;/button&gt;<br>        &lt;/form&gt;<br>    &lt;/section&gt;<br><br>    &lt;!-- Footer --&gt;<br>    &lt;footer class=&quot;bg-dark text-white text-center py-4&quot;&gt;<br>        &lt;p&gt;&amp;copy; 2024 Edge Detection App&lt;/p&gt;<br>    &lt;/footer&gt;<br><br>    &lt;!-- JavaScript to update file input label with file name --&gt;<br>    &lt;script&gt;<br>        // Update the label when a file is selected<br>        document.querySelector(&#39;.custom-file-input&#39;).addEventListener(&#39;change&#39;, function(e) {<br>            var fileName = document.getElementById(&quot;customFile&quot;).files[0].name;<br>            var nextSibling = e.target.nextElementSibling;<br>            nextSibling.innerText = fileName;<br>        });<br>    &lt;/script&gt;<br><br>    &lt;!-- Bootstrap JS and dependencies --&gt;<br>    &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.slim.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>3. display.html (Display Results Page):</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Edge Detection Results&lt;/title&gt;<br>    &lt;!-- Bootstrap CSS --&gt;<br>    &lt;link href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;styles.css&#39;) }}&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;!-- Navigation bar --&gt;<br>    &lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-light&quot;&gt;<br>        &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;Edge Detection&lt;/a&gt;<br>        &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#navbarNav&quot; aria-controls=&quot;navbarNav&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;<br>            &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;<br>        &lt;/button&gt;<br>        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNav&quot;&gt;<br>            &lt;ul class=&quot;navbar-nav ml-auto&quot;&gt;<br>                &lt;li class=&quot;nav-item&quot;&gt;<br>                    &lt;a class=&quot;nav-link&quot; href=&quot;/&quot;&gt;Home&lt;/a&gt;<br>                &lt;/li&gt;<br>                &lt;li class=&quot;nav-item&quot;&gt;<br>                    &lt;a class=&quot;nav-link&quot; href=&quot;/edge-detection&quot;&gt;Try Edge Detection&lt;/a&gt;<br>                &lt;/li&gt;<br>            &lt;/ul&gt;<br>        &lt;/div&gt;<br>    &lt;/nav&gt;<br><br>    &lt;!-- Output Section --&gt;<br>    &lt;section class=&quot;container text-center my-5&quot;&gt;<br>        &lt;h2 class=&quot;mb-4&quot;&gt;Edge Detection Results&lt;/h2&gt;<br>        &lt;div class=&quot;row&quot;&gt;<br>            &lt;!-- Original Image --&gt;<br>            &lt;div class=&quot;col-md-6&quot;&gt;<br>                &lt;h3&gt;Original Image&lt;/h3&gt;<br>                &lt;img src=&quot;{{ url_for(&#39;static&#39;, filename=&#39;images/original.jpg&#39;) }}&quot; class=&quot;img-fluid mb-3&quot; alt=&quot;Original Image&quot;&gt;<br>                &lt;a href=&quot;{{ url_for(&#39;download_file&#39;, filename=&#39;original.jpg&#39;) }}&quot; class=&quot;btn btn-primary&quot;&gt;Download Original&lt;/a&gt;<br>            &lt;/div&gt;<br>            &lt;!-- Processed Image --&gt;<br>            &lt;div class=&quot;col-md-6&quot;&gt;<br>                &lt;h3&gt;Edge Detected Image&lt;/h3&gt;<br>                &lt;img src=&quot;{{ url_for(&#39;static&#39;, filename=&#39;images/edges.jpg&#39;) }}&quot; class=&quot;img-fluid mb-3&quot; alt=&quot;Edge Detected Image&quot;&gt;<br>                &lt;a href=&quot;{{ url_for(&#39;download_file&#39;, filename=&#39;edges.jpg&#39;) }}&quot; class=&quot;btn btn-primary&quot;&gt;Download Edge Detected&lt;/a&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/section&gt;<br><br>    &lt;!-- Footer --&gt;<br>    &lt;footer class=&quot;bg-dark text-white text-center py-4&quot;&gt;<br>        &lt;p&gt;&amp;copy; 2024 Edge Detection App&lt;/p&gt;<br>    &lt;/footer&gt;<br><br>    &lt;!-- Bootstrap JS and dependencies --&gt;<br>    &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.slim.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Step 6: Adding the CSS for styling the website</h3><ol><li>styles.css</li></ol><pre>/* General body styling */<br>body {<br>    font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif;<br>    margin: 0;<br>    padding: 0;<br>    background-color: #f0f2f5;<br>    color: #333;<br>}<br><br>header {<br>    background-color: #0044cc;<br>    color: white;<br>    padding: 40px 20px;<br>    text-align: center;<br>    box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);<br>}<br><br>h1 {<br>    font-size: 3rem;<br>    margin: 0;<br>}<br><br>p {<br>    font-size: 1.2rem;<br>    line-height: 1.6;<br>    margin: 20px 0;<br>    text-align: center;<br>}<br><br>section {<br>    margin: 40px auto;<br>    max-width: 800px;<br>    padding: 20px;<br>    background-color: white;<br>    border-radius: 10px;<br>    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);<br>}<br><br>.how-it-works h2 {<br>    font-size: 2rem;<br>    text-align: center;<br>    margin-bottom: 20px;<br>}<br><br>.how-it-works p, .how-it-works ol {<br>    text-align: justify;<br>}<br><br>ol {<br>    padding-left: 20px;<br>}<br><br>footer {<br>    background-color: #0044cc;<br>    color: white;<br>    padding: 10px;<br>    text-align: center;<br>    position: fixed;<br>    bottom: 0;<br>    width: 100%;<br>}<br><br>.cta {<br>    text-align: center;<br>    margin-top: 50px;<br>}<br><br>.cta .btn {<br>    background-color: #28a745;<br>    color: white;<br>    padding: 15px 30px;<br>    font-size: 1.5rem;<br>    border: none;<br>    border-radius: 10px;<br>    text-decoration: none;<br>    cursor: pointer;<br>    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);<br>}<br><br>.cta .btn:hover {<br>    background-color: #218838;<br>}<br>.hero-section {<br>    background-image: url(https://medium.com/&#39;https://via.placeholder.com/1200x500&#39;); /* Replace with actual image */<br>    background-size: cover;<br>    background-position: center;<br>    padding: 150px 0;<br>}<br><br>footer {<br>    background-color: #222;<br>    color: #fff;<br>}<br><br>h2 {<br>    font-size: 2rem;<br>    font-weight: bold;<br>}<br><br>ul {<br>    list-style: none;<br>    padding-left: 0;<br>}<br><br>ul li::before {<br>    content: &quot;✔&quot;; /* Add custom checkmark icons for each list item */<br>    color: green;<br>    margin-right: 10px;<br>}<br>.hero-section {<br>    background-size: cover;<br>    background-position: center;<br>    padding: 150px 20px;<br>    position: relative;<br>}<br><br>.hero-section::before {<br>    content: &#39;&#39;;<br>    position: absolute;<br>    top: 0;<br>    left: 0;<br>    width: 100%;<br>    height: 100%;<br>    background-color: rgba(0, 0, 0, 0.4); /* Dark transparent overlay */<br>}<br><br>.hero-section h1, .hero-section p, .btn {<br>    position: relative;<br>    z-index: 1;<br>}<br>.btn:hover {<br>    background-color: #0069d9;<br>    transform: scale(1.05);<br>    transition: all 0.3s ease;<br>}</pre><h3>Step 7: Running the App</h3><p>Now that everything is set up, let’s run the Flask app!</p><ol><li>Start the Flask development server:</li></ol><pre>python app.py</pre><p>Open your browser and navigate to:</p><pre>http://127.0.0.1:5000/</pre><h3>Conclusion</h3><p>Congratulations! 🎉 You’ve built your own <strong>Edge Detection Web App</strong> using Python, Flask, and OpenCV! This project gave you hands-on experience with both web development and image processing.</p><p>Feel free to modify the project and add more features, such as trying different image processing techniques or improving the UI.</p><p>Happy coding!</p><h3>Check out the Code on GitHub</h3><p>If you want to check out the full code for this project, it’s available on my GitHub. Feel free to clone the repo and explore the code:</p><p>👉 <a href="https://github.com/kunal0230/edge-detection-web-app">Edge Detection Web App on GitHub</a></p><p>Make sure to give the repository a star ⭐ if you found this tutorial helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3326714be13f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>