

{"id":116520,"date":"2024-03-04T18:00:21","date_gmt":"2024-03-04T12:30:21","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=116520"},"modified":"2026-06-01T12:21:53","modified_gmt":"2026-06-01T06:51:53","slug":"document-scanner-using-opencv","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/","title":{"rendered":"OpenCV Project &#8211; Document Scanner"},"content":{"rendered":"<p>Get ready to create your own document scanner using OpenCV and Python! This project will walk you through the important stages of scanning, from capturing document images to enhancing their quality.<\/p>\n<p>In this OpenCV Document Scanner Project, we&#8217;ll cover document detection and perspective correction. With the power of OpenCV and Python, you&#8217;ll develop a reliable document scanner. Let&#8217;s dive in and unlock the potential of document scanning using OpenCV and Python.<\/p>\n<h2>Perspective Transform<\/h2>\n<p>Perspective transformation is a method used in document scanning to correct distortion and obtain rectangular representation of the document. It adjusts the image perspective, making it appear as if the document is viewed from a straight-on angle. By applying geometric transformations, such as rotation and scaling, perspective transformation ensures accurate and visually appealing scanned documents. We are importing this perspective_transform from transform.py script.<\/p>\n<h3>Prerequisites For Document Scanner Using OpenCV<\/h3>\n<p>Understanding of the Python programming language and knowledge of the OpenCV library is required. Apart from this, the following system requirements are needed.<\/p>\n<p>1. Python 3.7 and above<br \/>\n2. Any Python editor (VS code, Pycharm, etc.)<\/p>\n<h3>Download OpenCV Document Scanner Project<\/h3>\n<p>Please download the source code of OpenCV Document Scanner Project:<a href=\"https:\/\/drive.google.com\/file\/d\/1I-CSfvvJqz5LDZEeTi-oNMFYSjs0Va9Y\/view?usp=drive_link\"><strong> OpenCV<\/strong> <strong>Document Scanner Project Code.<\/strong><\/a><\/p>\n<h3>Installation<\/h3>\n<p>Open windows cmd as administrator<\/p>\n<p>1. Run the following command to install the opencv library.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install opencv-python<\/pre>\n<h3>Let\u2019s Implement It<\/h3>\n<p>To make your document scanner follow the below steps.<\/p>\n<p>1. First import all the libraries and perspective_transform from transform.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2\r\nimport numpy as np\r\nfrom transform import perspective_transform<\/pre>\n<p>2. Define the function scan_document which will take window size as a parameter.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def Scan_Document(window_size, file_path=None):<\/pre>\n<p>3. This will open the camera. Here I am using an external webcam. If you want to use an integrated camera then replace 1 by 0.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if file_path is None:\r\n        cap = cv2.VideoCapture(1)\r\n else:\r\n        cap = cv2.VideoCapture(file_path)<\/pre>\n<p>4. Here we are initializing some flag variables.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">save_image = False  \r\nscan_document = None \r\nsave_counter = 1<\/pre>\n<p>5. Start while loop.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">while True:<\/pre>\n<p>6. Here we are reading camera input. ret variable stores whether frames are successfully captured or not. Captured frames are stored in frame variable.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ret, frame = cap.read()<\/pre>\n<p>7. It checks whether frames are captured successfully.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if ret:<\/pre>\n<p>8. It converts the image to Gray, blurs it, detects edges to highlight shape boundaries, identifies shapes through contours, selects the five largest contours based on size, and sets a variable called &#8220;scan_document&#8221; to None.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\r\nBlurred = cv2.GaussianBlur(Gray, (5, 5), 0)\r\nEdges = cv2.Canny(Blurred, 50, 150)\r\ncontours, _ = cv2.findContours(Edges.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)\r\ncontours = sorted(contours, key=cv2.contourArea, reverse=True)[:5]\r\nscan_document = None<\/pre>\n<p><strong> Output of this step<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/gray-shape-boundaries-identifies-shapes.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132191 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/gray-shape-boundaries-identifies-shapes.webp\" alt=\"gray shape boundaries identifies shapes\" width=\"960\" height=\"756\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/blur-shape-boundaries-identifies-shapes.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132192 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/blur-shape-boundaries-identifies-shapes.webp\" alt=\"blur shape boundaries identifies shapes\" width=\"960\" height=\"748\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/edges-shape-boundaries-identifies-shapes.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132193 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/edges-shape-boundaries-identifies-shapes.webp\" alt=\"edges shape boundaries identifies shapes\" width=\"960\" height=\"760\" \/><\/a><\/p>\n<p>9. It checks each contour found in the previous step, calculates the perimeter of each contour and approximates it with a simpler polygon. If an approximated polygon has four sides (a quadrilateral), it assigns it to the variable &#8220;scan_document&#8221; and stops further iteration.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">for contour in contours:\r\n                perimeter = cv2.arcLength(contour, True)\r\n                approx = cv2.approxPolyDP(contour, 0.02 * perimeter, closed=True)\r\n                if len(approx) == 4:\r\n                    scan_document = approx\r\n                    break<\/pre>\n<p>10. If a quadrilateral shape is found, the code adjusts the shape into a 4*2 matrix. It then transforms the original image based on this shape, resulting in a modified image called &#8220;wrap.&#8221; Furthermore, the code generates two resized versions of the modified and original images using a specific window size.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if scan_document is not None:\r\n                scan_document = scan_document.reshape(4, 2)\r\n                wrap= perspective_transform(frame, scan_document)\r\n                resized1 = cv2.resize(wrap, window_size)\r\n                resized2 = cv2.resize(frame, window_size)<\/pre>\n<p>11. It shows the scanned document in the \u201cDataFlair\u201d window and original document in the \u201cOriginal Document\u201d window.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cv2.imshow(\"DataFlair\", resized1)\r\ncv2.imshow(\"Original Document\", resized2)<\/pre>\n<p>12. It saves the scanned document as an image file. When the save_image flag is set to True, the code generates a unique file name for the document and saves the transformed image as a JPEG file. It then increments a counter for future saves, displays a message confirming the save, and resets variables to continue scanning. This feature allows users to save the document.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if save_image:\r\n       file_name = f\"scanned_document_{save_counter}.jpg\"\r\n       cv2.imwrite(file_name, warped)\r\n       print(f\"Scanned document {save_counter} saved as {file_name}\")\r\n       save_counter += 1\r\n       save_image = False\r\n       scan_document = None<\/pre>\n<p>13. If the user presses key \u2018q\u2019, the program will stop executing and if the user presses \u2018s\u2019 key then the scanned document will be saved in the folder.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if cv2.waitKey(1) == ord('q'):\r\n           break\r\nelif cv2.waitKey(1) == ord('s'):\r\n            save_image = True<\/pre>\n<p>14. Once the program stops, it releases all the resources occupied by the program and closes all the windows.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cap.release()\r\ncv2.destroyAllWindows()<\/pre>\n<h3>OpenCV Document Scanner Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/once-the-program-stops.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132195 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/once-the-program-stops.webp\" alt=\"once the program stops\" width=\"1920\" height=\"1005\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/once-the-program-stops-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132196 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/once-the-program-stops-output.webp\" alt=\"once the program stops output\" width=\"1920\" height=\"1008\" \/><\/a><\/p>\n<h3>Morphological Operations in Document Scanner<\/h3>\n<p>Morphological operations in image processing are like digital tools that help shape and refine the objects in a picture. They smooth the image to reduce noise and highlight important edges and boundaries.<\/p>\n<p>This document scanner incorporates various morphological operations such as gray color conversion, Gaussian blur, and edge detection. These operations help to enhance image quality and reduce noise. These operations play a crucial role in transforming the document into a clear, readable form by refining its structure and eliminating unwanted artefacts.<\/p>\n<p>1. Gray color scale conversion.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)<\/pre>\n<p><strong> Output of this step<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/gray-color-scale-conversion.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132198 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/gray-color-scale-conversion.webp\" alt=\"gray color scale conversion\" width=\"960\" height=\"756\" \/><\/a><\/p>\n<p>2. Blurring the image.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Blurred = cv2.GaussianBlur(Gray, (5, 5), 0)<\/pre>\n<p><strong> Output of this step<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/blurring-the-image.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132199 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/blurring-the-image.webp\" alt=\"blurring the image\" width=\"960\" height=\"748\" \/><\/a><\/p>\n<p>3. Extracting edges from an image.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Edges = cv2.Canny(Blurred, 50, 150)<\/pre>\n<p><strong> Output of this step<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/extracting-edges.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132200 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/extracting-edges.webp\" alt=\"extracting edges\" width=\"960\" height=\"760\" \/><\/a><\/p>\n<h3>How to make an app for document scanner?<\/h3>\n<p>For making an app for document scanner we are making two files.<\/p>\n<p>1. Document_scanner.py<br \/>\n2. App.py<\/p>\n<p><strong>Note:-<\/strong> Both files must be in the same folder.<\/p>\n<p>In App.py we are importing Document_scanner.py file. The purpose behind importing files is to make code readable and small to make execution fast. Let\u2019s see the implementation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import tkinter as tk\r\nfrom tkinter import filedialog\r\nfrom document_scanner import Scan_Document\r\nimport img2pdf\r\ndef Browse_doc():\r\n    file_path = filedialog.askopenfilename(filetypes=[(\"Image files\", \"*.jpg;*.jpeg;*.png\"), (\"Word files\", \"*.doc;*.docx\"), (\"PowerPoint files\", \"*.ppt;*.pptx\")])\r\n    if file_path:\r\n        window_size = (612, 612)\r\n        Scan_Document(window_size, file_path)\r\ndef To_pdf():\r\n    file_path = filedialog.askopenfilename(filetypes=[(\"Image files\", \"*.jpg;*.jpeg;*.png\"), (\"Word files\", \"*.doc;*.docx\"), (\"PowerPoint files\", \"*.ppt;*.pptx\")])\r\n    if file_path:\r\n        save_path = filedialog.asksaveasfilename(defaultextension=\".pdf\", filetypes=[(\"PDF files\", \"*.pdf\")])\r\n        if save_path:\r\n            with open(save_path, \"wb\") as f:\r\n                f.write(img2pdf.convert(file_path))\r\ndef Capture_doc():\r\n    window_size = (612, 612)\r\n    Scan_Document(window_size)\r\n\r\nroot = tk.Tk()\r\nroot.title(\"Document Scanner App by DataFlair\")  \r\nbrowse_button = tk.Button(root, text=\"Browse Document\", command=Browse_doc)\r\nbrowse_button.pack()\r\nscan_button = tk.Button(root, text=\"Capture New Document\", command=Capture_doc)\r\nscan_button.pack()\r\nconvert_button = tk.Button(root, text=\"Convert to PDF\", command=To_pdf)\r\nconvert_button.pack()\r\nroot.mainloop()<\/pre>\n<p>It creates a user-friendly graphical user interface for document scanner. It has three buttons: &#8220;Browse Document&#8221; which is used for selecting an image file to scan and display, &#8220;Capture New Document&#8221; which is used to capture a fresh document using the camera and display and &#8220;Convert to PDF&#8221; which is used to convert an image or document file to PDF format and save it at a chosen location.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/convert-to-pdf.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132201 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/convert-to-pdf.webp\" alt=\"convert to pdf\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><strong>Capture New Document<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/capture-new-document-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132202 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/capture-new-document-.webp\" alt=\"capture new document\" width=\"1920\" height=\"1008\" \/><\/a><\/p>\n<p><strong>Convert to Pdf<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/Convert-to-Pdf.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132203 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/Convert-to-Pdf.webp\" alt=\"Convert to Pdf \" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-Convert-to-Pdf0A.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132204 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-Convert-to-Pdf0A.webp\" alt=\"opencv Convert to Pdf\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-Convert-to-Pdf-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132205 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-Convert-to-Pdf-output.webp\" alt=\"opencv convert to Pdf output\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><strong>Browse Document<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/browse-document.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132206 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/browse-document.webp\" alt=\"browse document\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/browse-document-image.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132207 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/browse-document-image.webp\" alt=\"browse document image\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>This document scanner built with OpenCV and Python, processes images to extract important shapes. It converts images to grayscale, enhances smoothness, detects edges, identifies contours, and selects the largest ones. If a quadrilateral shape is found, the code transforms the image based on that shape. It also creates resized versions of the transformed and original images. This document scanner is a valuable tool for extracting and working with document-like shapes from images.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2531,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1I-CSfvvJqz5LDZEeTi-oNMFYSjs0Va9Y\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601065201\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1I-CSfvvJqz5LDZEeTi-oNMFYSjs0Va9Y\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-01 11:08:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-04 17:42:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-09 18:06:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-13 15:26:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-17 23:09:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-21 04:15:31&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-21 04:15:31&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get ready to create your own document scanner using OpenCV and Python! This project will walk you through the important stages of scanning, from capturing document images to enhancing their quality. In this OpenCV&#46;&#46;&#46;<\/p>\n","protected":false},"author":86671,"featured_media":132210,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27755],"tags":[30155,30156,30153,30154,21719,30129,30121,30118],"class_list":["post-116520","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv-tutorials","tag-document-scanner","tag-document-scanner-project","tag-document-scanner-using-opencv","tag-opencv-document-scanner-project","tag-opencv-projects","tag-opencv-projects-for-practice","tag-opencv-projects-ideas","tag-python-opencv-projects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OpenCV Project - Document Scanner - DataFlair<\/title>\n<meta name=\"description\" content=\"OpenCV Document Scanner converts images to grayscale, enhances smoothness, detects edges, identifies contours, and selects the largest ones.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenCV Project - Document Scanner - DataFlair\" \/>\n<meta property=\"og:description\" content=\"OpenCV Document Scanner converts images to grayscale, enhances smoothness, detects edges, identifies contours, and selects the largest ones.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-04T12:30:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T06:51:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/document-scanner-using-opencv.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenCV Project - Document Scanner - DataFlair","description":"OpenCV Document Scanner converts images to grayscale, enhances smoothness, detects edges, identifies contours, and selects the largest ones.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/","og_locale":"en_US","og_type":"article","og_title":"OpenCV Project - Document Scanner - DataFlair","og_description":"OpenCV Document Scanner converts images to grayscale, enhances smoothness, detects edges, identifies contours, and selects the largest ones.","og_url":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2024-03-04T12:30:21+00:00","article_modified_time":"2026-06-01T06:51:53+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/document-scanner-using-opencv.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49"},"headline":"OpenCV Project &#8211; Document Scanner","datePublished":"2024-03-04T12:30:21+00:00","dateModified":"2026-06-01T06:51:53+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/"},"wordCount":908,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/document-scanner-using-opencv.webp","keywords":["document scanner","document scanner project","document scanner using opencv","opencv document scanner project","opencv projects","opencv projects for practice","opencv projects ideas","python opencv projects"],"articleSection":["OpenCV Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/","url":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/","name":"OpenCV Project - Document Scanner - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/document-scanner-using-opencv.webp","datePublished":"2024-03-04T12:30:21+00:00","dateModified":"2026-06-01T06:51:53+00:00","description":"OpenCV Document Scanner converts images to grayscale, enhances smoothness, detects edges, identifies contours, and selects the largest ones.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/document-scanner-using-opencv.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/document-scanner-using-opencv.webp","width":1200,"height":628,"caption":"document scanner using opencv"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/document-scanner-using-opencv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"OpenCV Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/opencv-tutorials\/"},{"@type":"ListItem","position":3,"name":"OpenCV Project &#8211; Document Scanner"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49","name":"TechVidvan Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","caption":"TechVidvan Team"},"description":"TechVidvan Team provides high-quality content &amp; courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.","url":"https:\/\/data-flair.training\/blogs\/author\/test001\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/116520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/86671"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=116520"}],"version-history":[{"count":10,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/116520\/revisions"}],"predecessor-version":[{"id":148604,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/116520\/revisions\/148604"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/132210"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=116520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=116520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=116520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}