From 5da407c1bd15f8a2e72926867d1fbb160a586298 Mon Sep 17 00:00:00 2001 From: Yash Patel <49101492+ryuk156@users.noreply.github.com> Date: Sun, 16 Aug 2020 13:59:43 +0530 Subject: [PATCH 1/3] Create car_detection_image.py --- Image-Processing/car_detection_image.py | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Image-Processing/car_detection_image.py diff --git a/Image-Processing/car_detection_image.py b/Image-Processing/car_detection_image.py new file mode 100644 index 00000000..14c10449 --- /dev/null +++ b/Image-Processing/car_detection_image.py @@ -0,0 +1,35 @@ +import cv2 + +img_file="car2.jpg" + +#trained car data Link:"https://gist.github.com/199995/37e1e0af2bf8965e8058a9dfa3285bc6" +classifier_car='car_dect.xml' + +#create image reader +img=cv2.imread(img_file) + +#convert image black and white i.e. grayscale +black_and_white=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) + +#create classifier +car_tracker=cv2.CascadeClassifier(classifier_car) + +#detect cars +cars=car_tracker.detectMultiScale(black_and_white) + + +## the above variable will return 4 cordinates i.e height,width,postionx,positiony + + +for (x,y,w,h) in cars: + cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3) ##this loop will create grren rectangle when car is detected + + + + + +#display image +cv2.imshow('car image',img) + +cv2.waitKey() + From 7f65b64a3ca3286ad60224b4fbf15762111e7fb6 Mon Sep 17 00:00:00 2001 From: Yash Patel <49101492+ryuk156@users.noreply.github.com> Date: Sun, 16 Aug 2020 16:18:55 +0530 Subject: [PATCH 2/3] Update car_detection_image.py --- Image-Processing/car_detection_image.py | 37 +++++-------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/Image-Processing/car_detection_image.py b/Image-Processing/car_detection_image.py index 14c10449..109668c0 100644 --- a/Image-Processing/car_detection_image.py +++ b/Image-Processing/car_detection_image.py @@ -1,35 +1,12 @@ import cv2 - img_file="car2.jpg" - -#trained car data Link:"https://gist.github.com/199995/37e1e0af2bf8965e8058a9dfa3285bc6" -classifier_car='car_dect.xml' - -#create image reader -img=cv2.imread(img_file) - -#convert image black and white i.e. grayscale -black_and_white=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) - -#create classifier -car_tracker=cv2.CascadeClassifier(classifier_car) - -#detect cars -cars=car_tracker.detectMultiScale(black_and_white) - - -## the above variable will return 4 cordinates i.e height,width,postionx,positiony - - -for (x,y,w,h) in cars: +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 - - - - - -#display image -cv2.imshow('car image',img) - +cv2.imshow('car image',img) #display image cv2.waitKey() From 99a5fdbb49441d8d427f04fa7c770f3123a942bb Mon Sep 17 00:00:00 2001 From: Yash Patel <49101492+ryuk156@users.noreply.github.com> Date: Mon, 17 Aug 2020 23:27:52 +0530 Subject: [PATCH 3/3] Update car_detection_image.py --- Image-Processing/car_detection_image.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Image-Processing/car_detection_image.py b/Image-Processing/car_detection_image.py index 109668c0..1ab991a1 100644 --- a/Image-Processing/car_detection_image.py +++ b/Image-Processing/car_detection_image.py @@ -1,12 +1,14 @@ import cv2 -img_file="car2.jpg" -classifier_car='car_dect.xml' #trained car data Link:"https://gist.github.com/199995/37e1e0af2bf8965e8058a9dfa3285bc6" +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 +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()