0
votes

I'm trying to use opencv to open an image size 4864 x 382565 and it is bigger than CV_IO_MAX_IMAGE_PIXELS limitation which is 2^30 pixels.

img = cv2.cvtColor(cv2.imread(path),cv2.COLOR_BGR2GRAY)

You can do the trick of calling set CV_IO_MAX_IMAGE_PIXELS=18500000000 from the shell before running python script to bypass this check, but I wonder is there a better solution?

Thanks

1
instead of specifying pixels you can mention, CV_IO_MAX_IMAGE_WIDTH, CV_IO_MAX_IMAGE_HEIGHT specifically if the dimension of your images are constant. Though adding 2 variables in place of 1 might sound weird, but this makes more logical readability. lets wait and hear for other answersvenkata krishnan

1 Answers

2
votes

I think I found the solution

os.environ["OPENCV_IO_MAX_IMAGE_PIXELS"] = pow(2,40).__str__()
import cv2 # import after setting OPENCV_IO_MAX_IMAGE_PIXELS

This will change the limitation to 2^40

Just remember to import opencv AFTER setting the environment variable, otherwise it wouldn't work