I have a distorted snapshot of my webcam. as jpeg file, intrinsic matrix and distortion coefficients:-
matrix intrisic matrix
(1137.0919189453125,0.0,383.99273681640625)
(0.0,264.17974853515625,312.74951171875)
(0.0,0.0,1.0)
matrix distortion :-
(-0.26913660764694214)
(0.22259517014026642)
(-0.0928017795085907)
(0.26249778270721436)
I don't know how to load these distortion coefficients in CvMat in order to obtain undistorted image using these distortion coefficients. also, I want to do this using javacv only.
edit:- also, i know the function
IplImage mapx=cvCreateImage(cvSize(src_img),IPL_DEPTH_32F,1);
IplImage mapy=cvCreateImage(cvSize(src_img),IPL_DEPTH_32F,1);
cvInitUndistortMap(CvMat intrinsic,CvMat distortion, IplImage mapx, IplImage mapy);
cvRemap(IplImage tm,IplImage src,IplImage mapx,IplImage mapy,CV_INTER_LINEAR|CV_WARP_FILL_OUTLIERS,cvScalarAll(0));
but i don't know how to initialize respective cvMats for intrinsic matrix and distortion coefficient.?
Radial distortion occurs when light rays bend more near the edges of a lens than they do at its optical center. The smaller the lens, the greater the distortion. The radial distortion coefficients model this type of distortion. The distorted points are denoted as (xdistorted, ydistorted):
Remove distortion from the images. I = imread(fullfile(matlabroot,'toolbox','vision','visiondata','calibration','mono','image01. jpg')); J = undistortImage(I,cameraParams); Display the original and the undistorted images.
Undistort Method. corrects lens distortion for the given camera matrix and distortion coefficients.
cv::undistort
?It takes your matrices as its parameters.
void undistort(const Mat& src, Mat& dst, const Mat& cameraMatrix, const Mat& distCoeffs, const Mat& newCameraMatrix=Mat())
The src
matrix is your image.
The dst
matrix is the undistorted image.
The cameraMatrix
is your intrinsic matrix.
The distCoeffs
matrix is your distortion matrix.
To quote from the documentation:
The particular subset of the source image that will be visible in the corrected image can be regulated by
newCameraMatrix
. You can use GetOptimalNewCameraMatrix to compute the appropriatenewCameraMatrix
, depending on your requirements.
OK. I just found the answer to your comment.... I think.
public static native void cvUndistortPoints(CvMat src, CvMat dst, CvMat camera_matrix,
CvMat dist_coeffs, CvMat R/*=null*/, CvMat P/*=null*/);
You can find this in http://www.java2s.com/Open-Source/Android/UnTagged/educationalrobots/name/audet/samuel/javacv/jna/cv.java.htm.
This is actually in imgproc.
Just make the last two parameters null
.
The second part - initializing a CvMat - is tougher than it looks, because you have to mess around with pointers if you want to do it elegantly, and I forget how to use JNA Pointers :)
So here's an alternate solution:
Use this constructor public static CvMat create(int rows, int cols, int type);
So, for your matrix, you would have three rows and three columns.
Your type would be one of the types in cxcore.java, probably CV_64FC1
, which is the single-channel double
type. Otherwise, if you're using float
s, it would be CV_32FC1
.
Then you would set the values, one by one, by using:
opencv_core.cvSet2D(matrix, i, j, value);
Where i
is row and j
is column!
Any more questions?
Cheerio!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With