title: detect rectangle in image and crop
body: <p>I have lots of scanned images of handwritten digit inside a rectangle(small one).</p>
  <p><a href="https://i.stack.imgur.com/ScexE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ScexE.jpg" alt="enter image description here" /></a></p>
  <p>Please help me to crop each image containing digits and save them by giving the same name to each row.</p>
  <pre><code>import cv2
  
  img = cv2.imread('Data\Scan_20170612_4.jpg')
  
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  gray = cv2.bilateralFilter(gray, 11, 17, 17)
  edged = cv2.Canny(gray, 30, 200)
  
  _, contours, hierarchy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
  
  i = 0
  for c in contours:
      peri = cv2.arcLength(c, True)
      approx = cv2.approxPolyDP(c, 0.09 * peri, True)
  
      if len(approx) == 4:
          screenCnt = approx
          cv2.drawContours(img, [screenCnt], -1, (0, 255, 0), 3)
          cv2.imwrite('cropped\\' + str(i) + '_img.jpg', img)
  
          i += 1
  </code></pre>