{"id":2257,"date":"2022-07-08T13:54:19","date_gmt":"2022-07-08T08:54:19","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2257"},"modified":"2022-07-08T13:54:22","modified_gmt":"2022-07-08T08:54:22","slug":"python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/","title":{"rendered":"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line"},"content":{"rendered":"\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">pip install opencv-python<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">code.py<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\"># OpenCV program to detect face in real time\n# import libraries of python OpenCV\n# where its functionality resides\n\nfrom cv2 import cv2\n\nimport clx.xms\nimport requests\n# By creating an account in sinch sms You can get your code.\n# code for sms starts here\n#client is a object that carries your unique token.\nclient = clx.xms.Client(service_plan_id='your_service id',\n            token='token_id')\n\ncreate = clx.xms.api.MtBatchTextSmsCreate()\ncreate.sender = 'sender no.'\ncreate.recipients = {'recipients no.'}\ncreate.body = 'This is a test message from your Sinch account'\n# code for sms ends here\n# Face Recognition starts from here.\n# load the required trained XML classifiers\n#https:\/\/github.com\/opencv\/opencv\/blob\/master\n#\/data\/haarcascades\/haarcascade_frontalface_default.xml\n# Trained XML classifiers describes some features of some\n# object we want to detect a cascade function is trained\n# from a lot of positive(faces) and negative(non-faces)\n# images.\n\ndetector = cv2.CascadeClassifier(\n  &quot;path&quot;)\n\n# capture frames from a camera\n\ncap = cv2.VideoCapture(0, cv2.CAP_DSHOW)\n#We want to send sms only once not until the face is there and for that we are\n#initializing the counter\ncounter = 0\n# loop runs if capturing has been initialized.\n\nwhile True:\n  # reads frames from a camera\n\n  ret, img = cap.read()\n\n  if ret:\n    # convert to gray scale of each frames\n\n    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n  # Detects faces of different sizes in the input image\n\n    faces = detector.detectMultiScale(gray, 1.1, 4)\n\n    for face in faces:\n      \n      x, y, w, h = face\n      # if there is any face and counter is zero then only it will send notification to the sender\n      if(face.any() and counter ==0):\n        try:\n        batch = client.create_batch(create)\n        except (requests.exceptions.RequestException, clx.xms.exceptions.ApiException) as ex:\n          print('Failed to communicate with XMS: %s' % str(ex))\n        #sms ends here\n      # To draw a rectangle in a face\n      cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)\n  \n    \n    cv2.imshow(&quot;Face&quot;, img)\n    counter = 1\n  # Wait for 'q' key to stop\n\n  key = cv2.waitKey(1)\n  if key == ord(&quot;q&quot;):\n    break\n# Close the window\ncap.release()\n# De-allocate any associated memory usage\n\ncv2.destroyAllWindows()<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>code.py<\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line<\/title>\n<meta name=\"description\" content=\"pip install opencv-python code.py # OpenCV program to detect face in real time # import libraries of python OpenCV # where its functionality resides from\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line\" \/>\n<meta property=\"og:description\" content=\"pip install opencv-python code.py # OpenCV program to detect face in real time # import libraries of python OpenCV # where its functionality resides from\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-08T08:54:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-08T08:54:22+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line","description":"pip install opencv-python code.py # OpenCV program to detect face in real time # import libraries of python OpenCV # where its functionality resides from","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:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/","og_locale":"en_US","og_type":"article","og_title":"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line","og_description":"pip install opencv-python code.py # OpenCV program to detect face in real time # import libraries of python OpenCV # where its functionality resides from","og_url":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-07-08T08:54:19+00:00","article_modified_time":"2022-07-08T08:54:22+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line","datePublished":"2022-07-08T08:54:19+00:00","dateModified":"2022-07-08T08:54:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/"},"wordCount":18,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/","url":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/","name":"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-07-08T08:54:19+00:00","dateModified":"2022-07-08T08:54:22+00:00","description":"pip install opencv-python code.py # OpenCV program to detect face in real time # import libraries of python OpenCV # where its functionality resides from","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/python3-opencv-detect-people-face-in-webcam-and-send-sms-using-sinch-api-in-command-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python 3 OpenCV Detect People Face in Webcam and Send SMS Using Sinch API in Command Line"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2257"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2257\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}