title: Merging overlapping rectangle with OpenCV
body: <p>I'm using two Haar cascade algorithms (frontal and profile) with OpenCV at the same time to improve the face detection.</p>
  
  <p>Unfortunately, the detection is not working correctly and I don't know how to fix it. The return value is 2 (on a picture with 5 faces, normally detected) and all the rectangles have disappeared.</p>
  
  <p>This is the expected result (without the overlapping rectangles):</p>
  
  <p><a href="https://i.stack.imgur.com/oZZsW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oZZsW.jpg" alt="image"></a></p>
  
  <p><a href="https://i.stack.imgur.com/UC2ub.jpg" rel="nofollow noreferrer">This is the original picture (and also the result.jpg) if you want to make your own test.</a></p>
  
  <p>This is the code :</p>
  
  <pre><code>import cv2
  import numpy as np
  
  image=cv2.imread("/home/pi/Downloads/test.jpg")
  face_cascade=cv2.CascadeClassifier("/home/pi/opencv-3.4.0/data/haarcascades/haarcascade_frontalface_alt.xml")
  profil_cascade=cv2.CascadeClassifier("/home/pi/opencv-3.4.0/data/haarcascades/haarcascade_profileface_alt.xml")
  
  gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
  face=face_cascade.detectMultiScale(gray, 1.06, 5)
  profil=profil_cascade.detectMultiScale(gray, 1.1, 5)
  
  combined_array=np.append(face, profil, axis=0)
  combined_list=combined_array.tolist()
  result=cv2.groupRectangles(combined_list,2)
  
  print("I've found "+str(len(result))+ " face(s)")
  
  for (x,y,w,h) in result[0]:
      cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)
  
  cv2.imwrite("/home/pi/Download/result.jpg", image)
  </code></pre>