title: How to simple crop the bounding box in python opencv
body: <p>I am trying to learn opencv and implementing a research project by testing some used cases. I am trying to crop the bounding box of the inside the image using python opencv . I have successfully created the bounding box but failed in crop</p>
  
  <p>this is the image </p>
  
  <p><a href="https://i.stack.imgur.com/Vb3mO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Vb3mO.png" alt="enter image description here"></a></p>
  
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  img = cv2.imread("Segmentacion/Img_183.png")
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)    
  dst = cv2.Canny(gray, 0, 150)
  blured = cv2.blur(dst, (5,5), 0)    
  MIN_CONTOUR_AREA=200
  img_thresh = cv2.adaptiveThreshold(blured, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
  Contours,imgContours = cv2.findContours(img_thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  for contour in Contours:
      if cv2.contourArea(contour) &gt; MIN_CONTOUR_AREA:
          [X, Y, W, H] = cv2.boundingRect(contour)
          box=cv2.rectangle(img, (X, Y), (X + W, Y + H), (0,0,255), 2)
  
  cropped_image = img[X:W, Y:H]
  print([X,Y,W,H])
  cv2.imwrite('contour.png', cropped_image )
  </code></pre>