I've used the sample OpenCV program to calculate the camera matrix and distortion coefficients from my camera and produced an xml file with the relevant data. No I would like to correct distortion in some images taken from the same camera. So I create the program but still got some error. I'm trying to use it to get undistort image.
Here is my code
#include <iostream>
#include <sstream>
#include <string>
#include <ctime>
#include <cstdio>
#include <opencv2/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include "cameracalibrator.h"
CameraCalibrator::CameraCalibrator() :
flag(0),
mustInitUndistort(true)
{
}
using namespace cv;
using namespace std;
int main(){
Mat src,gray,image;
Mat cameraMatrix = (Mat1d(3, 3) << 8.5033354550764898e+002, 0, 640, 0, 8.5033354550764898e+002, 360, 0, 0, 1);
Mat distortionCoefficients = (Mat1d(1, 5) << -4.2796890539434634e-001, 2.8770882755049054e-001, 0, 0, -1.4405356460809188e-001);
// remove distortion in an image (after calibration)
cv::Mat CameraCalibrator::remap(const cv::Mat &image) {
cv::Mat undistorted;
cv::Mat image=imread("C:/Users/NTU/Desktop/Test/im4.png");
if (mustInitUndistort) { // called once per calibration
cv::initUndistortRectifyMap(
cameraMatrix, // computed camera matrix
distCoeffs, // computed distortion matrix
cv::Mat(), // optional rectification (none)
cv::Mat(), // camera matrix to generate undistorted
// cv::Size(640,480),
image.size(), // size of undistorted
CV_32FC1, // type of output map
map1, map2); // the x and y mapping functions
mustInitUndistort= false;
}
// Apply mapping functions
cv::remap(image, undistorted, map1, map2,
cv::INTER_LINEAR); // interpolation type
return undistorted;
imshow("gg",undistorted);
while(uchar(waitKey(1))!='Q');
//return 0;
}
}
when run got this error :
error: qualified-id in declaration before '(' token
cv::Mat CameraCalibrator::remap(const cv::Mat &image) {
Any help?