From e89ab955d8f599f70d6c331aa6c16040e4b7e4a3 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 6 Oct 2018 19:42:59 +0530 Subject: Initial Commit for Opencv --- opencv.html.markdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 opencv.html.markdown (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown new file mode 100644 index 00000000..75ef7168 --- /dev/null +++ b/opencv.html.markdown @@ -0,0 +1,15 @@ +--- +language: c++ +filename: learncpp.cpp +contributors: + - ["Yogesh Ojha", "http://github.com/yogeshojha"] +--- +# Opencv + +Further Reading: + +An up-to-date language reference can be found at + + +Additional resources may be found at + -- cgit v1.2.3 From dcaec93a0e4b629bb07fcdd72dcb4c71b0d52530 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 6 Oct 2018 20:09:15 +0530 Subject: Update on opencv until read image --- opencv.html.markdown | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index 75ef7168..7e048df5 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -1,15 +1,52 @@ --- -language: c++ -filename: learncpp.cpp +language: c++/python +filename: learnopencv.py contributors: - ["Yogesh Ojha", "http://github.com/yogeshojha"] --- -# Opencv +### Opencv + +OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real-time computer vision. +Originally developed by Intel, it was later supported by Willow Garage then Itseez (which was later acquired by Intel). +Opencv currently supports wide variety of languages like, C++, Python, Java etc + +#### Installation +Please refer to these articles for installation of OpenCV on your computer. +* Windows Installation Instructions: + + +* Mac Installation Instructions (High Sierra): +https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a + +* Linux Installation Instructions (Ubuntu 18.04): + + +### Here we will be focusing on python implementation of OpenCV + +* __Reading image in OpenCV__ +``` +import cv2 +img = cv2.imread('cat.jpg') +# Simple isn't it? +# Displaying the image +# imshow() function is used to display the image +cv2.imshow('Image',img) +# Your first arguement is the title of the window and second parameter is image +# If you are getting error, Object Type None, your image path may be wrong. Please recheck the pack to the image +cv2.waitKey(0) +# waitKey() is a keyboard binding function and takes arguement in milliseconds. For GUI events you MUST use waitKey() function. +``` Further Reading: An up-to-date language reference can be found at - + Additional resources may be found at + +Good OpenCv Tutorials + + + + -- cgit v1.2.3 From 9169335e5bdf66916619a2565ba56235bc4cfb00 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 6 Oct 2018 22:19:52 +0530 Subject: Drawing functions added --- opencv.html.markdown | 63 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index 7e048df5..45046af6 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -1,5 +1,5 @@ --- -language: c++/python +language: python filename: learnopencv.py contributors: - ["Yogesh Ojha", "http://github.com/yogeshojha"] @@ -23,11 +23,11 @@ https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-pyt ### Here we will be focusing on python implementation of OpenCV -* __Reading image in OpenCV__ ``` +# Reading image in OpenCV import cv2 img = cv2.imread('cat.jpg') -# Simple isn't it? + # Displaying the image # imshow() function is used to display the image cv2.imshow('Image',img) @@ -35,10 +35,67 @@ cv2.imshow('Image',img) # If you are getting error, Object Type None, your image path may be wrong. Please recheck the pack to the image cv2.waitKey(0) # waitKey() is a keyboard binding function and takes arguement in milliseconds. For GUI events you MUST use waitKey() function. + +# Writing an image +cv2.imwrite('catgray.png',img) +# first arguement is the file name and second is the image + +# Convert image to grayscale +gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + +# Capturing Video from Webcam +cap = cv2.VideoCapture(0) +#0 is your camera, if you have multiple camera, you need to enter their id +while(True): + # Capturing frame-by-frame + _, frame = cap.read() + cv2.imshow('Frame',frame) + # When user presses q -> quit + if cv2.waitKey(1) & 0xFF == ord('q'): + break +# Camera must be released +cap.release() + +# Playing Video from file +cap = cv2.VideoCapture('movie.mp4') +while(cap.isOpened()): + _, frame = cap.read() + # Play the video in grayscale + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + cv2.imshow('frame',gray) + if cv2.waitKey(1) & 0xFF == ord('q'): + break +cap.release() + +# Drawing The Line in OpenCV +# cv2.line(img,(x,y),(x1,y1),(color->r,g,b->0 to 255),thickness) +cv2.line(img,(0,0),(511,511),(255,0,0),5) + +# Drawing Rectangle +# cv2.rectangle(img,(x,y),(x1,y1),(color->r,g,b->0 to 255),thickness) +# thickness = -1 used for filling the rectangle +cv2.rectangle(img,(384,0),(510,128),(0,255,0),3) + +# Drawing Circle +cv2.circle(img,(xCenter,yCenter), radius, (color->r,g,b->0 to 255), thickness) +cv2.circle(img,(200,90), 100, (0,0,255), -1) + +# Drawing Ellipse +cv2.ellipse(img,(256,256),(100,50),0,0,180,255,-1) + +# Adding Text On Images +cv2.putText(img,"Hello World!!!", (x,y), cv2.FONT_HERSHEY_SIMPLEX, 2, 255) + + +cv2.destroyAllWindows() +# destroyAllWindows() destroys all windows. If you wish to destroy specific window pass the exact name of window you created. ``` Further Reading: +OpenCV drawing Functions + + An up-to-date language reference can be found at -- cgit v1.2.3 From 8b1f80c472748359da442bd66232aae611610f50 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 6 Oct 2018 22:33:37 +0530 Subject: added haar cascades, and image processing --- opencv.html.markdown | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index 45046af6..4c52595e 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -86,13 +86,59 @@ cv2.ellipse(img,(256,256),(100,50),0,0,180,255,-1) # Adding Text On Images cv2.putText(img,"Hello World!!!", (x,y), cv2.FONT_HERSHEY_SIMPLEX, 2, 255) +# Blending Images +img1 = cv2.imread('cat.png') +img2 = cv2.imread('openCV.jpg') +dst = cv2.addWeighted(img1,0.5,img2,0.5,0) + +# Thresholding image +# Binary Thresholding +_,thresImg = cv2.threshold(img,127,255,cv2.THRESH_BINARY) +# Adaptive Thresholding +adapThres = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2) + +# Blur Image +# Gaussian Blur +blur = cv2.GaussianBlur(img,(5,5),0) +# Median Blur +medianBlur = cv2.medianBlur(img,5) + +# Canny Edge Detection +img = cv2.imread('cat.jpg',0) +edges = cv2.Canny(img,100,200) + +# Face Detection using Haar Cascades +# Download Haar Cascades from https://github.com/opencv/opencv/blob/master/data/haarcascades/ +import cv2 +import numpy as np +face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') +eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') + +img = cv2.imread('human.jpg') +gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + +aces = face_cascade.detectMultiScale(gray, 1.3, 5) +for (x,y,w,h) in faces: + cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) + roi_gray = gray[y:y+h, x:x+w] + roi_color = img[y:y+h, x:x+w] + eyes = eye_cascade.detectMultiScale(roi_gray) + for (ex,ey,ew,eh) in eyes: + cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2) + +cv2.imshow('img',img) +cv2.waitKey(0) cv2.destroyAllWindows() -# destroyAllWindows() destroys all windows. If you wish to destroy specific window pass the exact name of window you created. +# destroyAllWindows() destroys all windows. +# If you wish to destroy specific window pass the exact name of window you created. ``` Further Reading: +Download Cascade from + + OpenCV drawing Functions -- cgit v1.2.3 From 2a6ca9f3ff36203becd1cbeaf5e4a6878d85bc7e Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Mon, 8 Oct 2018 17:30:26 +0530 Subject: Update opencv.html.markdown --- opencv.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index 4c52595e..aa26ecc0 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -1,5 +1,6 @@ --- -language: python +category: tool +tool: OpenCV filename: learnopencv.py contributors: - ["Yogesh Ojha", "http://github.com/yogeshojha"] -- cgit v1.2.3 From 31e4b9653966df83d5333419b80384933de9367a Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Wed, 10 Oct 2018 20:06:34 +0530 Subject: Made Necessary Changes on Markdown --- opencv.html.markdown | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index aa26ecc0..7b61d2cd 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -13,18 +13,11 @@ Opencv currently supports wide variety of languages like, C++, Python, Java etc #### Installation Please refer to these articles for installation of OpenCV on your computer. -* Windows Installation Instructions: - - -* Mac Installation Instructions (High Sierra): -https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a - -* Linux Installation Instructions (Ubuntu 18.04): - - +* Windows Installation Instructions: [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows] +* Mac Installation Instructions (High Sierra): [https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a] +* Linux Installation Instructions (Ubuntu 18.04): [https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv] ### Here we will be focusing on python implementation of OpenCV - -``` +```python # Reading image in OpenCV import cv2 img = cv2.imread('cat.jpg') @@ -135,22 +128,14 @@ cv2.destroyAllWindows() # If you wish to destroy specific window pass the exact name of window you created. ``` -Further Reading: - -Download Cascade from - - -OpenCV drawing Functions - - -An up-to-date language reference can be found at - - -Additional resources may be found at - - -Good OpenCv Tutorials - - - - +### Further Reading: + +* Download Cascade from [https://github.com/opencv/opencv/blob/master/data/haarcascades] +* OpenCV drawing Functions [https://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html] +* An up-to-date language reference can be found at [https://opencv.org] +* Additional resources may be found at [https://en.wikipedia.org/wiki/OpenCV] +* Good OpenCv Tutorials + * [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html] + * [https://realpython.com/python-opencv-color-spaces] + * [https://pyimagesearch.com] + * [https://www.learnopencv.com] -- cgit v1.2.3 From 6f7caa6caac87f2086277fb0856ea668717ab18a Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 13 Oct 2018 20:11:59 +0530 Subject: Update opencv.html.markdown --- opencv.html.markdown | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index 7b61d2cd..9f81ee28 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -13,9 +13,10 @@ Opencv currently supports wide variety of languages like, C++, Python, Java etc #### Installation Please refer to these articles for installation of OpenCV on your computer. -* Windows Installation Instructions: [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows] -* Mac Installation Instructions (High Sierra): [https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a] -* Linux Installation Instructions (Ubuntu 18.04): [https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv] + +* Windows Installation Instructions: [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows]() +* Mac Installation Instructions (High Sierra): [https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a]() +* Linux Installation Instructions (Ubuntu 18.04): [https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv]() ### Here we will be focusing on python implementation of OpenCV ```python # Reading image in OpenCV @@ -130,12 +131,12 @@ cv2.destroyAllWindows() ### Further Reading: -* Download Cascade from [https://github.com/opencv/opencv/blob/master/data/haarcascades] -* OpenCV drawing Functions [https://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html] -* An up-to-date language reference can be found at [https://opencv.org] -* Additional resources may be found at [https://en.wikipedia.org/wiki/OpenCV] +* Download Cascade from [https://github.com/opencv/opencv/blob/master/data/haarcascades]() +* OpenCV drawing Functions [https://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html]() +* An up-to-date language reference can be found at [https://opencv.org]() +* Additional resources may be found at [https://en.wikipedia.org/wiki/OpenCV]() * Good OpenCv Tutorials - * [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html] - * [https://realpython.com/python-opencv-color-spaces] - * [https://pyimagesearch.com] - * [https://www.learnopencv.com] + * [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html]() + * [https://realpython.com/python-opencv-color-spaces]() + * [https://pyimagesearch.com]() + * [https://www.learnopencv.com]() -- cgit v1.2.3 From 76863b963ed57c5b75b9447caba283946802bbc1 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sun, 14 Oct 2018 12:40:30 +0530 Subject: Added new empty line --- opencv.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'opencv.html.markdown') diff --git a/opencv.html.markdown b/opencv.html.markdown index 9f81ee28..f8763b35 100644 --- a/opencv.html.markdown +++ b/opencv.html.markdown @@ -17,7 +17,9 @@ Please refer to these articles for installation of OpenCV on your computer. * Windows Installation Instructions: [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows]() * Mac Installation Instructions (High Sierra): [https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a]() * Linux Installation Instructions (Ubuntu 18.04): [https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv]() + ### Here we will be focusing on python implementation of OpenCV + ```python # Reading image in OpenCV import cv2 -- cgit v1.2.3