'cv2.imshow() is giving blank black color window frame

using the below code, cv2.imshow() is giving black color window output , how to make it work so that below code shd give proper display output and write the frame of output. Below i am attaching the video file which is used

capL = cv2.VideoCapture(vid_path,0)
capR = cv2.VideoCapture(vid_path2,0)

frame_width = int(capL.get(3))
frame_height = int(capL.get(4))
   
size = (frame_width, frame_height)

result = cv2.VideoWriter('depth_map_StereoSGBM.mp4', 
                         cv2.VideoWriter_fourcc(*'MP4V'),
                         20, size)

# stereo = cv2.StereoBM_create(numDisparities=16*16, blockSize=21)

# retL, frameL = capL.read()

while capL.isOpened() and capR.isOpened():
    retL, frameL = capL.read()
    retR, frameR = capR.read()
    
    # if frame is read correctly ret is True
    if not (retL and retR):
        print("Can't receive frame (stream end?). Exiting ...")
        break
    frameL = cv2.cvtColor(frameL, cv2.COLOR_BGR2GRAY)
    frameR = cv2.cvtColor(frameR, cv2.COLOR_BGR2GRAY)
    
    
    
    numdisp = 9
    stereo = cv2.StereoSGBM_create(
        minDisparity=2,
        numDisparities=numdisp*16,
        blockSize=11, #11
        P1=8 * 3 * 11**2,
        P2=32 * 3 * 11**2,
        # disp12MaxDiff=0,
        # preFilterCap=0,
        # uniquenessRatio=0,
        # speckleWindowSize=0,
        # speckleRange=0
    )

    disparity = (stereo.compute(frameL,frameR) + 16) * 10

    disparity = np.dstack((disparity,disparity,disparity))
    disparity = cv2.GaussianBlur(disparity,(5,5),0)
    print(disparity.max())
    print(disparity.min())   
    disparity = np.array(disparity , dtype=np.uint8)

    
    result.write(disparity)

    cv2.imshow('frame', disparity)
    if cv2.waitKey(1) == ord('q'):
        break
capL.release()
capR.release()

result.release()

cv2.destroyAllWindows()

https://drive.google.com/drive/folders/1_dVTV3d3OA6U-oDhra2MnneKbdREFtAC is the link of video used .

disparty.max() and disparity.min() before converting to uint8 is as follow

max 599
min 320
max 800
min 320
max 823
min 320
max 4097
min 320
max 20925
min 320
max 16683
min 320


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source