Python, eliminate small contours
I'm attempting to do the same thing as https://answers.opencv.org/question/1... but in Python and I am working from their solution. I am getting an error "SystemError: <built-in drawcontours="" function=""> returned NULL without setting an error". I also suspect I am doing other things wrong as I don't know what the Vector lines are for and I removed the Point() at the end of the findCountours function as it was causing errors. Here is what I have, I appreciate any help:</built-in>
import numpy as np
import cv2
# Mat result
# vector<vector<Point> >contours
# vector<Vec4i>hierarchy
savedContour = -1
maxArea = 0.0
# load image
image = cv2.imread('vlcsnap2.png')
binarayImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Find the largest contour
contours, hierarchy = cv2.findContours(binarayImage, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for i in range(0, len(contours)):
area = cv2.contourArea(contours[i])
if area > maxArea:
maxArea = area
savedContour = i
# Create mask
result = cv2.drawContours(binarayImage, savedContour, 255, cv2.FILLED, 8)
# apply the mask:
binarayImage &= result
#show image
cv2.imshow("Result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()
Ultimately, I'm trying to get from here:
to Here: