pythonc++opencvcomputer-visionstereoscopy

OpenCV 3.1 Remap function Type Value Error


I'm using OpenCV3.1 with python 2.7 to calibrate and rectify a stereo camera setup. When I try to apply the rectification and undistortion matrixes to the image using cv2.remap() I get the following error:

Traceback (most recent call last):
 File "C:\University\Year3\Third Year Project - Gaze Correction\EclipseWorkspace\PythonTest\videoCap.py", line 36, in <module>
stereoCalib.rectify(frames)
File "C:\University\Year3\Third Year Project - Gaze Correction\EclipseWorkspace\PythonTest\Calibrator.py", line 137, in rectify
borderMode=cv2.BORDER_CONSTANT )
TypeError: an integer is required

My code is this:

new_frames = []
new_img=[]
for i, side in enumerate(("left", "right")):
  new_img = cv2.remap(frames[i],
                      new_img,
                      self.undistortion_map[side],
                      self.rectification_map[side],
                      cv2.INTER_CUBIC,
                      borderMode=cv2.BORDER_CONSTANT )
  new_frames.append(new_img)

I've tried setting the INTER_CUBIC and BORDER_CONSTANT as int(1) and int(0) interchangably. I have also added the np.zeros(3) scalar at the end, but the error remained the same in all of my attempts.


Solution

  • The use as described in the documentation is wrong. It should be :

    new_img = cv2.remap(src,
                        map1,
                        map2,
                        interpolation=cv2.INTER_<VALUE>)
    

    Border mode is entirely optional, and so is borderValue.