'Python Remap function returns not an image

I have a problem with the code. There is no compile error, but the result does not give a corrected image. Could someone please explain me where is my error. I have the camera data like the camera matrices from the stereo calibration via ROS.

Here is my Code:

from pypylon import genicam
from pypylon import pylon
from PIL import Image

import sys
import cv2
import time
import os
import numpy as np

momo1=cv2.imread('camera_image_left.pgm',0)
momo2=cv2.imread('camera_image_right.pgm',0)

#cv2.imwrite('camera_image_left1.jpg',momo1)
#cv2.imwrite('camera_image_right1.jpg',momo2)


m1=np.matrix('1260.5003905791398 0.0 966.4264657323051;0.0 1260.5292466762314 588.706550112646;0.0, 0.0, 1.0')
m2=np.matrix('1270.3289245118788 0.0 890.5839146326629;0.0 1271.0784134532882 553.8894101510742;0.0, 0.0, 1.0')
dist_coefsl=np.array([-0.222743, 0.085158, -0.000596, -0.000561, 0.000000])
dist_coefsr=np.array([-0.212633, 0.081867, -0.000254, -0.001820, 0.000000])
r=np.matrix('0.9995020044229441 0.0002662502068116009 0.03155427491393791;-0.0011846985932157795 0.9995760413742915 0.029091820151790685; -0.03153315150377823 -0.02911471485912707 0.9990785723530015')
t=np.array([-0.16235665734042895, 0.0013399976049735557, 0.016907777470413887])
     
r1=np.zeros(shape=(3,3))
r2=np.zeros(shape=(3,3))
p1=np.zeros(shape=(3,4))
p2=np.zeros(shape=(3,4))


        
       
r1, r2, p1, p2, Q,_,_=cv2.stereoRectify(m1, dist_coefsl, m2, dist_coefsr, (momo1.shape[0], momo1.shape[1]), r, t, alpha=-1) 


  
map1x, map1y=cv2.initUndistortRectifyMap(m1, dist_coefsl, r1, p1, (momo1.shape[0],                        momo1.shape[1]), cv2.CV_32FC1)
map2x, map2y=cv2.initUndistortRectifyMap(m2, dist_coefsr, r2, p2, (momo1.shape[0], momo1.shape[1]), cv2.CV_32FC1)

print(map1x.shape)
print(map1y.shape)
cv2.imwrite('Test1.pgm',map1x)
cv2.imwrite('Test2.pgm',map1y)
cv2.imwrite('Test3.pgm',map2x)
cv2.imwrite('Test4.pgm',map2y)


              
        
      
dstl=cv2.remap=(momo1, map1x, map1y,cv2.INTER_LINEAR)
dstr=cv2.remap=(momo2, map2x, map2y,cv2.INTER_LINEAR)

print(len(dstl))
cv2.imwrite('Test5.pgm',dstl[0])
cv2.imwrite('Test6.pgm',dstl[1])
cv2.imwrite('Test7.pgm',dstl[2])
cv2.imwrite('Test8.pgm',dstl[3])

I get a list as return value for the remap function, there is an image in it, but this is exactly the same image, which I have read in. My goal is to process the 2 images I read in so that the lines match so that I can create a good disparity map.

Output console: student@ubuntu:~$ python3 rectify.py (1920, 1200) (1920, 1200) 4

Images: enter image description here enter image description here



Sources

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

Source: Stack Overflow

Solution Source