Error processing large images with openCV

Asked

Viewed 428 times

3

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 bigger map it from the error in converting RGB to HSV, but this error occurs because it failed to read the image so it is trying to convert an empty image, so the error.

this is the initial code and the error shown is in the conversion line 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)

error:

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

Note: Remembering that with smaller maps the code works, for this reason I believe that it can be some limit of memory allocation in the function cv2.imread.

Does anyone have any information about it? or knows how to increase the limit of memory allocation for reading image in openCV?

1 answer

1


As you’ve noted, your problem is that cvtColor is not recognizing the entrance image, probably he 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 mistake happens only in the cvtColor, I would expect that already in the imread of this problem.

Anyway, one thing you can do is see what the biggest image size your hardware can support is. For this, 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.

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

  • Thanks for the help, I ended up solving the problem by dividing the image into several parts. But I can’t say exactly the size limit for the operation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.