title: OpenCV Drawing Contour Error Assertion Failed
body: <p>So I am trying to follow guide on how to scan a document in <a href="https://www.pyimagesearch.com/2014/09/01/build-kick-ass-mobile-document-scanner-just-5-minutes/" rel="nofollow noreferrer">https://www.pyimagesearch.com/2014/09/01/build-kick-ass-mobile-document-scanner-just-5-minutes/</a>
  exactly on the step 2 process where i am supposed to find the contour and draw it to the image, i got an "Assertion Failed" error on drawContour function</p>
  
  <p>The guide did not have</p>
  
  <blockquote>
    <p>screenCnt = None</p>
  </blockquote>
  
  <p>so at first i got Error like screenCnt did not exist</p>
  
  <p>after i add it, got Assertion Failed instead
  even though i used the same image as the guide and tried another image too</p>
  
  <pre><code>#find contour
  cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
  cnts = imutils.grab_contours(cnts)
  cnts = cnts[0] if imutils.is_cv2() else cnts[1]
  cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5]
  screenCnt = None
  
  # loop over the contours
  for c in cnts:
      peri = cv2.arcLength(c, True)
      approx = cv2.approxPolyDP(c, 0.02 * peri, True)
      if len(approx) == 4:
          screenCnt = approx
          break
  
  #draw contour
  cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)
  </code></pre>
  
  <p>Here is what i got :</p>
  
  <blockquote>
    <p>Traceback (most recent call last): File
    "C:/Users/User/PycharmProjects/learn/project/app.py", line 218, in
     cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)</p>
    
    <p>cv2.error: OpenCV(4.1.0)
    C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2606:
    error: (-215:Assertion failed) reader.ptr != NULL in function
    'cvDrawContours'</p>
  </blockquote>
  
  <p>Any solution for this ? Thanks before</p>