

{"id":115160,"date":"2024-01-01T18:00:51","date_gmt":"2024-01-01T12:30:51","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=115160"},"modified":"2026-06-01T11:56:02","modified_gmt":"2026-06-01T06:26:02","slug":"opencv-pedestrian-detection-project","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/","title":{"rendered":"OpenCV Pedestrian Detection Project"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2501,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1rZWNxcG0pn6ekiJXW701iDd-jq2C-rM1\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601062658\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1rZWNxcG0pn6ekiJXW701iDd-jq2C-rM1\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-02 06:25:59&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 06:25:59&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Pedestrian detection using OpenCV is a technique to identify humans in images or videos. This method is widely used in various applications, such as surveillance and self-driving cars.<\/p>\n<p>OpenCV is an open-source computer vision library that provides functions to analyze images and videos. Pedestrian detection using OpenCV is based on simple rectangular features called Haar-like features. It is an easy and efficient way to detect pedestrians and has become a popular research area to improve its accuracy and efficiency.<\/p>\n<h2>What is meant by the Pedestrian?<\/h2>\n<p>Pedestrians are people who are traveling on foot, such as walking, running, or jogging, on sidewalks, crosswalks, or any other pedestrian-friendly areas. Pedestrians are an essential part of any urban or rural environment, as they provide a cost-effective and sustainable mode of transportation.<\/p>\n<p>Pedestrian safety is crucial, and it is important to ensure that pedestrians have safe and accessible places to walk, as well as protection from vehicular traffic. Pedestrian detection is the process of identifying pedestrians in images or videos, which is a critical component of many computer vision applications, such as autonomous vehicles and surveillance systems.<\/p>\n<h3>Cascade in Pedestrian Detection<\/h3>\n<p>Cascade in pedestrian detection is a machine learning algorithm used to detect pedestrians in images or videos. It&#8217;s trained on positive and negative images to learn to distinguish between them. It scans the image at different scales and locations, applying a series of classifiers in a cascade fashion to quickly and accurately detect pedestrians in real time. Cascade classifiers are widely used in pedestrian detection systems for surveillance, crowd monitoring, and self-driving cars.<\/p>\n<h3>Prerequisites for Pedestrian Detection Using OpenCV<\/h3>\n<p>It is important to have a solid understanding of the Python programming language and the OpenCV library. Apart from this, you should have the following system requirements.<\/p>\n<p>1. Python 3.7 and above<br \/>\n2. Any Python editor (VS code, Pycharm, etc.)<\/p>\n<h3>Download OpenCV Pedestrian Detection Project<\/h3>\n<p>Please download the source code of OpenCV Pedestrian Detection Project from the following link:<a href=\"https:\/\/drive.google.com\/file\/d\/1rZWNxcG0pn6ekiJXW701iDd-jq2C-rM1\/view?usp=drive_link\"><strong> OpenCV Pedestrian Detection Project Code.<\/strong><\/a><\/p>\n<h3>Installation<\/h3>\n<p>Open windows cmd as administrator<\/p>\n<p>1. To install the opencv library run the command from the cmd.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install opencv-python\r\n<\/pre>\n<h3>Let\u2019s Implement It<\/h3>\n<p>To implement it follow the below step.<\/p>\n<p>1. First of all we are importing all the necessary libraries that are required during implementation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2 \r\n<\/pre>\n<p>2. The line cap = cv2.VideoCapture(&#8216;pedestrian.avi&#8217;) creates a VideoCapture object in OpenCV that reads video frames from a file called &#8220;pedestrian.avi&#8221;.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cap = cv2.VideoCapture('pedestrian.avi')\r\n<\/pre>\n<p>3. This loads a pre-trained cascade classifier called &#8216;haarcascade_fullbody.xml&#8217;. This classifier is designed to detect the full body of a human in an image or video.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cascade_human = cv2.CascadeClassifier('haarcascade_fullbody.xml')\r\n<\/pre>\n<p>4. Start While loop.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">while True:\r\n<\/pre>\n<p>5. This reads a frame from the video capture object &#8216;cap&#8217;. It returns two values: &#8216;ret&#8217; which is a boolean indicating if the frame was successfully read or not, and &#8216;frame&#8217;, which is the actual image frame that was read from the video.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ret, frame = cap.read()\r\n<\/pre>\n<p>6. This code detects human bodies in a video frame by first converting it to grayscale and then using the detectMultiScale() method of the cascade classifier cascade_human. The method returns a list of rectangles that represent the detected human bodies.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\r\nhuman_bodies = cascade_human.detectMultiScale(gray, 1.9, 1)\r\n<\/pre>\n<p>7. It draws a rectangle around each detected human body in the original color frame using the cv2.rectangle() function. The (x, y) coordinates and the width (w) and height (h) of each detected human body are obtained from the human_bodies variable. The rectangle is drawn using the color (255, 0, 0) and a thickness of 2 pixels.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">for (x, y, w, h) in human_bodies:\r\n         cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)\r\n<\/pre>\n<p>8. This code displays the video frame with detected human bodies and waits for a key press. If the key pressed is &#8216;q&#8217;, the program exits and all windows are closed.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cv2.imshow('DataFlair', frame)\r\n    if cv2.waitKey(1) &amp; 0xFF == ord('q'):\r\n        break\r\n<\/pre>\n<p><strong>Note:-<\/strong> you have to include steps 5 to 8 in the while loop.<\/p>\n<p>9. release the video capture and close all windows that were opened using OpenCV in the previous code.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cap.release()\r\ncv2.destroyAllWindows()\r\n<\/pre>\n<h3>Opencv Pedestrian Detection Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/OpenCV-Pedestrian-Detection-output-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-131945 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/OpenCV-Pedestrian-Detection-output-.webp\" alt=\"opencv pedestrian detection output\" width=\"1153\" height=\"912\" \/><\/a><\/p>\n<h3>OpenCV Pedestrian Detection Video Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/pedestrian-detection-using-opencv-video-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-132533 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/pedestrian-detection-using-opencv-video-output.webp\" alt=\"pedestrian detection using opencv video output\" width=\"800\" height=\"600\" \/><\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>Pedestrian detection using OpenCV is an important technology that can improve pedestrian safety in self-driving cars, surveillance systems, and city planning.<\/p>\n<p>OpenCV is a flexible and powerful tool that can be customized to fit different situations. It uses advanced techniques to accurately detect pedestrians in difficult situations like low light, obstacles, and crowded backgrounds. As research continues, OpenCV will get even better at detecting pedestrians, making it safer for people to walk around in the future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pedestrian detection using OpenCV is a technique to identify humans in images or videos. This method is widely used in various applications, such as surveillance and self-driving cars. OpenCV is an open-source computer vision&#46;&#46;&#46;<\/p>\n","protected":false},"author":86671,"featured_media":131946,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27755],"tags":[27729,27730,27733,27732,21719,24317,27731,25729],"class_list":["post-115160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv-tutorials","tag-opencv-pedestrian-detection","tag-opencv-pedestrian-detection-project","tag-opencv-project-for-practice","tag-opencv-project-ideas","tag-opencv-projects","tag-pedestrian-detection","tag-pedestrian-detection-project","tag-python-opencv-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OpenCV Pedestrian Detection Project - DataFlair<\/title>\n<meta name=\"description\" content=\"Pedestrian detection using OpenCV is an important technology that can improve pedestrian safety in self-driving cars, surveillance systems, and city planning.\" \/>\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\/opencv-pedestrian-detection-project\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenCV Pedestrian Detection Project - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Pedestrian detection using OpenCV is an important technology that can improve pedestrian safety in self-driving cars, surveillance systems, and city planning.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/\" \/>\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-01-01T12:30:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T06:26:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-pedestrian-detection.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=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenCV Pedestrian Detection Project - DataFlair","description":"Pedestrian detection using OpenCV is an important technology that can improve pedestrian safety in self-driving cars, surveillance systems, and city planning.","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\/opencv-pedestrian-detection-project\/","og_locale":"en_US","og_type":"article","og_title":"OpenCV Pedestrian Detection Project - DataFlair","og_description":"Pedestrian detection using OpenCV is an important technology that can improve pedestrian safety in self-driving cars, surveillance systems, and city planning.","og_url":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2024-01-01T12:30:51+00:00","article_modified_time":"2026-06-01T06:26:02+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-pedestrian-detection.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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49"},"headline":"OpenCV Pedestrian Detection Project","datePublished":"2024-01-01T12:30:51+00:00","dateModified":"2026-06-01T06:26:02+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/"},"wordCount":709,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-pedestrian-detection.webp","keywords":["opencv pedestrian detection","opencv pedestrian detection project","opencv project for practice","opencv project ideas","opencv projects","pedestrian detection","pedestrian detection project","python opencv project"],"articleSection":["OpenCV Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/","url":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/","name":"OpenCV Pedestrian Detection Project - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-pedestrian-detection.webp","datePublished":"2024-01-01T12:30:51+00:00","dateModified":"2026-06-01T06:26:02+00:00","description":"Pedestrian detection using OpenCV is an important technology that can improve pedestrian safety in self-driving cars, surveillance systems, and city planning.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-pedestrian-detection.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/12\/opencv-pedestrian-detection.webp","width":1200,"height":628,"caption":"opencv pedestrian detection"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/opencv-pedestrian-detection-project\/#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 Pedestrian Detection Project"}]},{"@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\/115160","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=115160"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115160\/revisions"}],"predecessor-version":[{"id":148569,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115160\/revisions\/148569"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/131946"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=115160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=115160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=115160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}