title: How to get single bounding box while detecting face using opencv and python
body: <p>I do not get perfect accuracy while detecting a face using opencv.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import cv2
  
  #create a cascadeclassifier object
  face_cascade = cv2.CascadeClassifier("C:/Users/yash/AppData/Local/Programs/Python/Python35/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml")
  #create a cascade classifier.it will contain the features of the face
  
  #reading the image as it is
  img = cv2.imread("profile.JPG")
  
  #reading the image as gray_scale image
  gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #converting colored image to gray scale
  
  #search the co-ordinates of the image
  faces = face_cascade.detectMultiScale(gray_img,scaleFactor = 1.05,minNeighbors=5)
  #scaleFactor = decreases the shape value by 5%,until the face is found .smaller this value , the greater is the accuracy.
  #detectMultiScale = method to search for the face rectangle co-ordinates
  
  #print(type(faces))
  #print(faces)
  
  for x,y,w,h in faces:
      img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3)
  
  resized_img = cv2.resize(img,(int(img.shape[1]/2) , int(img.shape[0]/2)))    
  cv2.imshow("face detection",resized_img)
  
  cv2.waitKey(0)
  
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Here there is the <a href="https://i.stack.imgur.com/eDayT.jpg" rel="nofollow noreferrer">image</a> I am trying to get perfect accuracy on.</p>