From 89aaf83d53b3a93d196e9056bb0500f530444bdf Mon Sep 17 00:00:00 2001 From: Shubhamdeep Jha <41606999+TheDudeThatCode@users.noreply.github.com> Date: Thu, 8 Oct 2020 13:54:49 +0530 Subject: [PATCH] Update detect.py --- detect.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/detect.py b/detect.py index bdfd7b0..1f54702 100644 --- a/detect.py +++ b/detect.py @@ -1,31 +1,40 @@ import numpy as np import cv2 as cv -body_cascade = cv.CascadeClassifier('haarcascade_fullbody.xml') -upper_cascade = cv.CascadeClassifier('haarcascade_upperbody.xml') -lower_cascade = cv.CascadeClassifier('haarcascade_lowerbody.xml') + +import imutils + +body_cascade = cv.CascadeClassifier( + 'haarcascade_fullbody.xml') +upper_cascade = cv.CascadeClassifier( + 'haarcascade_upperbody.xml') +lower_cascade = cv.CascadeClassifier( + 'haarcascade_lowerbody.xml') img = cv.imread('kok.jpeg') + +img = imutils.resize(img, + width=min(600, img.shape[1])) gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) -bodies = body_cascade.detectMultiScale(gray, 1.3, 5) -upper = upper_cascade.detectMultiScale(gray, 1.3, 5) -lower = lower_cascade.detectMultiScale(gray, 1.3, 5) +bodies = body_cascade.detectMultiScale(gray, 1.0485258, 3) +upper = upper_cascade.detectMultiScale(gray, 1.0485258, 3) +lower = lower_cascade.detectMultiScale(gray, 1.0485258, 3) -for (x,y,w,h) in bodies: - cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) +for (x, y, w, h) in bodies: + cv.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] -for (x,y,w,h) in upper: - cv.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) +for (x, y, w, h) in upper: + cv.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) roi_gray = gray[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w] -for (x,y,w,h) in lower: - cv.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2) +for (x, y, w, h) in lower: + cv.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 2) roi_gray = gray[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w] -cv.imshow('img',img) +cv.imshow('img', img) cv.waitKey(0) -cv.destroyAllWindows() \ No newline at end of file +cv.destroyAllWindows()