From 6df803ccf280b7cc04e55af379fa0efa3ef36f72 Mon Sep 17 00:00:00 2001 From: yash15601 Date: Sun, 23 Aug 2020 19:31:57 +0530 Subject: [PATCH 1/4] added files --- .../Car_detection/car_detection.py | 13 ++++++++++++ .../Face_detection/Face_detection.py | 21 +++++++++++++++++++ Image-Processing/Face_detection/README.md | 20 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 Image-Processing/Car_detection/car_detection.py create mode 100644 Image-Processing/Face_detection/Face_detection.py create mode 100644 Image-Processing/Face_detection/README.md diff --git a/Image-Processing/Car_detection/car_detection.py b/Image-Processing/Car_detection/car_detection.py new file mode 100644 index 00000000..ee327b81 --- /dev/null +++ b/Image-Processing/Car_detection/car_detection.py @@ -0,0 +1,13 @@ +import cv2 +img_file = "car2.jpg" +classifier_car = 'car_dect.xml' #trained car data Link:"https://gist.github.com/199995/37e1e0af2bf8965e8058a9dfa3285bc6" +img=cv2.imread(img_file) #create image reader +black_and_white = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #convert image black and white i.e. grayscale +car_tracker = cv2.CascadeClassifier(classifier_car) #create classifier +cars = car_tracker.detectMultiScale(black_and_white) #detect cars + +for (x,y,w,h) in cars: ## the above variable will return 4 cordinates i.e height,width,postionx,positiony + cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3) ##this loop will create grren rectangle when car is detected + +cv2.imshow('car image',img) #display image +cv2.waitKey() \ No newline at end of file diff --git a/Image-Processing/Face_detection/Face_detection.py b/Image-Processing/Face_detection/Face_detection.py new file mode 100644 index 00000000..0ad85b8b --- /dev/null +++ b/Image-Processing/Face_detection/Face_detection.py @@ -0,0 +1,21 @@ +import cv2 ##Import OpenCv + +face = cv2.CascadeClassifier('C:/Users/91976/Desktop/haarcascade_frontalface_default.xml') ##'haarcascade_frontalface_default.xml' an opencv classifier for face detection + +cap = cv2.VideoCapture(0) ##capturevideo by webcam or your laptop default cam for webcame => 1 and for defalut laptop camera => 2 + +while True: + sucess,img=cap.read() + + gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ##before detecting face you should convert img or video into gray image + faces=face.detectMultiScale(gray,1.1,5) + + for ( x , y , w , h) in faces: + cv2.rectangle(img,( x , y ),( x*w , y*h ),(255,0,0),2) ##will create the rectangle where face is detected + + cv2.imshow('img',img) + k=cv2.waitKey(30) & 0xff + if k==27: + break + +cap.release() \ No newline at end of file diff --git a/Image-Processing/Face_detection/README.md b/Image-Processing/Face_detection/README.md new file mode 100644 index 00000000..48f7eb5a --- /dev/null +++ b/Image-Processing/Face_detection/README.md @@ -0,0 +1,20 @@ +# Image Processing + +Image Processing is most commonly termed as 'Digital Image Processing' and the domain in which it is frequently used is 'Computer Vision'. +Don't be confused - we are going to talk about both of these terms and how they connect. +Both Image Processing algorithms and Computer Vision (CV) algorithms take an image as input; however, in image processing, +the output is also an image, whereas in computer vision the output can be some features/information about the image. + +## OpenCV + +![](https://logodix.com/logo/1989939.png) + +## Installation + +### Windows + + $ pip install opencv-python +### MacOS + $ brew install opencv3 --with-contrib --with-python3 +### Linux + $ sudo apt-get install libopencv-dev python-opencv From c6c06c701b591a45e1c54c2f319e9c9427aa4060 Mon Sep 17 00:00:00 2001 From: Yash Patel <49101492+ryuk156@users.noreply.github.com> Date: Thu, 3 Sep 2020 08:09:04 +0530 Subject: [PATCH 2/4] deleted car_detection.py --- Image-Processing/Car_detection/car_detection.py | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 Image-Processing/Car_detection/car_detection.py diff --git a/Image-Processing/Car_detection/car_detection.py b/Image-Processing/Car_detection/car_detection.py deleted file mode 100644 index ee327b81..00000000 --- a/Image-Processing/Car_detection/car_detection.py +++ /dev/null @@ -1,13 +0,0 @@ -import cv2 -img_file = "car2.jpg" -classifier_car = 'car_dect.xml' #trained car data Link:"https://gist.github.com/199995/37e1e0af2bf8965e8058a9dfa3285bc6" -img=cv2.imread(img_file) #create image reader -black_and_white = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #convert image black and white i.e. grayscale -car_tracker = cv2.CascadeClassifier(classifier_car) #create classifier -cars = car_tracker.detectMultiScale(black_and_white) #detect cars - -for (x,y,w,h) in cars: ## the above variable will return 4 cordinates i.e height,width,postionx,positiony - cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3) ##this loop will create grren rectangle when car is detected - -cv2.imshow('car image',img) #display image -cv2.waitKey() \ No newline at end of file From 6067061e4c41e6f7d6daa5cddbb844e9018bbaae Mon Sep 17 00:00:00 2001 From: Yash Patel <49101492+ryuk156@users.noreply.github.com> Date: Thu, 3 Sep 2020 08:11:38 +0530 Subject: [PATCH 3/4] updated face_detection.py --- .../Face_detection/Face_detection.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Image-Processing/Face_detection/Face_detection.py b/Image-Processing/Face_detection/Face_detection.py index 0ad85b8b..ce00c5c1 100644 --- a/Image-Processing/Face_detection/Face_detection.py +++ b/Image-Processing/Face_detection/Face_detection.py @@ -1,21 +1,19 @@ import cv2 ##Import OpenCv face = cv2.CascadeClassifier('C:/Users/91976/Desktop/haarcascade_frontalface_default.xml') ##'haarcascade_frontalface_default.xml' an opencv classifier for face detection - -cap = cv2.VideoCapture(0) ##capturevideo by webcam or your laptop default cam for webcame => 1 and for defalut laptop camera => 2 +cap = cv2.VideoCapture(0) ##capturevideo by webcam or your laptop default cam for webcame => 1 and for defalut laptop camera => 2 while True: - sucess,img=cap.read() - - gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ##before detecting face you should convert img or video into gray image - faces=face.detectMultiScale(gray,1.1,5) + sucess,img = cap.read() + gray = cv2.cvtColor( img , cv2.COLOR_BGR2GRAY ) ##before detecting face you should convert img or video into gray image + faces = face.detectMultiScale( gray ,1.1 ,5 ) for ( x , y , w , h) in faces: cv2.rectangle(img,( x , y ),( x*w , y*h ),(255,0,0),2) ##will create the rectangle where face is detected cv2.imshow('img',img) - k=cv2.waitKey(30) & 0xff - if k==27: + k = cv2.waitKey(30) & 0xff + if k == 27: break -cap.release() \ No newline at end of file +cap.release() From fac39eb3916b92951b47b26d3169f1f984e4fcf8 Mon Sep 17 00:00:00 2001 From: Yash Patel <49101492+ryuk156@users.noreply.github.com> Date: Thu, 3 Sep 2020 08:12:16 +0530 Subject: [PATCH 4/4] Update Face_detection.py --- Image-Processing/Face_detection/Face_detection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Image-Processing/Face_detection/Face_detection.py b/Image-Processing/Face_detection/Face_detection.py index ce00c5c1..0d9218d6 100644 --- a/Image-Processing/Face_detection/Face_detection.py +++ b/Image-Processing/Face_detection/Face_detection.py @@ -4,7 +4,7 @@ cap = cv2.VideoCapture(0) ##capturevideo by webcam or your laptop default cam for webcame => 1 and for defalut laptop camera => 2 while True: - sucess,img = cap.read() + sucess , img = cap.read() gray = cv2.cvtColor( img , cv2.COLOR_BGR2GRAY ) ##before detecting face you should convert img or video into gray image faces = face.detectMultiScale( gray ,1.1 ,5 )