python – Error processing large images with openCV

Question:

I'm trying to process an orthomosaic, the problem is that the image is too big, with other smaller maps I can process normally, but when I go to process a larger map it gives an error when converting from RGB to HSV, but this error occurs because it couldn't read the image is soon trying to convert an empty image, hence the error.

this is the initial code and the error presented is in the line converting from RGB to HSV…

import cv2
import numpy as np

imageName = "mapa.tif"

imagem = cv2.imread(imageName,cv2.IMREAD_COLOR)
hsv = cv2.cvtColor(imagem, cv2.COLOR_BGR2HSV)

mistake:

OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/color.cpp, line 3959

Obs.: Remembering that with smaller maps the code works, for this reason I believe there may be some memory allocation limit in the cv2.imread function.

Does anyone have any info on this? or do you know how to increase the memory allocation limit for reading image in openCV?

Answer:

As you've already noticed, your problem is that cvtColor isn't recognizing the input image, it probably thinks None when expecting an image with at least 3 color channels: image.shape[2] equal to 3 or 4.

It's strange that the error only cvtColor in cvtColor , I would expect it to be already on the imread this problem.

Anyway, one thing you can do is see what is the largest image size your hardware can support. For that, you need to check the image size ( image.size ) and what type ( type(image) ). With this you will know the maximum size of the image that can be converted.

Then you have two approaches that depend on what you want to do with that image. 1) resize the image ( resize ) 2) break the image into smaller parts, convert and then reassemble. As images are ndarrays, just use indices to separate the part of the ndarray you want.

Scroll to Top
AllEscort