From d45361346e720ea9c2debce64cd83585fef4397b Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 08:37:19 +0530 Subject: [PATCH 1/7] Create AbhishekBhosale_C# --- AbhishekBhosale_C# | 1 + 1 file changed, 1 insertion(+) create mode 100644 AbhishekBhosale_C# diff --git a/AbhishekBhosale_C# b/AbhishekBhosale_C# new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/AbhishekBhosale_C# @@ -0,0 +1 @@ + From c6de8b797fc82fd3dc37fd160c39a36e00af405d Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 15:31:59 +0530 Subject: [PATCH 2/7] Delete AbhishekBhosale_C# --- AbhishekBhosale_C# | 1 - 1 file changed, 1 deletion(-) delete mode 100644 AbhishekBhosale_C# diff --git a/AbhishekBhosale_C# b/AbhishekBhosale_C# deleted file mode 100644 index 8b1378917..000000000 --- a/AbhishekBhosale_C# +++ /dev/null @@ -1 +0,0 @@ - From c3c8ac0b2b906b3181043f58e982a719da88eaf3 Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 15:32:12 +0530 Subject: [PATCH 3/7] Markdown.md --- AbhishekBhosale_C#/Markdown.md | 286 +++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 AbhishekBhosale_C#/Markdown.md diff --git a/AbhishekBhosale_C#/Markdown.md b/AbhishekBhosale_C#/Markdown.md new file mode 100644 index 000000000..2a7c3fef8 --- /dev/null +++ b/AbhishekBhosale_C#/Markdown.md @@ -0,0 +1,286 @@ +# Introduction to Markdown + +Markdown is a lightweight markup language with plain text formatting syntax. What this means to you is that by using just a few extra symbols in your text, Markdown helps you create a document with an explicit structure. + +## Why Markdown + +* **Easy** The syntax is very simple. + +* **Fast:** It speeds up the workflows. + +* **Clean:** No missing closing tags, no improperly nested tags, no blocks left without containers. + +* **Portable:** Cross-platform by nature. + +* **Flexible:** Output documents to a wide array of formats like, convert to HTML , rich text for sending emails or any number of other proprietary formats. + + +> We will be using markdown in almost every module's assignment, so it is an important thing to learn here if you don't know already. + +## Basic working in Markdown + +### 1. Heading + +Use # for headings. You can use this like in HTML for H1, H2 etc. + + + +**Input:** + + + +```md + +# H1 +## H2 +### H3 +. +. +###### H6 +``` + +**Output:** + +# H1 +## H2 +### H3 +. + +. +###### H6 + +
+ +### 2. Bold,Italics and striking words + +Use `**` for making text bold and `*` for italics. + +> You are required to close the tag here. + +**Input:** + +```md + +**Bold** +*Italics* +***Bold and Italics Both*** +~~this is the striking one~~ +``` + +**Output:** + +**Bold** + +*Italics* + +***Bold and Italics Both*** + +~~this is the striking one~~ + +
+ + +### 3. Lists + +Use `*` from new line for unordered list, `1.` for order. + +> You can also use these with proper indentation. + +**Input:** + +```md + +* Unordered + +1. Ordered + +* Nested + 1. ordered inside. + * Unordered inside + +``` + +**Output:** + + +* Unordered + +1. Ordered + +* Nested + 1. ordered inside. + * Unordered inside + + + +
+ +### 4. Hyperlinks and images + +Use `[text](url)` for hyperlinks and, `![text](path/url)` for image. + +> You can also use image links by nesting these both. + +**Input:** + +```md + +[Devincept Website](https://devincept.tech/) + +![DevIncept logo image](extras/logo.gif) + +[![DevIncept logo image link](extras/logo.gif)](https://devincept.tech/) + +``` + +**Output:** + +[Devincept Website](https://devincept.tech/) + +![DevIncept logo image](extras/logo.gif) + +[![DevIncept logo image link](extras/logo.gif)](https://devincept.tech/) + + + +
+ +### 5. Coding and notes + +* Use ` for liner codes or highlight. +* Use ``` for multiline code. +* Use > to give a note. + +> You can also use language of code to make the multiline code more realistic, exp: ```python + +**Input:** + +```md + `simple code or highlight` + + > Give a note like this + + ```python + #simple python multiline code + a=input() + c=a + print (c) + ``` +``` + + + +**Output:** + +`simple code or highlight` + + +> Give a note like this + + +```python +#simple python multiline code +a=input() +c=a +print (c) +``` + + +
+ +### 6. Table + +Till now we got to know some important + + +**Input:** + +```md + +|Heading 1|Heading 2| Heading 3| +|---------|---------|----------| +| Data | Data | Data | +| Data | Data | Data | + +``` + +**Output:** + +|Heading 1|Heading 2| Heading 3| +|---------|---------|----------| +| Data | Data | Data | +| Data | Data | Data | + +
+ +### 7. The power of HTML + +We have seen the basic features of markdown till now, but superpower of markdown is, You can directly use HTML in it. + +> Some times it becomes a little difficult to do some complex things in markdown, so using HTML that time can make it work. + +**Input:** + + +```md +Lists or table inside the table can be implemented using HTML + +|Heading 1|Heading 2| Heading 3 | +|---------|---------|----------------------------------------------------------------------------| +| Data | Data | Data
  • Data part 1
  • Data part 2
| +| Data | Data |
h1h2
d1d2
| + +``` + +**Output:** + +|Heading 1|Heading 2| Heading 3| +|---------|---------|----------| +| Data | Data | Data
  • Data part 1
  • Data part 2
| +| Data | Data |
h1h2
d1d2
| + + +
+ +### 7. Emojis to make it :heart: + +Use emojis in your repository's Readme to make it Awesome :exclamation::exclamation::exclamation: + +**Input:** + + +```md +Use anywhere just like + +:bowtie: :blush: :smiley: :relaxed: + +:smile: :smirk: :heart_eyes: :kissing_heart: + +:heart: :kissing_closed_eyes: :flushed: :relieved: + +``` + +**Output:** + +:bowtie: :blush: :smiley: :relaxed: + +:smile: :smirk: :heart_eyes: :kissing_heart: + +:heart: :kissing_closed_eyes: :flushed: :relieved: + +> To get the complete list of github markdown emoji markup [click here](https://gist.github.com/rxaviers/7360908) + +
+ +  + +These were the most used Markdown features. These will help you for you assignment in this module as well as in further program, and without markdown your repository on github is just a code-file, start using it now :wink: + +  + +  + + + +Thanks for Reading!!! + From 221e44fd5b5ed8eb4c5a962a55e67e86d117cd73 Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 15:45:29 +0530 Subject: [PATCH 4/7] Create AbhishekBhosale_Objectdetection_OpenCV.md --- .../AbhishekBhosale_Objectdetection_OpenCV.md | 242 ++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md diff --git a/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md new file mode 100644 index 000000000..39738ae46 --- /dev/null +++ b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md @@ -0,0 +1,242 @@ +OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. + +# Introduction to OpenCV # + +OpenCV is one of the most popular computer vision libraries. If you want to start your journey in the field of computer vision, then a thorough understanding of the concepts of OpenCV is of paramount importance. + We will cover the following topics: + + * Reading an image + * Extracting the RGB values of a pixel + * Extracting the Region of Interest (ROI) + * Resizing the Image + * Rotating the Image + * Drawing a Rectangle + * Displaying text + +# Reading an image # +Use the below mentioned code to import and use OpenCv +# Importing the OpenCV library # +import cv2 +# Reading the image using imread() function # +image = cv2.imread('image.png') + +# Extracting the height and width of an image # +h, w = image.shape[:2] +# Displaying the height and width # +print("Height = {}, Width = {}".format(h, w)) + +Now we will focus on extracting the RGB values of an individual pixel. +Note – OpenCV arranges the channels in BGR order. So the 0th value will correspond to Blue pixel and not Red. + +# Extracting the RGB values of a pixel # +* Extracting RGB values. +* Here we have randomly chosen a pixel +* by passing in 100, 100 for height and width. +(B, G, R) = image[100, 100] + +* Displaying the pixel values +print("R = {}, G = {}, B = {}".format(R, G, B)) + +* We can also pass the channel to extract +* the value for a specific channel +B = image[100, 100, 0] +print("B = {}".format(B)) + +# Extracting the Region of Interest (ROI) # + +* We will calculate the region of interest +* by slicing the pixels of the image +roi = image[100 : 500, 200 : 700] + +# Resizing the Image # + +* resize() function takes 2 parameters, +* the image and the dimensions +resize = cv2.resize(image, (800, 800)) + +# Calculating the ratio # +ratio = 800 / w + +# Creating a tuple containing width and height # +dim = (800, int(h * ratio)) + +# Resizing the image # +resize_aspect = cv2.resize(image, dim) + +# Rotating the Image # + +* Calculating the center of the image +center = (w // 2, h // 2) + +* Generating a rotation matrix +matrix = cv2.getRotationMatrix2D(center, -45, 1.0) + +* Performing the affine transformation +rotated = cv2.warpAffine(image, matrix, (w, h)) + +There are a lot of steps involved in rotating an image. So, let me explain each of them in detail. + +The 2 main functions used here are – + + getRotationMatrix2D() + warpAffine() + +getRotationMatrix2D() +It takes 3 arguments – + + center – The center coordinates of the image + Angle – The angle (in degrees) by which the image should be rotated + Scale – The scaling factor + + + It returns a 2*3 matrix consisting of values derived from alpha and beta + alpha = scale * cos(angle) + beta = scale * sine(angle) + + Rotation Matrix + + warpAffine() + + The function warpAffine transforms the source image using the rotation matrix: + + dst(x, y) = src(M11X + M12Y + M13, M21X + M22Y + M23) + + Here M is the rotation matrix, described above. + It calculates new x, y co-ordinates of the image and transforms it. + +# Drawing a Rectangle # + +It is an in-place operation. +* We are copying the original image, +* as it is an in-place operation. +output = image.copy() + +* Using the rectangle() function to create a rectangle. +rectangle = cv2.rectangle(output, (1500, 900), (600, 400), (255, 0, 0), 2) + +It takes in 5 arguments – + + * Image + * Top-left corner co-ordinates + * Bottom-right corner co-ordinates + * Color (in BGR format) + * Line width + +# Displaying text # +It is also an in-place operation + +* Copying the original image +output = image.copy() + +* Adding the text using putText() function +text = cv2.putText(output, 'OpenCV Demo', (500, 550), cv2.FONT_HERSHEY_SIMPLEX, 4, (255, 0, 0), 2) + +It takes in 7 arguments – + + * Image + * Text to be displayed + * Bottom-left corner co-ordinates, from where the text should start + * Font + * Font size + * Color (BGR format) + * Line width + + +# Object Detection # + +Object Detection is a computer technology related to computer vision, image processing, and deep learning that deals with detecting instances of objects in images and videos +By applying object detection, you’ll not only be able to determine what is in an image, but also where a given object resides! +In this section we will understand a variety of object detection methods: + +## Template Matching ## + * Simply looking for an exact copy of an image in another larger image. + * It simply scans a larger image for a provided template by sliding the template target image across the larger image. + * The main option that can be adjusted is the comparison method used as the target template is slid across the larger image. + * The methods are all some source of correlation base metric. + * So we can see the different methods that opencv has available + ![](https://miro.medium.com/max/700/1*VghwcBOX62lu4HzRH8FIMg.png) +## Corner Detection ## +* A corner is a point whose local neighbourhood stands in two dominant and different edge directions. +* Or simply a corner can be interpreted as the junction of two edges or an edge is a sudden change in brightness. +* There are various corner detection algorithms +* We will take look at some of the most popular algorithms: + * Harris Corner Detection + * Shi-Tomasi Corner Detection +* Harris Corner Detection + * Published in 1988 by Chris Harris and Mike Stephens. + * The basic intuition is that corners can be detected by looking for significant change in all directions. + ![]( https://media5.datahacker.rs/2019/07/130-1024x608.png) +* Shi-Tomasi Corner Detection + * Published in 1994 by J. Shi and C. Tomasi in their paper *Good Features to Track*. + * It made a small change to the Harris Corner Detector which ended up with better results + * It changes the scoring function selection criteria that Harris uses for corner detection. + * Harris Corner Detection uses: + * **R = λ1λ2 – k( λ1 + λ2)** + * Shi-Tomasi uses: + * **R = min(λ1, λ2)** +## Edge Detection ## +* Expanding to find general edges of objects +* Canny Edge Detection Method + 1. Apply Gaussian filter to smooth the image in order to remove the noise. + 1. Find the intensity gradients of the image. + 1. Apply non-maximum suppression to get rid of spurious response to edge detection. + 1. Apply double threshold to determine possible edges. + 1. Track edge by hysteresis: Finalize the detection of edges by supressing all other edges that are weak and not connected to strong edges. +## Grid Detection ## +* Combining both concepts to find grid in images (useful for applications). +* Often cameras can create distortion in an image such as radial distortion and tangential distortion +* A good way to account for these distortions when performing like object tracking is to have a recognizable pattern attached to the object being tracked. +* Grid patterns are often used to calibrate cameras and track motion. +## Contour Detection ## +* Contours are defined simply as a curve joining all the continuous points having same colour or intensity. +* Contours are a useful tool for shape analysis and object detection and recognition +* OpenCV has a built in Counter finder function that can also help us differentiate between internal and external contours (eg – grabbing the eyes and smile from a cartoon face). +* Allows us to detect foreground vs background. +## Feature Matching ## +* Feature matching extracts defining key features from an input image (using ideas from corner, edge and contour detection). +* Then using a distance calculation, finds all the matches in a secondary image. +* More advanced methods of detecting matching object in another image, even if the target image is not shown exactly the same image we are searching. +* Feature Matching results: + +![](https://docs.opencv.org/3.4/matcher_result1.jpg) +* Notice how the input image is not exactly what is shown in the secondary image +* 3 methods of feature matching are: + 1. Brute-Force Matching with ORB Descriptors + 1. Brute-Force Matching with SIFT Descriptors and Ratio Test + 1. FLANN based Matcher + +## Watershed Algorithm ## +* Metaphorically, Watershed Algorithm transformation treats the image it operates upon like a topographic map, with the brightness of each point representing it’s height, and finds the line that runs along the tops of ridges. +* Any grayscale image can be viewed as a topographic surface where high intensity denotes peaks and hills while low intensity denotes valleys +* As the “water” rises, depending on the peaks (gradient) nearby, “water” from different valleys (different segments of the image), with different colors could start merge. +* To avoid this merging, the algorithm creates barrier (segment edge boundaries) in locations where “water” merges. +* The algorithm can then fill every isolated valley(local minima) with different colored water(labels). +* Advances algorithm that allows us to segment images into foreground and background +* Also allows us to manually set seeds to choose segments of an image. + * A common example is the use of coins next to each other on a table + * Attempting to segment these coins can be difficult: + + ![](https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQRLGLxjK2fADx4e7Sci8koBkeB0Lh-QtqAdg&usqp=CAU)\ + * It may be unclear to the algorithm if it should be treated as one large object or many small objects. + * The watershed algorithm can be very effective for these sort of problems +## Facial and Eye Detection ## +* Haar Cascades to identify faces in images +* We will be able to very quickly detect if a face is in an image and locate +* However we won’t know who’s face it belongs to. +* We would need a really large dataset and deep learning for facial recognition. +* Main feature types: + +![](https://docs.opencv.org/3.4/haar_features.jpg) +* Each feature is a single value obtained by subtracting sum of pixels under white rectangle from sum of pixels under black rectangle. +* Realistically, our images won’t be perfect lines and edges. +* These features are calculated by: + * **mean(dark region) – mean(light region)** +* A perfect edge would result in a value of one. +* The closer the result is to one, the better the feature. +* The Voila-Jones algorithm solves this by using the integral image. +* Resulting in an O(1) running time of the algorithm +* The algo also saves time by going through a cascade of classifiers. +* This means we will treat the image to a series(cascade)of classifiers based on the simple feature . +* Once an image fails a classifier, we can stop attempting to detect a face. + +### Thank You! From 75a6dd850f94729e27dd4ef27103ca85e09be48a Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 16:08:15 +0530 Subject: [PATCH 5/7] Update AbhishekBhosale_Objectdetection_OpenCV.md --- .../AbhishekBhosale_Objectdetection_OpenCV.md | 248 ++---------------- 1 file changed, 23 insertions(+), 225 deletions(-) diff --git a/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md index 39738ae46..f449b57e9 100644 --- a/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md +++ b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md @@ -1,242 +1,40 @@ -OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. +# Created by Abhishek -# Introduction to OpenCV # +## Object Detection -OpenCV is one of the most popular computer vision libraries. If you want to start your journey in the field of computer vision, then a thorough understanding of the concepts of OpenCV is of paramount importance. - We will cover the following topics: +In this page for Object Detection we will be using Haar feature-based Cascade classifiers. - * Reading an image - * Extracting the RGB values of a pixel - * Extracting the Region of Interest (ROI) - * Resizing the Image - * Rotating the Image - * Drawing a Rectangle - * Displaying text +**What is that?** -# Reading an image # -Use the below mentioned code to import and use OpenCv -# Importing the OpenCV library # -import cv2 -# Reading the image using imread() function # -image = cv2.imread('image.png') +It is an effective object detection method proposed by Paul Viola and Michael Jones in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features” in 2001. It is a machine learning based approach where a cascade function is trained from a lot of positive and negative images. It is then used to detect objects in other images. -# Extracting the height and width of an image # -h, w = image.shape[:2] -# Displaying the height and width # -print("Height = {}, Width = {}".format(h, w)) +Initially, the algorithim need a lot of positive images and negative images to train the classifier. Then we need to extract features from it so for this we use haar features as shown the image below.Now all possible sizes and locations of each kernel s used to calculate plenty of features. But among all these features we calculated, most of them are irrelevant.For this, we apply each and every feature on all the training images. For each feature, it finds the best threshold which will classify the faces to positive and negative. But obviously, there will be errors or misclassifications. We select the features with minimum error rate, which means they are the features that best classifies the face and non-face images.Final classifier is a weighted sum of these weak classifiers. It is called weak because it alone can’t classify the image, but together with others forms a strong classifier. The paper says even 200 features provide detection with 95% accuracy. Their final setup had around 6000 features. -Now we will focus on extracting the RGB values of an individual pixel. -Note – OpenCV arranges the channels in BGR order. So the 0th value will correspond to Blue pixel and not Red. + ![image](https://rahullpatell.files.wordpress.com/2015/04/main23.png) -# Extracting the RGB values of a pixel # -* Extracting RGB values. -* Here we have randomly chosen a pixel -* by passing in 100, 100 for height and width. -(B, G, R) = image[100, 100] +In an image, most of the image region is non-face region. So it is a better idea to have a simple method to check if a window is not a face region. If it is not, discard it in a single shot. Don’t process it again. Instead focus on region where there can be a face. This way, we can find more time to check a possible face region. -* Displaying the pixel values -print("R = {}, G = {}, B = {}".format(R, G, B)) +For this they introduced the concept of Cascade of Classifiers. Instead of applying all the 6000 features on a window, group the features into different stages of classifiers and apply one-by-one.If a window fails the first stage, discard it. We don’t consider remaining features on it. If it passes, apply the second stage of features and continue the process. The window which passes all stages is a face region. -* We can also pass the channel to extract -* the value for a specific channel -B = image[100, 100, 0] -print("B = {}".format(B)) +So this is a simple intuitive explanation of how Viola-Jones face detection works. -# Extracting the Region of Interest (ROI) # +--- -* We will calculate the region of interest -* by slicing the pixels of the image -roi = image[100 : 500, 200 : 700] +**Now lets take an example like face detection and eye detection and see what are the process that needs to be done.** -# Resizing the Image # +* A image when we import using OpenCV it is of the color format BGR. So we need to change it to grayscale to apply the Haar Cascade Classifier. +* Now to find the faces we use the **detectMultiScale()** function and it returns values of the format **(x, y, w, h)** where x is the starting x-coordinate, y is the starting y-coordinate and w is the width and h is the height. +* Then to make it visible on the photo we use **rectangle()** function and draw rectangle around it like the below picture. + ![image](https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTF9LipPzwRM-yh3DO7tNk4hHgB6MHmVKtorg&usqp=CAU) +* Now we can jus take out the part of the image of the face using **roi()** funtion and then apply the eye cascade classifier for this part by repeating the above steps. -* resize() function takes 2 parameters, -* the image and the dimensions -resize = cv2.resize(image, (800, 800)) -# Calculating the ratio # -ratio = 800 / w +**We can also apply this classifier for a video as well.** -# Creating a tuple containing width and height # -dim = (800, int(h * ratio)) +The steps are as follows: +* First the video capture needs to be turned on using **VideoCapture()** function. +* Next the current frame needs to extracted using **read** function. +* Now we need to do the same process as we did for an image. -# Resizing the image # -resize_aspect = cv2.resize(image, dim) -# Rotating the Image # - -* Calculating the center of the image -center = (w // 2, h // 2) - -* Generating a rotation matrix -matrix = cv2.getRotationMatrix2D(center, -45, 1.0) - -* Performing the affine transformation -rotated = cv2.warpAffine(image, matrix, (w, h)) - -There are a lot of steps involved in rotating an image. So, let me explain each of them in detail. - -The 2 main functions used here are – - - getRotationMatrix2D() - warpAffine() - -getRotationMatrix2D() -It takes 3 arguments – - - center – The center coordinates of the image - Angle – The angle (in degrees) by which the image should be rotated - Scale – The scaling factor - - - It returns a 2*3 matrix consisting of values derived from alpha and beta - alpha = scale * cos(angle) - beta = scale * sine(angle) - - Rotation Matrix - - warpAffine() - - The function warpAffine transforms the source image using the rotation matrix: - - dst(x, y) = src(M11X + M12Y + M13, M21X + M22Y + M23) - - Here M is the rotation matrix, described above. - It calculates new x, y co-ordinates of the image and transforms it. - -# Drawing a Rectangle # - -It is an in-place operation. -* We are copying the original image, -* as it is an in-place operation. -output = image.copy() - -* Using the rectangle() function to create a rectangle. -rectangle = cv2.rectangle(output, (1500, 900), (600, 400), (255, 0, 0), 2) - -It takes in 5 arguments – - - * Image - * Top-left corner co-ordinates - * Bottom-right corner co-ordinates - * Color (in BGR format) - * Line width - -# Displaying text # -It is also an in-place operation - -* Copying the original image -output = image.copy() - -* Adding the text using putText() function -text = cv2.putText(output, 'OpenCV Demo', (500, 550), cv2.FONT_HERSHEY_SIMPLEX, 4, (255, 0, 0), 2) - -It takes in 7 arguments – - - * Image - * Text to be displayed - * Bottom-left corner co-ordinates, from where the text should start - * Font - * Font size - * Color (BGR format) - * Line width - - -# Object Detection # - -Object Detection is a computer technology related to computer vision, image processing, and deep learning that deals with detecting instances of objects in images and videos -By applying object detection, you’ll not only be able to determine what is in an image, but also where a given object resides! -In this section we will understand a variety of object detection methods: - -## Template Matching ## - * Simply looking for an exact copy of an image in another larger image. - * It simply scans a larger image for a provided template by sliding the template target image across the larger image. - * The main option that can be adjusted is the comparison method used as the target template is slid across the larger image. - * The methods are all some source of correlation base metric. - * So we can see the different methods that opencv has available - ![](https://miro.medium.com/max/700/1*VghwcBOX62lu4HzRH8FIMg.png) -## Corner Detection ## -* A corner is a point whose local neighbourhood stands in two dominant and different edge directions. -* Or simply a corner can be interpreted as the junction of two edges or an edge is a sudden change in brightness. -* There are various corner detection algorithms -* We will take look at some of the most popular algorithms: - * Harris Corner Detection - * Shi-Tomasi Corner Detection -* Harris Corner Detection - * Published in 1988 by Chris Harris and Mike Stephens. - * The basic intuition is that corners can be detected by looking for significant change in all directions. - ![]( https://media5.datahacker.rs/2019/07/130-1024x608.png) -* Shi-Tomasi Corner Detection - * Published in 1994 by J. Shi and C. Tomasi in their paper *Good Features to Track*. - * It made a small change to the Harris Corner Detector which ended up with better results - * It changes the scoring function selection criteria that Harris uses for corner detection. - * Harris Corner Detection uses: - * **R = λ1λ2 – k( λ1 + λ2)** - * Shi-Tomasi uses: - * **R = min(λ1, λ2)** -## Edge Detection ## -* Expanding to find general edges of objects -* Canny Edge Detection Method - 1. Apply Gaussian filter to smooth the image in order to remove the noise. - 1. Find the intensity gradients of the image. - 1. Apply non-maximum suppression to get rid of spurious response to edge detection. - 1. Apply double threshold to determine possible edges. - 1. Track edge by hysteresis: Finalize the detection of edges by supressing all other edges that are weak and not connected to strong edges. -## Grid Detection ## -* Combining both concepts to find grid in images (useful for applications). -* Often cameras can create distortion in an image such as radial distortion and tangential distortion -* A good way to account for these distortions when performing like object tracking is to have a recognizable pattern attached to the object being tracked. -* Grid patterns are often used to calibrate cameras and track motion. -## Contour Detection ## -* Contours are defined simply as a curve joining all the continuous points having same colour or intensity. -* Contours are a useful tool for shape analysis and object detection and recognition -* OpenCV has a built in Counter finder function that can also help us differentiate between internal and external contours (eg – grabbing the eyes and smile from a cartoon face). -* Allows us to detect foreground vs background. -## Feature Matching ## -* Feature matching extracts defining key features from an input image (using ideas from corner, edge and contour detection). -* Then using a distance calculation, finds all the matches in a secondary image. -* More advanced methods of detecting matching object in another image, even if the target image is not shown exactly the same image we are searching. -* Feature Matching results: - -![](https://docs.opencv.org/3.4/matcher_result1.jpg) -* Notice how the input image is not exactly what is shown in the secondary image -* 3 methods of feature matching are: - 1. Brute-Force Matching with ORB Descriptors - 1. Brute-Force Matching with SIFT Descriptors and Ratio Test - 1. FLANN based Matcher - -## Watershed Algorithm ## -* Metaphorically, Watershed Algorithm transformation treats the image it operates upon like a topographic map, with the brightness of each point representing it’s height, and finds the line that runs along the tops of ridges. -* Any grayscale image can be viewed as a topographic surface where high intensity denotes peaks and hills while low intensity denotes valleys -* As the “water” rises, depending on the peaks (gradient) nearby, “water” from different valleys (different segments of the image), with different colors could start merge. -* To avoid this merging, the algorithm creates barrier (segment edge boundaries) in locations where “water” merges. -* The algorithm can then fill every isolated valley(local minima) with different colored water(labels). -* Advances algorithm that allows us to segment images into foreground and background -* Also allows us to manually set seeds to choose segments of an image. - * A common example is the use of coins next to each other on a table - * Attempting to segment these coins can be difficult: - - ![](https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQRLGLxjK2fADx4e7Sci8koBkeB0Lh-QtqAdg&usqp=CAU)\ - * It may be unclear to the algorithm if it should be treated as one large object or many small objects. - * The watershed algorithm can be very effective for these sort of problems -## Facial and Eye Detection ## -* Haar Cascades to identify faces in images -* We will be able to very quickly detect if a face is in an image and locate -* However we won’t know who’s face it belongs to. -* We would need a really large dataset and deep learning for facial recognition. -* Main feature types: - -![](https://docs.opencv.org/3.4/haar_features.jpg) -* Each feature is a single value obtained by subtracting sum of pixels under white rectangle from sum of pixels under black rectangle. -* Realistically, our images won’t be perfect lines and edges. -* These features are calculated by: - * **mean(dark region) – mean(light region)** -* A perfect edge would result in a value of one. -* The closer the result is to one, the better the feature. -* The Voila-Jones algorithm solves this by using the integral image. -* Resulting in an O(1) running time of the algorithm -* The algo also saves time by going through a cascade of classifiers. -* This means we will treat the image to a series(cascade)of classifiers based on the simple feature . -* Once an image fails a classifier, we can stop attempting to detect a face. - -### Thank You! +The full code is [here](https://github.com/rakshith48/Open-contributions/blob/master/Rakshith_OpenCV_ObjectDetection.ipynb) From 2082bdc61628061754183107be7baf459e1deb62 Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 16:12:22 +0530 Subject: [PATCH 6/7] Create AbhishekBhosale_Objectdetection_OpenCV.ipynb --- ...hishekBhosale_Objectdetection_OpenCV.ipynb | 276 ++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.ipynb diff --git a/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.ipynb b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.ipynb new file mode 100644 index 000000000..0d7d0433c --- /dev/null +++ b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.ipynb @@ -0,0 +1,276 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import cv2 as cv" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Loading the Haar Cascade Classifier (xml) files and images" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "# Loads all the classifiers\n", + "face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')\n", + "eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml')\n", + "fullbody_cascade = cv.CascadeClassifier('haarcascade_fullbody.xml')\n", + "cars_cascade = cv.CascadeClassifier('cars.xml')\n", + "bus_cascade = cv.CascadeClassifier('bus.xml')\n", + "\n", + "# Loads all the images\n", + "img = cv.imread('face.jpg')\n", + "body = cv.imread('body1.jpg')\n", + "car = cv.imread('cars1.jpeg')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Defining object detection function" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def object_detection(image, cascade, text, color = (255, 0, 0)):\n", + " \n", + " # Our operations on the frame come here\n", + " gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)\n", + " objects = cascade.detectMultiScale(gray, 1.3, 5)\n", + " for (x, y, w, h) in objects:\n", + " \n", + " # Draws rectangle around the objects\n", + " image = cv.rectangle(image, (x,y), (x+w , y+h), color, 2)\n", + " \n", + " # Display text on top of rectangle\n", + " cv.putText(image, text, (x, y-10), cv.FONT_HERSHEY_SIMPLEX, 0.9, color, 2)\n", + " \n", + " # Display the resulting frame\n", + " cv.imshow('img', image)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Face detection and eye detection" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# Detects the faces\n", + "object_detection(img, face_cascade, 'face')\n", + "cv.waitKey(0)\n", + "# Closes the image window\n", + "cv.destroyAllWindows()\n", + "\n", + "# Detects the eyes\n", + "object_detection(img, eye_cascade, 'eye')\n", + "cv.waitKey(0)\n", + "# Closes the image window\n", + "cv.destroyAllWindows()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "cap = cv.VideoCapture(0)\n", + "\n", + "while(True):\n", + " # Capture frame-by-frame\n", + " ret, frame = cap.read()\n", + "\n", + " # Our operations on the frame come here\n", + "# gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)\n", + " \n", + "# faces = face_cascade.detectMultiScale(gray, 1.3, 5)\n", + "# for (x, y, w, h) in faces:\n", + "# frame = cv.rectangle(frame, (x,y), (x+w , y+h), (255, 0, 0), 2)\n", + "# roi_gray = gray[y:y+h, x:x+w]\n", + "# roi_color = frame[y:y+h, x:x+w]\n", + "# eyes = eye_cascade.detectMultiScale(roi_gray)\n", + "# for (ex, ey, ew, eh) in eyes:\n", + "# cv.rectangle(roi_color, (ex,ey), (ex+ew , ey+eh), (0, 255, 0), 2)\n", + "\n", + "# # Display the resulting frame\n", + "# cv.imshow('frame', frame)\n", + "\n", + " object_detection(frame, face_cascade, 'face')\n", + " # Waits for Q key to quit\n", + " if cv.waitKey(1) & 0xFF == ord('q'):\n", + " break\n", + "\n", + "# When everything done, release the capture\n", + "cap.release()\n", + "cv.destroyAllWindows()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Car detection" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# Loads the video\n", + "cap = cv.VideoCapture('cars.avi')\n", + "\n", + "while(True):\n", + " \n", + " # Capture frame-by-frame\n", + " ret, frame = cap.read()\n", + " \n", + " # Breaks at the end of video\n", + " if (type(frame) == type(None)):\n", + " break\n", + " \n", + " # Calls the object detection function\n", + " object_detection(frame, cars_cascade, 'car')\n", + " \n", + " if cv.waitKey(1) & 0xFF == ord('q'):\n", + " break\n", + "\n", + "# When everything done, release the capture\n", + "cap.release()\n", + "cv.destroyAllWindows()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Human detection" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# Loads the video\n", + "cap = cv.VideoCapture('pedestrians.avi')\n", + "\n", + "while(True):\n", + " \n", + " # Capture frame-by-frame\n", + " ret, frame = cap.read()\n", + " \n", + " # Breaks at the end of video\n", + " if (type(frame) == type(None)):\n", + " break\n", + " \n", + " # Calls the object detection function\n", + " object_detection(frame, fullbody_cascade, 'human')\n", + " \n", + " if cv.waitKey(1) & 0xFF == ord('q'):\n", + " break\n", + "\n", + "# When everything done, release the capture\n", + "cap.release()\n", + "cv.destroyAllWindows()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bus detection" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# Loads the video\n", + "cap = cv.VideoCapture('bus1.mp4')\n", + "\n", + "while(True):\n", + " \n", + " # Capture frame-by-frame\n", + " ret, frame = cap.read()\n", + " \n", + " # Breaks at the end of video\n", + " if (type(frame) == type(None)):\n", + " break\n", + " \n", + " # Calls the object detection function\n", + " object_detection(frame, bus_cascade, 'bus')\n", + " \n", + " if cv.waitKey(1) & 0xFF == ord('q'):\n", + " break\n", + "\n", + "# When everything done, release the capture\n", + "cap.release()\n", + "cv.destroyAllWindows()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From d4c170d1ca4672be35dcd01e9b7ca829289ae84a Mon Sep 17 00:00:00 2001 From: Abhixtrent28 Date: Sun, 18 Jul 2021 16:14:28 +0530 Subject: [PATCH 7/7] Update AbhishekBhosale_Objectdetection_OpenCV.md --- AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md index f449b57e9..491d86065 100644 --- a/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md +++ b/AbhishekBhosale_C#/AbhishekBhosale_Objectdetection_OpenCV.md @@ -37,4 +37,4 @@ The steps are as follows: * Now we need to do the same process as we did for an image. -The full code is [here](https://github.com/rakshith48/Open-contributions/blob/master/Rakshith_OpenCV_ObjectDetection.ipynb) +The full code is [here](https://github.com/Abhixtrent28/Open-contributions/blob/2082bdc61628061754183107be7baf459e1deb62/AbhishekBhosale_C%23/AbhishekBhosale_Objectdetection_OpenCV.ipynb)