Search code examples
pythonresizeopencv3.0remap

OpenCV: error in resizing video's frame for depthmap


I am performing a depth map with opencv3.4. As I obtained the calibration file, I would like to have the disparity map true 2 stereo cameras. In order to do this i call the calibration file but when i try to resize and remap the video windows, i got the following error. Note: the same script, works with a calibration file taken from just 8 images. the current file is from 21 images. what could be the problem?

Error

here everything it display when i try to run the dept map

  File "<ipython-input-5-f2eac343bb87>", line 1, in <module>
    runfile('C:/Users/gaetano/Desktop/SONIDO ORIGINAL/biggerDepth2.py', wdir='C:/Users/gaetano/Desktop/SONIDO ORIGINAL')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/gaetano/Desktop/SONIDO ORIGINAL/biggerDepth2.py", line 68, in <module>
    dst= cv2.resize(dst, (0,0),dst, 2.0, 2.0, cv2.INTER_LINEAR)

error: C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize

Code

The code interrupt in line resize in the end of this code, so the remap should be ok. Is a problem of the value I give x, y , w, h? or maybe a problem about the number of bit of the matrix?

ret, frame = cap1.read()
ret, frame2 = cap2.read()

#cv2.imshow('frame', frame)
#cv2.imshow('frame2', frame2)
#imgL = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#imgR = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
##    dst = cv2.remap(frame, mapx1, mapy1, 
cv2.INTER_LINEAR,cv2.BORDER_CONSTANT, 0)

# imgL_rectified = cv2.remap(imgL, camera_config.left_map1, 
camera_config.left_map2, cv2.INTER_LINEAR)
dst = cv2.remap(frame, mapx1, mapy1, cv2.INTER_LINEAR)

dst = dst[y:y + h, x:x + w]
#print(dst)
##       dst2 = cv2.remap(frame2, mapx2, mapy2, 
cv2.INTER_LINEAR,cv2.BORDER_CONSTANT, 0)
dst2 = cv2.remap (frame2, mapx2, mapy2, cv2.INTER_LINEAR)
dst2 = dst2[y:y + h, x:x + w]

dst= cv2.resize(dst, (0,0),dst, 2.0, 2.0, cv2.INTER_LINEAR)
dst2 = cv2.resize(dst2, (0,0),dst2, 2.0, 2.0,cv2.INTER_LINEAR)

Solution

  • Have a look at the following link, Assertion failure : size.width>0 && size.height>0 in function imshow

    Also, check the value returned by ret in ret, frame = cap1.read(). I think it may be false and there is no image read at all.