error: (-215:Assertion failed) nelems <= size_t(INT_MAX)*size_t(INT_MAX) in function 'cv::Mat::reserveBuffer'

asked 2020-04-06 09:00:34 -0500

Ser gravatar image

updated 2020-04-06 09:12:21 -0500

berak gravatar image

Hi I am using the piece of code below for disparity image creation:

import numpy as np
from sklearn.preprocessing import normalize
import cv2

print('loading images...')
imgL = cv2.imread('Img/index.jpg')  # downscale images for faster processing
imgR = cv2.imread('Img/index.jpg')

# SGBM Parameters -----------------
window_size = 3  # wsize default 3; 5; 7 for SGBM reduced size image; 15 for SGBM full size image (1300px and above); 5 Works nicely

left_matcher = cv2.StereoSGBM_create(
    minDisparity=0,
    numDisparities=160,  # max_disp has to be dividable by 16 f. E. HH 192, 256
    blockSize=5,
    P1=8 * 3 * window_size ** 2,
    # wsize default 3; 5; 7 for SGBM reduced size image; 15 for SGBM full size image (1300px and above); 5 Works nicely
    P2=32 * 3 * window_size ** 2,
    disp12MaxDiff=1,
    uniquenessRatio=15,
    speckleWindowSize=0,
    speckleRange=2,
    preFilterCap=63,
    mode=cv2.STEREO_SGBM_MODE_SGBM_3WAY
)

right_matcher = cv2.ximgproc.createRightMatcher(left_matcher)

# FILTER Parameters
lmbda = 80000
sigma = 1.2
visual_multiplier = 1.0

wls_filter = cv2.ximgproc.createDisparityWLSFilter(matcher_left=left_matcher)
wls_filter.setLambda(lmbda)
wls_filter.setSigmaColor(sigma)

print('computing disparity...')
displ = left_matcher.compute(imgL, imgR)  # .astype(np.float32)/16
dispr = right_matcher.compute(imgR, imgL)  # .astype(np.float32)/16
displ = np.int16(displ)
dispr = np.int16(dispr)
filteredImg = wls_filter.filter(displ, imgL, None, dispr)  # important to put "imgL" here!!!

filteredImg = cv2.normalize(src=filteredImg, dst=filteredImg, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX);
filteredImg = np.uint8(filteredImg)
cv2.imshow('Disparity Map', filteredImg)
cv2.waitKey()
cv2.destroyAllWindows()

I am getting an error like:

loading images...
computing disparity...
Traceback (most recent call last):
  File "D:/Users/T0232750/PycharmProjects/Python_WS/DepthImage.py", line 39, in <module>
    displ = left_matcher.compute(imgL, imgR)  # .astype(np.float32)/16
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\core\src\matrix.cpp:670: error: (-215:Assertion failed) nelems <= size_t(INT_MAX)*size_t(INT_MAX) in function 'cv::Mat::reserveBuffer'

Process finished with exit code 1

Can someone help to fix this????????????

edit retag flag offensive close merge delete