{"id":88632,"date":"2024-12-24T18:00:20","date_gmt":"2024-12-24T12:30:20","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=88632"},"modified":"2024-12-24T18:22:00","modified_gmt":"2024-12-24T12:52:00","slug":"python-opencv-selfie-capture-by-detecting-smile-project","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/","title":{"rendered":"Python OpenCV Project &#8211; Auto-capture Selfie by Detecting Smile"},"content":{"rendered":"<p>Enter the wonderful realm of Smile Capture, where a single smile can bring moments of pure happiness to life. It is important to capture every moment of our life. In this OpenCV Selfie Capture, we are exploring the fascinating technology that can effortlessly capture the true feeling of joy. We will capture your smile from every angle.<\/p>\n<h2>Prerequisites For Python OpenCV Selfie Capture by Detecting Smile<\/h2>\n<p>A strong grasp of the Python programming language and proficiency with the OpenCV library is essential\/ Additionally, ensuring your system meets the required specifications is crucial for the endeavour.<\/p>\n<p>1. Python 3.7 and above<\/p>\n<p>2. Any Python editor (VS code, Pycharm, etc.)<\/p>\n<h3>Download the Python OpenCV Selfie Capture by Detecting Smile Project<\/h3>\n<p>Please download the source code of Python OpenCV Selfie Capture when the User Smiles: <a href=\"https:\/\/drive.google.com\/file\/d\/1HwQb6p91XDEfJIyyP-gukn_Gz49cVJqN\/view?usp=sharing\"><strong>Python<\/strong> <strong>OpenCV Selfie Capture by Detecting Smile Project Code.<\/strong><\/a><\/p>\n<h3>Installation<\/h3>\n<p>Open Windows cmd as administrator<\/p>\n<p>1. Enter the following command to install the OpenCV library<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install opencv-python<\/pre>\n<p>2. Use the following command to install dlib library.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install dlib<\/pre>\n<h3>Let\u2019s Implement It<\/h3>\n<p>For the implementation, follow the below steps.<\/p>\n<p>1. Here, we are importing the required packages for our implementation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2\r\nimport dlib<\/pre>\n<p>2. Here, we are initializing a frontal face detector to detect faces in images. We are also using a pretrained modelto predict facial landmarks and detect smiles.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">face_detection = dlib.get_frontal_face_detector()\r\nsmile_detection = dlib.shape_predictor(\"shape_predictor_68_face_landmarks.dat\")<\/pre>\n<p>3. Now, we are opening the camera and initializing the smile_count variable.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cap = cv2.VideoCapture(0)\r\nsmile_count=0<\/pre>\n<p>4. Start the while loop.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">while True:<\/pre>\n<p>5. Using a loop, we continuously capture the frames and convert them to a grey scale.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ret, frame = cap.read()\r\ngray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\r\nfaces = face_detection(gray)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/OpenCV-Selfie-Capture.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-89185\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/OpenCV-Selfie-Capture.webp\" alt=\"OpenCV Selfie Capture\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p>6. This loop measures mouth width using facial landmarks for each recognized face. If the mouth width exceeds 65, it says smile detected and saves the current frame in the directory.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">for face in faces:\r\n        landmarks = smile_detection(gray,face)\r\n        left_co = (landmarks.part(48).x, landmarks.part(48).y)\r\n        right_co = (landmarks.part(54).x, landmarks.part(54).y)\r\n        mouth_wid = right_co[0] - left_co[0]\r\n        print(mouth_wid)\r\n        if mouth_wid &gt; 65:\r\n            cv2.putText(frame, \"Smile Detected\", (70, 70), cv2.FONT_HERSHEY_SIMPLEX, 2, (14, 255, 132), 3)\r\n            cv2.imwrite(\"Selfie.jpg\", frame)\r\n            smile_count += 1\r\n            selfie_filename = f\"selfie_{smile_count}.jpg\"\r\n            cv2.imwrite(selfie_filename, frame)<\/pre>\n<p>7. Frames are shown in the \u201cTechVidvan\u201d window. If the user presses the \u2018q\u2019 key, it stops executing.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cv2.imshow(\"TechVidvan\", frame)\r\n    if cv2.waitKey(1) &amp; 0xFF == ord('q'):\r\n        break<\/pre>\n<p><strong>Note:-<\/strong> write the steps 5-7 inside the 4th step while loop.<\/p>\n<p>8. Once the program stops, it closes the camera and all the windows.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cap.release()\r\ncv2.destroyAllWindows()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/OpenCV-Selfie-Capture-smile-dete.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-89186\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/OpenCV-Selfie-Capture-smile-dete.webp\" alt=\"OpenCV Selfie Capture smile dete\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/OpenCV-Selfie-Captur-output-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-89187\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/OpenCV-Selfie-Captur-output-.webp\" alt=\"OpenCV Selfie Capture output\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/output-OpenCV-Selfie-Captur.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-89188\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/09\/output-OpenCV-Selfie-Captur.webp\" alt=\"output OpenCV Selfie Capture\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>To sum up, Smile Capture technology adds a sprinkle of enhancement to our digital experience. Facial recognition and image processing turn smiles into cherished memories. As technology connects our virtual and real worlds, smile capture beautifully enhances our lives.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enter the wonderful realm of Smile Capture, where a single smile can bring moments of pure happiness to life. It is important to capture every moment of our life. In this OpenCV Selfie Capture,&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":447378,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[193],"tags":[5690,5573,391,5688,379,5550,481,5689,5575],"class_list":["post-88632","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv-tutorials","tag-auto-capture-selfie-by-detecting-smile-using-opencv","tag-opencv","tag-opencv-project","tag-python-opencv-auto-capture-selfie-by-detecting-smile","tag-python-opencv-project","tag-python-opencv-project-for-beginners","tag-python-opencv-project-ideas","tag-python-opencv-selfie-capture-by-detecting-smile-project","tag-python-opencv-selfie-capture-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python OpenCV Project - Auto-capture Selfie by Detecting Smile - TechVidvan<\/title>\n<meta name=\"description\" content=\"The Python OpenCV Selfie Capture when the User Smiles, a fascinating technology adds a sprinkle of enhancement to our digital experience.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python OpenCV Project - Auto-capture Selfie by Detecting Smile - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"The Python OpenCV Selfie Capture when the User Smiles, a fascinating technology adds a sprinkle of enhancement to our digital experience.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-24T12:30:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-24T12:52:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/10\/selfie-capture.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=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\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=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python OpenCV Project - Auto-capture Selfie by Detecting Smile - TechVidvan","description":"The Python OpenCV Selfie Capture when the User Smiles, a fascinating technology adds a sprinkle of enhancement to our digital experience.","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:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/","og_locale":"en_US","og_type":"article","og_title":"Python OpenCV Project - Auto-capture Selfie by Detecting Smile - TechVidvan","og_description":"The Python OpenCV Selfie Capture when the User Smiles, a fascinating technology adds a sprinkle of enhancement to our digital experience.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2024-12-24T12:30:20+00:00","article_modified_time":"2024-12-24T12:52:00+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/10\/selfie-capture.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/dde481bb412350cde1ed6e389bc0deaf"},"headline":"Python OpenCV Project &#8211; Auto-capture Selfie by Detecting Smile","datePublished":"2024-12-24T12:30:20+00:00","dateModified":"2024-12-24T12:52:00+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/"},"wordCount":360,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/10\/selfie-capture.webp","keywords":["auto capture selfie by detecting smile using opencv","opencv","opencv project","python opencv auto capture selfie by detecting smile","python opencv project","python opencv project for beginners","python opencv project ideas","python opencv selfie capture by detecting smile project","python opencv selfie capture project"],"articleSection":["OpenCV Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/","url":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/","name":"Python OpenCV Project - Auto-capture Selfie by Detecting Smile - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/10\/selfie-capture.webp","datePublished":"2024-12-24T12:30:20+00:00","dateModified":"2024-12-24T12:52:00+00:00","description":"The Python OpenCV Selfie Capture when the User Smiles, a fascinating technology adds a sprinkle of enhancement to our digital experience.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/10\/selfie-capture.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/10\/selfie-capture.webp","width":1200,"height":628,"caption":"selfie capture"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-opencv-selfie-capture-by-detecting-smile-project\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Python OpenCV Project &#8211; Auto-capture Selfie by Detecting Smile"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/dde481bb412350cde1ed6e389bc0deaf","name":"TechVidvan Team"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=88632"}],"version-history":[{"count":5,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88632\/revisions"}],"predecessor-version":[{"id":447773,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88632\/revisions\/447773"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/447378"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=88632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=88632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=88632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}