How to create a depth map

I’m trying to build depth map using StereoBM. Code:

import cv2
import numpy as np

left_image = cv2.imread('im10.jpg', 0)
right_image = cv2.imread('im11.jpg', 0)
left_image2 = cv2.imread('im0.jpg', 0)
right_image2 = cv2.imread('im1.jpg', 0)

left_image = cv2.resize(left_image, (800, 600))
right_image = cv2.resize(right_image, (800, 600))
left_image2 = cv2.resize(left_image2, (800, 600))
right_image2 = cv2.resize(right_image2, (800, 600))

stereoBM = cv2.StereoBM_create(0, 7)
disparity_map = stereoBM.compute(left_image, right_image).astype(np.float32)
disparity_map2 = stereoBM.compute(left_image2, right_image2).astype(np.float32)
disparity_map = cv2.normalize(disparity_map, 0, 255, cv2.NORM_MINMAX)
disparity_map2 = cv2.normalize(disparity_map2, 0, 255, cv2.NORM_MINMAX)

cv2.imshow('disparity', disparity_map)
cv2.imshow('disparity2', disparity_map2)
cv2.waitKey()

disparity_map - depth map for images from internet
disparity_map2 - depth map for my images


(downloaded image at left side, my images at right side)

I use 2 wide angle IR cameras. For calibration i using this guide -https://stereopi.com/blog/opencv-and-depth-map-stereopi-tutorial

Why my map is so bad? What resolution should the image have?

Sry for my bad english :smiley:

that is evidence of bad parameters to the block matching algorithm, or the pictures are flipped/shifted to cause no real correspondences to exist in the range of disparity it’s testing.

with those thumbnails, it’s hard to help.

but why, if you flip both images horizontally, then the depth map is not built correctly?
how do i make 2 perfect images for the correct build?

i made two new photos with large resolution, but effect is same. Horizontal flip dont affect too

I didn’t mean flip individual images, but switch their sides, so pardon for the choice of word. I’m not saying that’ll always do anything. it may do something in some cases.