# Fisheys camera undistort to a larger image

**URL:** <https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872>\
**Category:** Uncategorized\
**Created:** [August 23, 2021, 4:17am UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872 "2021-08-23T04:17:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![autocar](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@autocar](https://forum.opencv.org/u/autocar)\
**Post date:** [August 23, 2021, 4:17am UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872/1 "2021-08-23T04:17:26Z")

</div>

Hi, I have a fisheye camera which is calibrated. I am now trying to undistort the image to a larger image to keep all original image content. Below is my code. The original image is 640x480 and I would like to undistort it to a 1200x1200 image. However, when I ran the code, the output image “rview” was always 640x480. WHy?

```
Mat frame =.../my input image, size(640x480)
Mat output;
Mat newK;
Mat view, map1, map2;

Size newSize(1200, 1200); //I want to undistort to a 1200x1200 image
Mat rview(newSize, frame.type()); //rview size is 1200x1200

fisheye::estimateNewCameraMatrixForUndistortRectify(K, D, frame.size(), Matx33d::eye(), newK, 1);
fisheye::initUndistortRectifyMap(K, D, Matx33d::eye(), newK, frame.size(), CV_16SC2, map1, map2); //as input, frame size is 640x480, as output map1, map2 size were 640x480

remap(frame, rview, map1, map2, INTER_LINEAR); //rview image size changed to 640x480
imwrite("rview.png", rview);
```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 23, 2021, 3:58pm UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872/2 "2021-08-23T15:58:45Z")

</div>

which matrices are sized 640x480, besides the obvious one? you should _check_ them.

---

<div class="post-metadata">

**Author:** ![autocar](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@autocar](https://forum.opencv.org/u/autocar)\
**Post date:** [August 23, 2021, 4:21pm UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872/3 "2021-08-23T16:21:13Z")

</div>

I edited my post to have those information

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 23, 2021, 4:49pm UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872/4 "2021-08-23T16:49:43Z")

</div>

I meant all of them.

specifically map1 and map2

and all arguments to `initUndistortRectifyMap`

---

<div class="post-metadata">

**Author:** ![autocar](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@autocar](https://forum.opencv.org/u/autocar)\
**Post date:** [August 23, 2021, 6:20pm UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872/5 "2021-08-23T18:20:42Z")

</div>

updated, please see the comments

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 23, 2021, 6:22pm UTC](https://forum.opencv.org/t/fisheys-camera-undistort-to-a-larger-image/4872/6 "2021-08-23T18:22:32Z")

</div>

[https://docs.opencv.org/master/db/d58/group\_\_calib3d\_\_fisheye.html#ga384940fdf04c03e362e94b6eb9b673c9](https://docs.opencv.org/master/db/d58/group __calib3d__ fisheye.html#ga384940fdf04c03e362e94b6eb9b673c9)

see `new_size` there
