This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <map> | |
#include <vector> | |
using namespace std; | |
class Snake{ | |
int end; | |
public: | |
Snake() {} | |
Snake(int anEnd) : end(anEnd) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Face Detection | |
-> Using method used by Viola and jones (real time object detection) | |
-> We will use lot of images with positive faces and negative faces and will train the cascade file to detect the faces | |
-> In Open CV we dont have to actually do this we can use trained cascade file to detect things | |
''' | |
import cv2 | |
faceCascade = cv2.CascadeClassifier("Resources/haarcascade_frontalface_default.xml") | |
img = cv2.imread("Resources/lena.png") | |
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enable=False | |
''' | |
Reading Image | |
''' | |
if enable: | |
import cv2 | |
img = cv2.imread("Resources/lena.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
path = 'Resources/shapes.png' | |
img = cv2.imread(path) | |
imgContour = img.copy() | |
def stackImages(scale, imgArray): | |
rows = len(imgArray) | |
cols = len(imgArray[0]) | |
rowsAvailable = isinstance(imgArray[0], list) | |
width = imgArray[0][0].shape[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
''' | |
Here we will try to detect colors in the image | |
''' | |
def empty(a): | |
pass | |
# Function used to stack the images | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Join Images | |
We will try to put all images in one window | |
""" | |
import cv2 | |
import numpy as np | |
#Function used to stack the images | |
def stackImages(scale, imgArray): | |
rows = len(imgArray) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
img = np.zeros((512,512)) # gray scale image (can check by shape also ) | |
# To add the color make it 3 channel | |
img = np.zeros((512,512,3)) | |
#img[:]=255,0,0 | |
''' | |
To Draw the line ,Rectange ,Circle and put text on images | |
''' | |
cv2.line(img,(0,0),(300,300),(0,255,0),3) # start point ,end point and thickness |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
img = cv2.imread("Resources/lambo.PNG") | |
cv2.imshow("Image ", img) | |
print(img.shape) | |
''' | |
Resizing the image | |
''' | |
imgResizeinc = cv2.resize(img,(600,600)) | |
print(imgResizeinc.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
img = cv2.imread("Resources/lena.png") | |
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # converting to it gray scale image | |
cv2.imshow("GrayScale", imgGray) | |
# To Blur the image we will use Gaussian Blur to blur | |
imgBlur = cv2.GaussianBlur(imgGray,(7,7),0) # as a paramter kernel size is passed | |
cv2.imshow("GrayScaleBlur", imgBlur) | |
# To detect the edges we use the Canny Filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
vid = cv2.VideoCapture(0) # instead of file path we will use the id of the device (webcam) | |
#now we define some specific parameter for the webcam | |
vid.set(3,640) | |
vid.set(4,480) | |
#Rest Code is same as basic video read | |
while vid.isOpened(): # Used to check if camera is opened or not | |
success,img=vid.read() | |
if success: | |
cv2.imshow("Video",img) |
NewerOlder