我使用OpenCV示例程序从我的相机计算相机矩阵和失真系数,并生成带有相关数据的xml文件。 不,我想纠正从同一相机拍摄的一些图像中的失真。所以我创建程序但仍然有一些错误。我试图用它来获得不失真的图像。
这是我的代码
#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;
}
}
运行时遇到此错误:
error: qualified-id in declaration before '(' token
cv::Mat CameraCalibrator::remap(const cv::Mat &image) {
任何帮助?