├── fisheye_sample.jpg ├── README.md ├── fisheye_example.py ├── .gitignore └── LICENSE /fisheye_sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smidm/opencv-python-fisheye-example/HEAD/fisheye_sample.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenCV Python Fisheye Example 2 | 3 | - `cv2.fisheye.undistortImage` example usage. 4 | - OpenCV version 3 or newer required. 5 | -------------------------------------------------------------------------------- /fisheye_example.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | assert float(cv2.__version__.rsplit('.', 1)[0]) >= 3, 'OpenCV version 3 or newer required.' 5 | 6 | K = np.array([[ 689.21, 0. , 1295.56], 7 | [ 0. , 690.48, 942.17], 8 | [ 0. , 0. , 1. ]]) 9 | 10 | # zero distortion coefficients work well for this image 11 | D = np.array([0., 0., 0., 0.]) 12 | 13 | # use Knew to scale the output 14 | Knew = K.copy() 15 | Knew[(0,1), (0,1)] = 0.4 * Knew[(0,1), (0,1)] 16 | 17 | 18 | img = cv2.imread('fisheye_sample.jpg') 19 | img_undistorted = cv2.fisheye.undistortImage(img, K, D=D, Knew=Knew) 20 | cv2.imwrite('fisheye_sample_undistorted.jpg', img_undistorted) 21 | cv2.imshow('undistorted', img_undistorted) 22 | cv2.waitKey() 23 | 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | *,cover 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | 53 | # Sphinx documentation 54 | docs/_build/ 55 | 56 | # PyBuilder 57 | target/ 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Matěj Šmíd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | --------------------------------------------------------------------------------