0

我的代码有问题。没有编译错误,但结果没有给出正确的图像。有人可以解释一下我的错误在哪里。我有相机数据,比如通过 ROS 立体校准的相机矩阵。

这是我的代码:

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])

我得到一个列表作为 remap 函数的返回值,其中有一个图像,但这与我读入的图像完全相同。我的目标是处理我读入的 2 个图像,以便线条匹配我可以创建一个很好的视差图。

输出控制台:student@ubuntu:~$ python3 rectify.py (1920, 1200) (1920, 1200) 4

图片: 在此处输入图像描述 在此处输入图像描述

4

0 回答 0