<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ opencv - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ opencv - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 21 May 2026 16:11:45 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/opencv/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Use OpenCV and Python for Computer Vision and AI ]]>
                </title>
                <description>
                    <![CDATA[ OpenCV is a popular Python library for real-time computer vision. We just released a new OpenCV course on the freeCodeCamp.org YouTube channel. This course comes directly from the creators of OpenCV and is the perfect course for beginners.  You will ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-opencv-and-python-for-computer-vision-and-ai/</link>
                <guid isPermaLink="false">66b20365a2135cc2539a21a4</guid>
                
                    <category>
                        <![CDATA[ opencv ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Mon, 07 Jun 2021 20:54:41 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/06/opencv.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>OpenCV is a popular Python library for real-time computer vision.</p>
<p>We just released a new OpenCV course on the freeCodeCamp.org YouTube channel. This course comes directly from the creators of OpenCV and is the perfect course for beginners. </p>
<p>You will learn how to use OpenCV for Computer Vision and AI. You will learn and get exposed to a wide range of exciting topics like Image &amp; Video Manipulation, Image Enhancement, Filtering, Edge Detection, Object Detection and Tracking, Face Detection and the OpenCV Deep Learning Module.</p>
<p>At the end of this course there is an interview with Dr. Satya Mallick, the CEO of OpenCV.org. Dr. Mallick shares his views on the many opportunities in the Computer Vision and AI job market.  He gives advice on how to prepare and get hired for a job in AI.</p>
<p>Here are the sections in this course:</p>
<ul>
<li>Module 1: Getting Started with Images </li>
<li>Module 2: Basic Image Manipulation </li>
<li>Module 3: Image Annotation </li>
<li>Module 4: Image Enhancement </li>
<li>Module 5: Accessing the Camera </li>
<li>Module 6: Read and Write Videos </li>
<li>Module 7: Image Filtering and Edge Detection </li>
<li>Module 8: Image Features and Image Alignment</li>
<li>Module 9: Image Stitching and Creating Panoramas </li>
<li>Module 10: High Dynamic Range Imaging (HDR) </li>
<li>Module 11: Object Tracking </li>
<li>Module 12: Face Detection </li>
<li>Module 13: Object Detection </li>
<li>Module 14: Pose Estimation using OpenPose </li>
<li>Interview with OpenCV CEO, Dr. Satya Mallick </li>
</ul>
<p>Watch the course below or <a target="_blank" href="https://www.youtube.com/watch?v=P4Z8_qe2Cu0">on the freeCodeCamp.org YouTube channel</a> (3-hour watch).</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/P4Z8_qe2Cu0" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Python and OpenCV Course –Create Computer Vision Apps in the Cloud ]]>
                </title>
                <description>
                    <![CDATA[ OpenCV is a library of programming functions mainly aimed at real-time computer vision.  We just published a course on the freeCodeCamp.org YouTube channel that will teach you how to use OpenCV in the cloud with Python. Misbah Mohammed created this c... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/create-computer-vision-apps-in-the-cloud-with-opencv-and-python/</link>
                <guid isPermaLink="false">66b201d427569435a9255a9d</guid>
                
                    <category>
                        <![CDATA[ opencv ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Wed, 05 May 2021 21:11:40 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/05/opencvmusk.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>OpenCV is a library of programming functions mainly aimed at real-time computer vision. </p>
<p>We just published a course on the freeCodeCamp.org YouTube channel that will teach you how to use OpenCV in the cloud with Python.</p>
<p>Misbah Mohammed created this course. He has a lot of experience with machine learning and makes it simple to follow along if you already know some Python.</p>
<p>You will learn how to create computer vision applications in the cloud on Google Colab. You will use AI and machine learning.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/opencv.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here are the sections in this video:</p>
<ul>
<li>Lesson 1: Changing color profiles in an image</li>
<li>Image Properties</li>
<li>Lesson 2: Edge Detection</li>
<li>Erosion and Dilation</li>
<li>Lesson 3: Image Manipulation-Noise Removal</li>
<li>Lesson 4: Drawing Shapes and Writing Text on Images</li>
<li>Intermediate Exercise 1: Color Detection</li>
<li>Intermediate Exercise 2: Face Detection</li>
<li>Intermediate Exercise 3: Shape Detection</li>
<li>Project 1: Ball Tracking</li>
<li>Project 2: Face Recognition</li>
</ul>
<p>Watch the full course below or <a target="_blank" href="https://youtu.be/iXNsAYOTzgM">on the freeCodeCamp.org YouTube channel</a> (3 hour watch).</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/iXNsAYOTzgM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn How to Use the OpenCV Computer Vision Library ]]>
                </title>
                <description>
                    <![CDATA[ OpenCV is a cross-platform library that can be used to code real-time computer vision applications. It makes it easier to implement image processing, face detection, and object detection. We've released a full course on the freeCodeCamp.org YouTube c... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/opencv-full-course/</link>
                <guid isPermaLink="false">66b205f1f31aa965000e586d</guid>
                
                    <category>
                        <![CDATA[ opencv ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Wed, 04 Nov 2020 18:07:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/11/opencv.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>OpenCV is a cross-platform library that can be used to code real-time computer vision applications. It makes it easier to implement image processing, face detection, and object detection.</p>
<p>We've released a full course on the freeCodeCamp.org YouTube channel that will help you get started with OpenCV. You will learn how to use it with the Python programming language.</p>
<p>The course was created by Jason Dsouza. Jason has been teaching about deep learning and Python for many years.</p>
<p>The course starts with the basics such as reading images and video, image transformations, and drawing on images. Then it covers more advanced concepts such as color spaces, edge detection, and thresholding. Towards the end, you'll learn to build a Deep Computer Vision model to detect between the characters in "The Simpsons".</p>
<p>Here are the topics covered in this course:</p>
<h3 id="heading-section-1-basics">Section #1 - Basics</h3>
<ul>
<li>Reading Images &amp; Video</li>
<li>Resizing and Rescaling Frames</li>
<li>Drawing Shapes &amp; Putting Text</li>
<li>Essential Functions in OpenCV</li>
<li>Image Transformations</li>
<li>Contour Detection</li>
</ul>
<h3 id="heading-section-2-advanced">Section #2 - Advanced</h3>
<ul>
<li>Color Spaces</li>
<li>Color Channels</li>
<li>Blurring</li>
<li>BITWISE operations</li>
<li>Masking</li>
<li>Histogram Computation</li>
<li>Thresholding/Binarizing Images</li>
<li>Edge Detection</li>
</ul>
<h3 id="heading-section-3-faces">Section #3 - Faces:</h3>
<ul>
<li>Face Detection with Haar Cascades</li>
<li>Face Recognition with OpenCV's built-in recognizer</li>
</ul>
<h3 id="heading-section-4-capstone">Section #4 - Capstone</h3>
<ul>
<li>Deep Computer Vision </li>
</ul>
<p>Watch the full course on <a target="_blank" href="https://www.youtube.com/watch?v=oXlwWbU8l2o">the freeCodeCamp.org YouTube channel</a> (4-hour watch).</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Facial recognition using OpenCV in Java ]]>
                </title>
                <description>
                    <![CDATA[ By Manish Bansal Ever since the Artificial Intelligence boom began — or the iPhone X advertisement featuring the face unlock feature hit TV screens — I’ve wanted to try this technology. However, once I started googling about it, I typically only foun... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/facial-recognition-using-opencv-in-java-92fa40c22f62/</link>
                <guid isPermaLink="false">66c34a3f0f58901a62091766</guid>
                
                    <category>
                        <![CDATA[ Artificial Intelligence ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computer Vision ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Java ]]>
                    </category>
                
                    <category>
                        <![CDATA[ opencv ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 25 Jul 2018 15:29:37 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*fpDngO6lM5pDeIPOOezK1g.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Manish Bansal</p>
<p>Ever since the Artificial Intelligence boom began — or the iPhone X advertisement featuring the face unlock feature hit TV screens — I’ve wanted to try this technology. However, once I started googling about it, I typically only found code examples in Python. And being a Java enthusiast for seven years, I got demotivated seeing that. Therefore, I finally decided to hunt for Java open source libraries for this.</p>
<p>Currently, there are various Java libraries out there. But the most popular one I found was <a target="_blank" href="https://github.com/opencv/opencv">OpenCV</a>.</p>
<p>OpenCV is an open source computer vision library that has tons of modules like object detection, face recognition, and augmented reality. Although this library is written in C++, it also offers battle-tested Java bindings.</p>
<p>However, there is one issue. As part of its software release, it offers only a few modules (with Java bindings) out of the box — and facial recognition is not one of them. Therefore, to use it, you need to manually build it.</p>
<p><strong>Wait! What? Why?</strong></p>
<p>Yes — the reason cited by the OpenCV community is that the modules are not completely stable. Therefore, they are not bundled along with the standard release. Hence, they maintain them in a separate repository <a target="_blank" href="https://github.com/opencv/opencv_contrib">here</a>.</p>
<p>If you have no or very little C++ experience (like me), you must have already started to feel dizzy about building a C++ library yourself. But don’t worry, I am here to hold your hand and walk you through this tedious process. So let’s begin, shall we?</p>
<h3 id="heading-building-opencv-for-java-from-scratch">Building OpenCV for Java from scratch</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/UPSASYdL1mTRl1Y2WO8wo5ORbKIVlJ0SZ4zp" alt="Image" width="800" height="533" loading="lazy">
_“Birds flying around a half-built building and construction site” by [Unsplash](https://unsplash.com/@danist07?utm_source=medium&amp;utm_medium=referral" rel="noopener" target="_blank" title=""&gt;贝莉儿 NG on &lt;a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral" rel="noopener" target="<em>blank" title=")</em></p>
<p>You can find various resources for step by step instructions like <a target="_blank" href="https://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html#install-opencv-3-x-under-windows">this</a>, <a target="_blank" href="https://www.learnopencv.com/install-opencv3-on-windows/">this</a>, and <a target="_blank" href="https://perso.uclouvain.be/allan.barrea/opencv/cmake_config.html">this</a>. However, none of them worked perfectly for me, as one thing or another was missing. The closest I found, which helped me, is <a target="_blank" href="https://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html#install-opencv-3-x-under-linux">this</a> one. However, you do not need to refer to it. You can follow below steps and you will be good.</p>
<p>First, you need to have the below software on your PC. Here, I am building a 64-bit version of the library as I own a 64 bit PC. But you can build it for 32-bit as well.</p>
<p>The required software is:</p>
<ol>
<li><a target="_blank" href="https://cmake.org">Cmake</a> (I used 3.6.0 rc-4 version).</li>
<li><a target="_blank" href="https://ant.apache.org">Ant</a> (used internally for building JAR)</li>
<li>MinGW — W64 GCC-8.1.0</li>
<li><a target="_blank" href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html">64 bit JDK 1.8</a></li>
</ol>
<p><strong>A word about MinGW:</strong> Here, to build this library, we need C++ compilers. You can use Visual Studio tools (VS), which is far better. However, I did not have the luxury to do that, as I built it on my office laptop and VS is licensed software unavailable to Java people here. Therefore, I had to use open source tools, and the best one is MinGW (Minimalist GNU for Windows).</p>
<p>Also, it is very important to use the correct version of MinGW. Download version <a target="_blank" href="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z">x86_64-posix-seh</a>, as there is thread support in this version. I have not tried all other versions. But version <a target="_blank" href="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-win32/sjlj/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.7z">x86_64-win32-sjlj</a> does not work at all.</p>
<p>To give some more perspective, the build is done by the utility called <strong>make</strong> which comes as part of MinGW (bin/mingw32-make.exe). make is a task runner for C++ like “Ant” is for Java. But C++ code and make scripts are very much platform-dependent. Hence, to make the distributables platform-independent, the utility <strong>CMake</strong> is used. CMake generates platform-dependent make scripts.</p>
<h3 id="heading-generating-build-configurations-using-cmake"><strong>Generating build configurations using CMake</strong></h3>
<p><strong>Step 1:</strong> Download the source code zip of both the <a target="_blank" href="https://github.com/opencv/opencv/releases">opencv</a> and <a target="_blank" href="https://github.com/opencv/opencv_contrib/releases">opencv_contrib</a>, and extract them into a directory. Further, create a folder called “build” in the same directory (I created “build_posix” as visible in the screenshots).</p>
<p><strong>Step 2:</strong> Open CMake. Point “where is the source code” to the opencv extracted folder. Further, point “where to build the binaries” to the “build” folder you created.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3w-kaNsw1jy-wgJj27ivlgUpkB3nWbKhmSAg" alt="Image" width="800" height="93" loading="lazy"></p>
<p><strong>Step 3:</strong> Add the 64 bit JDK 1.8 bin folder, the MinGW bin folder, and the Ant bin folder to the “PATH” environment variables. This is important, as CMake will look in the environment variables for configuration. If this is not done, then we will have to configure CMake manually in step 5.</p>
<p><strong>In case you have multiple JDKs in your system and you already have some different JDK in “PATH” &amp; you don’t want to add JDK 1.8 in “PATH”, you can skip this. But do configure it manually in step 5.</strong></p>
<p><strong>Step 4:</strong> Press the “Configure” button and select “ MinGw Makefiles” and “finish”. After this, CMake will start configuring your project. It will take a while and, after it finishes configuring, it will show the current available configurations.</p>
<p>In case you are wondering if the configurations generated for you are correct, you can refer to the logs which got generated for me <a target="_blank" href="https://pastebin.com/50rtPkt6">here</a> and compare.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1yaCLCiHsbLeyhIyjrWmIfMJfH2VO0bXcdk9" alt="Image" width="515" height="366" loading="lazy"></p>
<p><strong>Step 5:</strong> Now comes the most important part — changing the configurations. First, click the checkboxes “Grouped” and “Advanced” to organize the configurations.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/HNOpUBXPSjKz6lJcJiTQcZxlxLPWVRSD6yKR" alt="Image" width="644" height="42" loading="lazy"></p>
<ul>
<li>Verify that ANT_EXECUTABLE (search “ANT_EXECUTABLE” in the search box) and all five “JAVA” configurations are pointing to the 64-bit JDK 1.8. If Step 3 was done properly, then this will be correct. Otherwise, correct them.</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zKNLlpIu8mRydVeelgHNLs4CevTolRnHxTrP" alt="Image" width="800" height="201" loading="lazy"></p>
<ul>
<li>Un-check Python (search “Python”) related check boxes under “BUILD” and “INSTALL” groups as we don’t need Python builds.</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zXNIv3AOYlE5jS7KKgBm3Gkp7rBZA2PfrGkS" alt="Image" width="705" height="280" loading="lazy"></p>
<ul>
<li>Disable “WITH_MSMF” and “WITH_IPP &amp; WITH_TBB”. These libs are only available for VS.</li>
<li>Edit “OPENCV_EXTRA_MODULES_PATH” under “OPENCV” group and set it to the “modules” folder under the “opencv_contrib” source folder you extracted earlier.</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Vxz1vQr2-CoYNCn2HMyrkN0FjuI6pvTEZlOm" alt="Image" width="800" height="273" loading="lazy"></p>
<p>After this, press the “Configure” button again. This will do the final configurations. You can refer to the logs which got generated for me <a target="_blank" href="https://pastebin.com/B71iVjQT">here</a>.</p>
<p><strong>Note</strong>: Make sure to compare your “Configure” logs generated with the one I shared in pastebin above. If you find some <strong>major</strong> difference, then first try correcting your configurations and press “Configure” again. Otherwise, there are chances that your build will fail and that it will be more difficult to debug.</p>
<p><strong>Step 6:</strong> After this, press “Generate”. It will take few seconds and then close CMake.</p>
<h3 id="heading-compiling-opencv"><strong>Compiling OpenCV</strong></h3>
<p>Now, if all the configurations generated above are correct, this task will be a breeze (of 2–3 hours!). Just open the command prompt, go to the “build” folder, and execute the command below.</p>
<pre><code>mingw32-make.exe  -j5 &gt; buildLogs.txt
</code></pre><p>Here, <code>-j5</code> is added, which instructs the make utility to run five jobs in parallel. This will make your build faster, at least theoretically.</p>
<p>Further, do not forget to push the logs to a text file. These might get too big, in which case your command prompt window might truncate it. You need them in case compilation fails. You can refer to the compilation logs generated in my case <a target="_blank" href="https://pastebin.com/r7RSXSDm">here</a>.</p>
<p><strong>Note</strong>: The order of log statements might not be the same for you, as the build is happening in five parallel threads.</p>
<p>Once the build is over, you can check the “bin” and “lib” folders inside your “build” directory. Inside “bin”, you will have all your opencv<em>.exe’s and libopencv</em>.dll’s and your compiled JAR. Further, “lib” will have your main dll (libopencv_javaxxx.dll) along with some more dependent files.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/mIygBsHnPC5flruoL8nFf3yEAF7P96QMYh6l" alt="Image" width="695" height="413" loading="lazy">
<em>“bin” folder after successful compilation</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ORUBTFMX5NhE0AjRxAfiLfoTAW4o3OnDR1VX" alt="Image" width="613" height="377" loading="lazy">
<em>“lib” folder after successful compilation</em></p>
<h3 id="heading-hands-on-with-opencv-face-recognition-api">Hands on with OpenCV face recognition API</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/e3jIAxwvVbVXoR2L0sOeAUQ352nzncBolZYX" alt="Image" width="800" height="548" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral" rel="noopener" target="_blank" title=""&gt;rawpixel on &lt;a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral" rel="noopener" target="<em>blank" title=")</em></p>
<p>Now that you have built the library, you first need to set up the environment variables, as well as the user library, in Eclipse.</p>
<ol>
<li>Create a variable OPENCV_JAVA_BIN and point it to the “bin” folder generated inside your “build” directory.</li>
<li>Create OPENCV_JAVA_LIB and point it to the “lib” folder generated inside your “build” directory.</li>
<li>Append both the above variables to the “PATH” variable.</li>
<li>Open up your Eclipse and create a new user library which you will be using for your face recognition project. Go to “Window” &gt; “Preferenc<strong>es</strong>”. From the menu, navigate under “Java” &gt; “Build Path” &gt; “User Libraries” and choose “New…” . Enter a name for the library — for example, opencv — and select the newly created user library. Choose “Add External JARs…” , and browse to select “opencv-3xx.jar” from your computer.</li>
</ol>
<p>After this, there is <strong>no need</strong> to link the native library, as this was added to your “path” variables in Step 3.</p>
<p>Once you are done with this setup, you can clone my Git repository from <a target="_blank" href="https://github.com/manishbansal8843/Opencv-facerec-java">here</a> and import the project into your Eclipse workspace. Further, you will need to add JDK 1.8 as well as the opencv user library (just created above) to this project. Once you are done, you will be ready to test your newly built OpenCV library.</p>
<p>As of this writing, there are three programs in this project.</p>
<ul>
<li><strong>HelloWorld</strong>: you can run this to test if your OpenCV library setup is ok. If this does not work properly, you need to sort this out <strong>first</strong>. The only issues you will encounter at this point will be related to system environment variables or user library setup.</li>
<li><strong>FaceDetection</strong>: you can use this to test the face detection module. It is a different module from face recognition. This is a module which gets shipped along with standard release of OpenCV. As of this writing, we can provide an image as an input to the program, and it will detect all the faces inside the image. The output image has green rectangles drawn on all the detected faces.</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/TzyLTh-v5ie9SpRVJH2rHyK3OPSpSHpvYWFJ" alt="Image" width="714" height="1024" loading="lazy">
<em>Input image for Face Detection program</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/csQYwDeXAiOBbv6AWCOxhlLMvqZ1wyaf0GRz" alt="Image" width="714" height="1024" loading="lazy">
<em>Output image of face detection program</em></p>
<ul>
<li><p><strong>FaceRecognition:</strong> the OpenCV facerec module includes three algorithms:</p>
</li>
<li><p>Eigenfaces</p>
</li>
<li>Fisherfaces</li>
<li>Local Binary Patterns Histograms.</li>
</ul>
<p>For technical details on all these algorithms, you can refer <a target="_blank" href="https://docs.opencv.org/2.4/modules/contrib/doc/facerec/facerec_tutorial.html">this</a> official article. For demonstration purposes, I will show you how to use the Eigenfaces algorithm.</p>
<p>First, you need to <a target="_blank" href="http://www.cl.cam.ac.uk/Research/DTG/attarchive/pub/data/att_faces.zip">download</a> training data from the face database. This data contains ten different images for each of 40 distinct subjects (400 images). For some subjects, the images were taken at different times, varying the lighting, facial expressions (open / closed eyes, smiling / not smiling), and facial details (glasses / no glasses). After extracting them on your computer, you need to prepare a .csv file containing the path of each image, along with their corresponding label.</p>
<p>To make it easy, I have one TrainingData.txt in my Git repository. However, you need to edit the file and alter the paths of images as per your computer directory location.</p>
<p><strong>Note</strong>: the downloaded face database contains images in .pgm format. This format is <strong>not supported</strong> by Windows. To actually convert them to .jpg, I added PGMToJPGConverter to my repository. You can use to this to convert the images and have an actual look at the training data.</p>
<p>After this, you can run the face recognition program. Below are the steps performed in the program:</p>
<ol>
<li>OpenCV library is <a target="_blank" href="https://github.com/manishbansal8843/Opencv-facerec-java/blob/0d56b0a369e33a09e8af52613dbd79afdccad397/src/com/demo/facerecognition/FaceRecognitionEigenFaces.java#L20">loaded</a> as usual.</li>
<li>The .csv file is read, and two ArrayList(s) are <a target="_blank" href="https://github.com/manishbansal8843/Opencv-facerec-java/blob/0d56b0a369e33a09e8af52613dbd79afdccad397/src/com/demo/facerecognition/FaceRecognitionEigenFaces.java#L24">created</a>. One for the matrix of images and other for their corresponding labels.</li>
<li>Out of the 400 input images, the last entry in the list data structure is <a target="_blank" href="https://github.com/manishbansal8843/Opencv-facerec-java/blob/0d56b0a369e33a09e8af52613dbd79afdccad397/src/com/demo/facerecognition/FaceRecognitionEigenFaces.java#L26-L29">removed and saved</a> for testing the trained model later.</li>
<li>After that, the remaining 399 images are used for <a target="_blank" href="https://github.com/manishbansal8843/Opencv-facerec-java/blob/0d56b0a369e33a09e8af52613dbd79afdccad397/src/com/demo/facerecognition/FaceRecognitionEigenFaces.java#L34">training</a> the Eigenfaces algorithm.</li>
<li>Once training is complete, the model is asked to <a target="_blank" href="https://github.com/manishbansal8843/Opencv-facerec-java/blob/0d56b0a369e33a09e8af52613dbd79afdccad397/src/com/demo/facerecognition/FaceRecognitionEigenFaces.java#L39">predict</a> the label of the image we removed in step 3.</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3h2mUCWnXzKQeFfIMJpFMIGxLoAM80Bp6tP0" alt="Image" width="701" height="145" loading="lazy">
<em>Output of Face Recognition Program</em></p>
<p>Here, we can observe that the algorithm is able to predict the label of our test subject with a confidence value of 1807. The lower the value, the better the prediction. Similarly, you can perform this exercise with two other algorithms. The C++ code can be downloaded from <a target="_blank" href="https://docs.opencv.org/2.4/modules/contrib/doc/facerec/facerec_tutorial.html#fisherfaces-in-opencv">here</a> and <a target="_blank" href="https://docs.opencv.org/2.4/modules/contrib/doc/facerec/facerec_tutorial.html#local-binary-patterns-histograms-in-opencv">here</a>.</p>
<blockquote>
<p><strong>Update (27th Dec 2018)</strong>: In case you find building the openCV java bindings painful, then i have a good news for you. Recently, I have found an easier way to get all the openCV dependencies for java. For complete details, please refer my <a target="_blank" href="https://medium.com/@manishbansal8843/face-recognition-using-opencv-in-java-updated-8fc329863e52">another article</a>.</p>
</blockquote>
<p><strong>Congratulations</strong>!! ? You made it to the end. And if you liked ?this article, hit that clap button below ?. It means a lot to me and it helps other people see the story.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to use image preprocessing to improve the accuracy of Tesseract ]]>
                </title>
                <description>
                    <![CDATA[ By Berk Kaan Kuguoglu Previously, on How to get started with Tesseract, I gave you a practical quick-start tutorial on Tesseract using Python. It is a pretty simple overview, but it should help you get started with Tesseract and clear some hurdles th... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/getting-started-with-tesseract-part-ii-f7f9a0899b3f/</link>
                <guid isPermaLink="false">66c34b625ced6d98e4bd32e0</guid>
                
                    <category>
                        <![CDATA[ OCR  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ opencv ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tesseract ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 06 Jun 2018 13:25:41 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*iZwvUAtgcOAVgjO23Hd2ig.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Berk Kaan Kuguoglu</p>
<p>Previously, on <a target="_blank" href="https://medium.com/@bkaankuguoglu/getting-started-with-tesseract-part-i-2a6a6b1cf75e">How to get started with Tesseract</a>, I gave you a practical quick-start tutorial on Tesseract using Python. It is a pretty simple overview, but it should help you get started with Tesseract and clear some hurdles that I faced when I was in your shoes. Now, I’m keen on showing you a few more tricks and stuff you can do with Tesseract and OpenCV to improve your overall accuracy.</p>
<h3 id="heading-where-did-we-leave-off-last-time">Where did we leave off last time?</h3>
<p>In <a target="_blank" href="https://medium.com/@bkaankuguoglu/getting-started-with-tesseract-part-i-2a6a6b1cf75e">the previous story</a>, I didn’t bother going into details for the most part. But if you liked the first story, here comes the sequel! So where did we leave off?</p>
<p>Ah, we had a brief overview of rescaling, noise removal, and binarization. Now, it’s time to get down to details and show you a few settings you can play with.</p>
<h3 id="heading-rescaling">Rescaling</h3>
<p>The images that are rescaled are either shrunk or enlarged. If you’re interested in shrinking your image, <strong>INTER_AREA</strong> is the way to go for you. (Btw, the parameters <em>fx</em> and <em>fy</em> denote the scaling factor in the function below.)</p>
<pre><code>img = cv2.resize(img, None, fx=<span class="hljs-number">0.5</span>, fy=<span class="hljs-number">0.5</span>, interpolation=cv2.INTER_AREA)
</code></pre><p>On the other hand, as in most cases, you may need to scale your image to a larger size to recognize small characters. In this case, <strong>INTER_CUBIC</strong> generally performs better than other alternatives, though it’s also slower than others.</p>
<pre><code>img = cv2.resize(img, None, fx=<span class="hljs-number">2</span>, fy=<span class="hljs-number">2</span>, interpolation=cv2.INTER_CUBIC)
</code></pre><p>If you’d like to trade off some of your image quality for faster performance, you may want to try <strong>INTER_LINEAR</strong> for enlarging images.</p>
<pre><code>img = cv2.resize(img, None, fx=<span class="hljs-number">2</span>, fy=<span class="hljs-number">2</span>, interpolation=cv2.INTER_LINEAR)
</code></pre><h3 id="heading-blurring"><strong>Blurring</strong></h3>
<p>It’s worth mentioning that there are a few blur filters available in the <a target="_blank" href="https://docs.opencv.org/3.4.0/d4/d13/tutorial_py_filtering.html">OpenCV library</a>. Image blurring is usually achieved by convolving the image with a low-pass filter kernel. While filters are usually used to blur the image or to reduce noise, there are a few differences between them.</p>
<h4 id="heading-1-averaging">1. Averaging</h4>
<p>After convolving an image with a normalized box filter, this simply takes the average of all the pixels under the kernel area and replaces the central element. It’s pretty self-explanatory, I guess.</p>
<pre><code>img = cv.blur(img,(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>))
</code></pre><h4 id="heading-2-gaussian-blurring">2. Gaussian blurring</h4>
<p>This works in a similar fashion to Averaging, but it uses Gaussian kernel, instead of a normalized box filter, for convolution. Here, the dimensions of the kernel and standard deviations in both directions can be determined independently. Gaussian blurring is very useful for removing — guess what? — gaussian noise from the image. On the contrary, gaussian blurring does not preserve the edges in the input.</p>
<pre><code>img = cv2.GaussianBlur(img, (<span class="hljs-number">5</span>, <span class="hljs-number">5</span>), <span class="hljs-number">0</span>)
</code></pre><h4 id="heading-3-median-blurring">3. Median blurring</h4>
<p>The central element in the kernel area is replaced with the median of all the pixels under the kernel. Particularly, this outperforms other blurring methods in removing salt-and-pepper noise in the images.</p>
<p>Median blurring is a non-linear filter. Unlike linear filters, median blurring replaces the pixel values with the median value available in the neighborhood values. So, median blurring preserves edges as the median value must be the value of one of neighboring pixels.</p>
<pre><code>img = cv2.medianBlur(img, <span class="hljs-number">3</span>)
</code></pre><h4 id="heading-4-bilateral-filtering">4. Bilateral filtering</h4>
<p>Speaking of keeping edges sharp, bilateral filtering is quite useful for removing the noise without smoothing the edges. Similar to gaussian blurring, bilateral filtering also uses a gaussian filter to find the gaussian weighted average in the neighborhood. However, it also takes pixel difference into account while blurring the nearby pixels.</p>
<p>Thus, it ensures only those pixels with similar intensity to the central pixel are blurred, whereas the pixels with distinct pixel values are not blurred. In doing so, the edges that have larger intensity variation, so-called edges, are preserved.</p>
<pre><code>img = cv.bilateralFilter(img,<span class="hljs-number">9</span>,<span class="hljs-number">75</span>,<span class="hljs-number">75</span>)
</code></pre><p>Overall, if you are interested in preserving the edges, go with median blurring or bilateral filtering. On the contrary, gaussian blurring is likely to be faster than median blurring. Due to its computational complexity, bilateral filtering is the slowest of all methods.</p>
<p>Again, you do you.</p>
<h3 id="heading-image-thresholding">Image Thresholding</h3>
<p>There’s not a single image thresholding method that fits all types of documents. In reality, all filters perform differently on varying images. For instance, while some filters successfully binarize some images, they may fail to binarize others. Likewise, some filters may work well with those images that other filters cannot binarize well.</p>
<p>I’ll try to cover the basics here, though I do recommend that you read the official documentation of <a target="_blank" href="https://docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html">OpenCV on Image Thresholding</a> for more information and the theory behind it.</p>
<h4 id="heading-1-simple-threshold">1. Simple Threshold</h4>
<p>You might recall a friend of yours giving you some advice about your life by saying “things are not always black and white”. Well, for a simple threshold, things are pretty straight-forward.</p>
<pre><code>cv.threshold(img,<span class="hljs-number">127</span>,<span class="hljs-number">255</span>,cv.THRESH_BINARY)
</code></pre><p>First, you pick a threshold value, say 127. If the pixel value is greater than the threshold, it becomes black. If less, it becomes white. OpenCV provides us with different types of thresholding methods that can be passed as the fourth parameter. I often use binary threshold for most tasks, but for other thresholding methods you may visit <a target="_blank" href="https://docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html">the official documentation.</a></p>
<h4 id="heading-2-adaptive-threshold">2. Adaptive Threshold</h4>
<p>Rather than setting a one global threshold value, we let the algorithm calculate the threshold for small regions of the image. Thus, we end up having various threshold values for different regions of the image, which is great!</p>
<pre><code>cv2.adaptiveThreshold(img, <span class="hljs-number">255</span>, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, <span class="hljs-number">31</span>, <span class="hljs-number">2</span>)
</code></pre><p>There are two adaptive methods for calculating the threshold value. While <strong>Adaptive Thresh Mean</strong> returns the mean of the neighborhood area, <strong>Adaptive Gaussian Mean</strong> calculates the weighted sum of the neighborhood values.</p>
<p>We’ve got two more parameters that determine the size of the neighborhood area and the constant value that is subtracted from the result: the fifth and sixth parameters, respectively.</p>
<h4 id="heading-3-otsus-threshold">3. Otsu’s Threshold</h4>
<p>This method particularly works well with <strong>bimodal images</strong>, which is an image whose histogram has two peaks. If this is the case, we might be keen on picking a threshold value between these peaks. This is what Otsu’s Binarization actually does, though.</p>
<pre><code>cv2.threshold(img, <span class="hljs-number">0</span>, <span class="hljs-number">255</span>, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[<span class="hljs-number">1</span>]
</code></pre><p>It’s pretty useful for some cases. But it may fail to binarize images that are not bimodal. So, please take this filter with a grain of salt.</p>
<h4 id="heading-types-of-thresholding">Types of thresholding</h4>
<p>You might have already noticed there is a parameter, or in some cases a combination of a few parameters, that are passed as arguments to determine the type of thresholding, such as THRESH_BINARY. I’m not going into the detail here now, as it is explained clearly in <a target="_blank" href="https://docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html">the official documentation</a>.</p>
<h3 id="heading-what-next">What next?</h3>
<p>So far, we’ve discussed some of the techniques of image pre-processing. You might wonder when exactly you’re going to get your hands dirty. Well, the time has come. Before you get back to your favorite Python IDE — mine is <a target="_blank" href="https://www.jetbrains.com/pycharm/">PyCharm</a>, btw — I’m going to show you few lines of code that will save you some time while trying to find which combination of filters and image manipulations work well with your documents.</p>
<p>Let’s start by defining a switcher function that holds a few combinations of thresholding filters and blurring methods. Once you get the idea, you could also add more filters, incorporating other image pre-processing methods like rescaling into your filter set.</p>
<p>Here I’ve created 20 different combinations of image thresholding methods, blurring methods, and kernel sizes. The switcher function, _apply<em>threshold</em>, takes two arguments, namely OpenCV image and an integer that denotes the filter. Likewise, since this function returns the OpenCV image as a result, it could easily be integrated into our _get<em>string</em> function from the previous post.</p>
<pre><code>def apply_threshold(img, argument):    switcher = {        <span class="hljs-number">1</span>: cv2.threshold(cv2.GaussianBlur(img, (<span class="hljs-number">9</span>, <span class="hljs-number">9</span>), <span class="hljs-number">0</span>), <span class="hljs-number">0</span>, <span class="hljs-number">255</span>, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[<span class="hljs-number">1</span>],        <span class="hljs-number">2</span>: cv2.threshold(cv2.GaussianBlur(img, (<span class="hljs-number">7</span>, <span class="hljs-number">7</span>), <span class="hljs-number">0</span>), <span class="hljs-number">0</span>, <span class="hljs-number">255</span>, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[<span class="hljs-number">1</span>],        <span class="hljs-number">3</span>: cv2.threshold(cv2.GaussianBlur(img, (<span class="hljs-number">5</span>, <span class="hljs-number">5</span>), <span class="hljs-number">0</span>), <span class="hljs-number">0</span>, <span class="hljs-number">255</span>, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[<span class="hljs-number">1</span>],
</code></pre><pre><code>                              ...
</code></pre><pre><code>        <span class="hljs-number">18</span>: cv2.adaptiveThreshold(cv2.medianBlur(img, <span class="hljs-number">7</span>), <span class="hljs-number">255</span>, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, <span class="hljs-number">31</span>, <span class="hljs-number">2</span>),        <span class="hljs-number">19</span>: cv2.adaptiveThreshold(cv2.medianBlur(img, <span class="hljs-number">5</span>), <span class="hljs-number">255</span>, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, <span class="hljs-number">31</span>, <span class="hljs-number">2</span>),        <span class="hljs-number">20</span>: cv2.adaptiveThreshold(cv2.medianBlur(img, <span class="hljs-number">3</span>), <span class="hljs-number">255</span>, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, <span class="hljs-number">31</span>, <span class="hljs-number">2</span>)    }    <span class="hljs-keyword">return</span> switcher.get(argument, <span class="hljs-string">"Invalid method"</span>)
</code></pre><p>And, here it comes.</p>
<pre><code>def get_string(img_path, method):    # Read image using opencv    img = cv2.imread(img_path)    # Extract the file name without the file extension    file_name = os.path.basename(img_path).split(<span class="hljs-string">'.'</span>)[<span class="hljs-number">0</span>]    file_name = file_name.split()[<span class="hljs-number">0</span>]    # Create a directory <span class="hljs-keyword">for</span> outputs    output_path = os.path.join(output_dir, file_name)    <span class="hljs-keyword">if</span> not os.path.exists(output_path):        os.makedirs(output_path)
</code></pre><pre><code>    # Rescale the image, <span class="hljs-keyword">if</span> needed.    img = cv2.resize(img, None, fx=<span class="hljs-number">1.5</span>, fy=<span class="hljs-number">1.5</span>, interpolation=cv2.INTER_CUBIC)
</code></pre><pre><code>    # Convert to gray    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)    # Apply dilation and erosion to remove some noise    kernel = np.ones((<span class="hljs-number">1</span>, <span class="hljs-number">1</span>), np.uint8)    img = cv2.dilate(img, kernel, iterations=<span class="hljs-number">1</span>)    img = cv2.erode(img, kernel, iterations=<span class="hljs-number">1</span>)
</code></pre><pre><code>    # Apply threshold to get image <span class="hljs-keyword">with</span> only black and white    img = apply_threshold(img, method)
</code></pre><pre><code>    # Save the filtered image <span class="hljs-keyword">in</span> the output directory    save_path = os.path.join(output_path, file_name + <span class="hljs-string">"_filter_"</span> + str(method) + <span class="hljs-string">".jpg"</span>)    cv2.imwrite(save_path, img)    # Recognize text <span class="hljs-keyword">with</span> tesseract <span class="hljs-keyword">for</span> python    result = pytesseract.image_to_string(img, lang=<span class="hljs-string">"eng"</span>)
</code></pre><pre><code>    <span class="hljs-keyword">return</span> result
</code></pre><h3 id="heading-last-words">Last words</h3>
<p>Now, all we need to do is to write a simple for loop that iterates over the input directory to collect images and applies each filter on the images gathered. I prefer to use <em>glob</em>, or <em>os</em>, for collecting images from directories, and <em>argparse</em> for passing arguments via terminal, like any other sane person would do.</p>
<p>Here I’ve done pretty much the same thing as in my <a target="_blank" href="https://gist.github.com/bkaankuguoglu/111f9f5e0c30b5f57d7c5338d6dcb6fc">gist</a>, if you’d like have a look at it. However, feel free to use the tools you feel comfortable with.</p>
<p>So far, I’ve tried to cover a few useful image pre-processing concepts and implementations, though it’s probably just the tip of the iceberg. I don’t know how much “leisure time” I’m going to have in the upcoming weeks, so, I can’t give you a specific time frame for publishing my next post. However, I’m considering adding at least one more part to this series that explains a few things I left out, such as rotation and de-skewing on images.</p>
<p>Until then, best bet is to just keep your wits about you and continue to look for signs.<a target="_blank" href="https://www.youtube.com/watch?v=B_CHjYoqPUU">*</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How you can get started with Tesseract ]]>
                </title>
                <description>
                    <![CDATA[ By Berk Kaan Kuguoglu It’s far from a secret that Tesseract is not an all-in-one OCR tool that recognizes all sort of texts and drawings. In fact, this couldn’t be further from the truth. If this was a secret, I’ve already spoiled it and it’s already... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/getting-started-with-tesseract-part-i-2a6a6b1cf75e/</link>
                <guid isPermaLink="false">66c34b604f7405e6476b01c7</guid>
                
                    <category>
                        <![CDATA[ OCR  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ opencv ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tesseract ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tutorial ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 05 Jun 2018 18:42:00 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*pv8wGtNSz5Xe5OCrOIJxyw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Berk Kaan Kuguoglu</p>
<p>It’s far from a secret that Tesseract is not an all-in-one OCR tool that recognizes all sort of texts and drawings. In fact, this couldn’t be further from the truth. If this was a secret, I’ve already spoiled it and it’s already too late to go back anyway. So, why not dive deep into Tesseract and share few tips and tricks that could improve your results?</p>
<h3 id="heading-i-love-free-stuff">I love free stuff!</h3>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
