﻿{"id":650,"date":"2022-06-15T16:13:59","date_gmt":"2022-06-15T10:43:59","guid":{"rendered":"https:\/\/blogs.infosys.com\/digital-experience\/?p=650"},"modified":"2022-06-15T18:27:53","modified_gmt":"2022-06-15T12:57:53","slug":"exploring-opencv","status":"publish","type":"post","link":"https:\/\/blogs.infosys.com\/digital-experience\/emerging-technologies\/exploring-opencv.html","title":{"rendered":"Exploring OpenCV"},"content":{"rendered":"<p>OpenCV (Open-Source Computer Vision) is an OS computer vision &amp; ML\u00a0 library which has 2500+ optimized algorithms. These algorithms have wide variety of applications including face recognition &amp; detection, classifying human actions from videos, tracking eye movements, object identification, moving object tracking, image stitching to supply high-resolution image of the whole scene etc.<\/p>\n<p>It supports OS platforms like Android, Linux, MacOS &amp; Windows and provides interfaces in C++, Python, JAVA, and MATLAB. Mostly the applications of OpenCV are aligned to real-time vision taking advantage of Matrix Math Extensions(MMX) and Streaming SIMD Extensions(SSE) instructions when available. The Modular structure of OpenCV, which is developed using C++, are:<\/p>\n<ul>\n<li><strong>core<\/strong> \u2013\u00a0comprises of basic data structures that all other modules are referenced from.<\/li>\n<li><strong>videoio<\/strong> \u2013 interface to video codecs and video capturing<\/li>\n<li><strong>highgui<\/strong> \u2013 interface for simple GUI\u2019s<\/li>\n<li><strong>imgproc<\/strong> \u2013 handles image processing like non-linear &amp; linear image filtering, histograms, geometrical image transformations (generic table-based remapping, affine &amp; perspective warping, resize), color space conversion etc.<\/li>\n<li><strong>video<\/strong> \u2013 handles video analysis like object tracking, background subtraction, motion estimation<\/li>\n<li><strong>calib3d<\/strong> \u2013 algorithms like stereo correspondence &amp; basic multiple-view geometry, elements of 3D reconstruction &amp; object pose estimation.<\/li>\n<li><strong>features2d<\/strong> \u2013 salient feature detectors, descriptors and descriptor matchers<\/li>\n<li><strong>objdetect<\/strong> \u2013 object detection and also provides predefined classes for people, cars, eyes, faces etc.<\/li>\n<li>and few modules like Google test wrappers &amp; FLANN , Python bindings etc.<\/li>\n<\/ul>\n<p>A sample python code for recognizing sign plate from an image is given below:<\/p>\n<pre>import cv2\r\nfrom matplotlib import pyplot as plot\r\n\r\n# Load sample image\r\ntest_image = cv2.imread(\"image.jpg\")\r\n\r\n# By default OpenCV loads images as BRG\r\n# gray scale version for object detection\r\ngray_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)\r\n# rgb version for ploting the result\r\nrgb_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)\r\n\r\n# Load the haar classifier\r\nstop_haar = cv2.CascadeClassifier('stop_data.xml')\r\n\r\n# Find parts in image matching the classifier\r\nsigns_found = stop_haar.detectMultiScale(gray_image, minSize =(20, 20))\r\ncount = len(signs_found)\r\nif count != 0:\r\n  \u00a0 for (h, w, width, height) in signs_found:\r\n  \u00a0 \u00a0 \u00a0 # A rectangle drawn where sign is recognized\r\n  \u00a0 \u00a0 \u00a0 cv2.rectangle(rgb_image, (h, w),\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (h + height, w + width),\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (0, 255, 0), 5)\u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n# Plot the result\r\nplot.subplot(1, 1, 1)\r\nplot.imshow(rgb_image)\r\nplot.show()\r\n\r\n<\/pre>\n<p>which gives below given result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-652\" src=\"https:\/\/blogs.infosys.com\/digital-experience\/storage\/2022\/06\/opencv-300x179.png\" alt=\"\" width=\"300\" height=\"179\" \/><\/p>\n<p>The xml <em>stop_data.xml<\/em> is a Haar cascade classifier. Haar cascade is an approach to train a classifier using lots of positive and negative images.<\/p>\n<p>OpenCV is extensively used by well-established companies like Google, Microsoft, Intel, IBM, Honda, Toyota, Sony along with startups like Applied Minds, VideoSurf, and Zeitera.<\/p>\n<p>Deployed usage of OpenCV span the range from drowning accident detection in swimming pool in Europe, street-view image stitching, mine equipment monitoring in China, intrusion detection in surveillance video in Israel, checking runways for debris in Turkey to rapid face detection in Japan.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenCV (Open-Source Computer Vision) is an OS computer vision &amp; ML\u00a0 library which has [&hellip;]<\/p>\n","protected":false},"author":236,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[],"coauthors":[93],"class_list":["post-650","post","type-post","status-publish","format-standard","hentry","category-emerging-technologies"],"acf":[],"_links":{"self":[{"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/posts\/650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/users\/236"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/comments?post=650"}],"version-history":[{"count":16,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/posts\/650\/revisions"}],"predecessor-version":[{"id":702,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/posts\/650\/revisions\/702"}],"wp:attachment":[{"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/media?parent=650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/categories?post=650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/tags?post=650"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.infosys.com\/digital-experience\/wp-json\/wp\/v2\/coauthors?post=650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}