0

I pass the image name as a parameter to this function:

def main(imageName):
    image = cv2.imread(imageName)
    cv2.imshow('color_image', image)
    gray_image =  grey(image)
    cv2.imshow("gray_image", gray_image)
    cv2.waitKey(0)
    clahe_image = clahe(gray_image,0)
    cv2.imshow("clahe_image", clahe_image)
    cv2.waitKey(0)
    dst_img = denoise(clahe_image)
    cv2.imshow("dst_img", dst_img)
    cv2.waitKey(0)
    binary_img = threshld(dst_img,0)
    cv2.imshow("binary_img", binary_img)
    cv2.waitKey(0)
    skiw_img = deskew(binary_img)
    cv2.imshow("skiw_img", skiw_img)
    cv2.imwrite("skiw_img.png", skiw_img)
    cv2.waitKey(0)

then i get that error.but when i execute it without parameter

def main():
    image = cv2.imread('e2nn.png')
    cv2.imshow('color_image', image)
    gray_image =  grey(image)
    cv2.imshow("gray_image", gray_image)
    cv2.waitKey(0)
    clahe_image = clahe(gray_image,0)
    cv2.imshow("clahe_image", clahe_image)
    cv2.waitKey(0)
    dst_img = denoise(clahe_image)
    cv2.imshow("dst_img", dst_img)
    cv2.waitKey(0)
    binary_img = threshld(dst_img,0)
    cv2.imshow("binary_img", binary_img)
    cv2.waitKey(0)
    skiw_img = deskew(binary_img)
    cv2.imshow("skiw_img", skiw_img)
    cv2.imwrite("skiw_img.png", skiw_img)
    cv2.waitKey(0)

i did not get that error and it execute well.

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87

1 Answers1

1

This error comes up when no image (the array containing the image information) reaches the imshow() function. This is caused because your imread() function is not returning the desired output. Common mistakes include the following:

  1. Incorrect Image Name: Check the name of the image right down to the format. Even jpg and jpeg are different.
  2. Incorrect Path: In the case that your image is not in the same directory, put the full path to the image. Since you're using Windows, don't forget to change the backslash to forward. Those using Ubuntu should ensure that they put a '\' before home eg '\home\username\Desktop'
  3. Access Issues: This is more prevalent for linux users but sometime you might not have read access to the image. Try using chmod 777 and run your code again. Please note that it is advised to change the access back to something more restrictive.