Ask Your Question

Revision history [back]

Error with findContours()

I'm getting the following error here:

error: (-215) scn == 3 || scn == 4 in function cv::cvtColor This is my code

def detectBoxes(img):
    image = np.asarray(img)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gradient = cv2.Laplacian(gray, cv2.CV32F)
    kernel = np.ones((15,15),np.uint8)
    closing = cv2.morphologyEx(gradient, cv2.MORPH_CLOSE, kernel)
    closing = cv2.cvtColor(closing, cv2.COLOR_BGR2GRAY)
    im2, cnts, hier = cv2.findContours(closing, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

I think it's because findContours needs another type of color conversion, but I'm unsure about which one. Any clues here? Thanks