1 /* 2 Copyright (c) 2019 Ferhat Kurtulmuş 3 Boost Software License - Version 1.0 - August 17th, 2003 4 Permission is hereby granted, free of charge, to any person or organization 5 obtaining a copy of the software and accompanying documentation covered by 6 this license (the "Software") to use, reproduce, display, distribute, 7 execute, and transmit the Software, and to prepare derivative works of the 8 Software, and to permit third-parties to whom the Software is furnished to 9 do so, all subject to the following: 10 The copyright notices in the Software and this entire statement, including 11 the above license grant, this restriction and the following disclaimer, 12 must be included in all copies of the Software, in whole or in part, and 13 all derivative works of the Software, unless such copies or derivative 14 works are solely in the form of machine-executable object code generated by 15 a source language processor. 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 19 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 20 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 DEALINGS IN THE SOFTWARE. 23 */ 24 25 module opencvd.calib3d; 26 27 import std.conv; 28 29 import opencvd.cvcore; 30 31 private extern (C){ 32 void Fisheye_UndistortImage(Mat distorted, Mat undistorted, Mat k, Mat d); 33 void Fisheye_UndistortImageWithParams(Mat distorted, Mat undistorted, Mat k, Mat d, Mat knew, Size size); 34 35 void InitUndistortRectifyMap(Mat cameraMatrix,Mat distCoeffs,Mat r,Mat newCameraMatrix,Size size,int m1type,Mat map1,Mat map2); 36 Mat GetOptimalNewCameraMatrixWithParams(Mat cameraMatrix,Mat distCoeffs,Size size,double alpha,Size newImgSize,Rect* validPixROI,bool centerPrincipalPoint); 37 Mat FindHomography1(Point2fs srcPoints, Point2fs dstPoints, int method, 38 double ransacReprojThreshold, Mat mask, int maxIters, double confidence); 39 } 40 41 void fisheye_UndistortImage(Mat distorted, Mat undistorted, Mat k, Mat d){ 42 Fisheye_UndistortImage(distorted, undistorted, k, d); 43 } 44 45 void fisheye_UndistortImageWithParams(Mat distorted, Mat undistorted, Mat k, Mat d, Mat knew, Size size){ 46 Fisheye_UndistortImageWithParams(distorted, undistorted, k, d, knew, size); 47 } 48 49 void initUndistortRectifyMap(Mat cameraMatrix,Mat distCoeffs, Mat r, Mat newCameraMatrix, Size size, int m1type, Mat map1, Mat map2){ 50 InitUndistortRectifyMap(cameraMatrix, distCoeffs, r, newCameraMatrix, size, m1type, map1, map2); 51 } 52 53 Mat getOptimalNewCameraMatrixWithParams(Mat cameraMatrix,Mat distCoeffs,Size size,double alpha,Size newImgSize,Rect* validPixROI,bool centerPrincipalPoint){ 54 return GetOptimalNewCameraMatrixWithParams(cameraMatrix, distCoeffs, size, alpha, newImgSize, validPixROI, centerPrincipalPoint); 55 } 56 57 enum: int{ 58 LMEDS = 4, 59 RANSAC = 8, 60 RHO = 16 61 } 62 63 Mat findHomography(Point2f[] srcPoints, Point2f[] dstPoints, int method=0, 64 double ransacReprojThreshold=3, Mat mask=Mat(), int maxIters=2000, double confidence=0.995){ 65 66 return FindHomography1(Point2fs(srcPoints.ptr, srcPoints.length.to!int), 67 Point2fs(dstPoints.ptr, dstPoints.length.to!int), 68 method, ransacReprojThreshold, mask, maxIters, confidence); 69 }