图片矫正方法

#define _CRT_SECURE_NO_WARNINGS
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include "opencv2/calib3d/calib3d.hpp"
#include "windows.h"
#include "time.h"
#include "stdio.h"
#include "opencv2/core.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <opencv2/calib3d.hpp>
#include "windows.h"
#include "time.h"
#include "iostream"
#include "opencv2/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <opencv2/imgproc/types_c.h>
#include <opencv2/calib3d/calib3d_c.h>
#include<time.h>

using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;
#define _CRT_SECURE_NO_WARNINGS


const int ImgWidth = 2800;
const int ImgHeight = 2800;
cv::Mat map1, map2;
Mat srcImage, srcImage1;
cv::Size imageSize(ImgWidth, ImgHeight);
const double alpha = 1;
clock_t start, finish;
Mat IntrinsicMatrix, DistortionCoeffs, newMatrix;


void jiaozhenginit()
{
    FileStorage fs2("C:/Users/mmmmpc/source/repos/1/x64/Debug/123.xml", FileStorage::READ);
    fs2["Intrinsic_Matrix"] >> IntrinsicMatrix;
    fs2["Distortion_Coeffs"] >> DistortionCoeffs;
    fs2.release();

}
void jiaozheng()
{

    Mat srcImage, srcImage1;
    srcImage = cv::imread("C:/Users/mmmmpc/source/repos/1/x64/Debug/test.jpg", cv::IMREAD_COLOR);
    srcImage = srcImage(Range(110, 2920), Range(620, 3450));
    clock_t start, finish;
    double totaltime;

    start = clock();
    cv::undistort(srcImage,													//输入源图像
        srcImage1,												//存放矫正后图像
        IntrinsicMatrix,										//内参矩阵
        DistortionCoeffs										//畸变矩阵
    );
    imwrite("C:/Users/mmmmpc/source/repos/1/x64/Debug/bbb.jpg", srcImage1);





} 

void jiaozheng2() {
   
    srcImage = cv::imread("C:/Users/mmmmpc/source/repos/1/x64/Debug/test.jpg", cv::IMREAD_COLOR);
    srcImage = srcImage(Range(110, 2920), Range(620, 3450)); 
    start = clock();
    FileStorage fs2("C:/Users/mmmmpc/source/repos/1/x64/Debug/123.xml", FileStorage::READ);
    fs2["Intrinsic_Matrix"] >> IntrinsicMatrix;
    fs2["Distortion_Coeffs"] >> DistortionCoeffs;
    fs2.release();
    finish = clock();
    printf("%f seconds\n", (double)(finish - start) / CLOCKS_PER_SEC);
   
    start = clock(); //开始矫正
    cv::initUndistortRectifyMap(
        IntrinsicMatrix,//内参矩阵
        DistortionCoeffs,//畸变矩阵
        cv::Mat(),
        IntrinsicMatrix,
        imageSize,
        CV_16SC2, map1, map2
    );
    cv::remap(
        srcImage,													//输入源图像
        srcImage1,
        map1, map2, cv::INTER_LINEAR
    );
    finish = clock();//矫正结束

    printf("%f seconds\n", (double)(finish - start) / CLOCKS_PER_SEC);
    imwrite("C:/Users/mmmmpc/source/repos/1/x64/Debug/bbb.jpg", srcImage1);


}
int main()
{

    jiaozhenginit();
    clock_t start, finish;
    double totaltime;
    start = clock();
    jiaozheng2();
    finish = clock();
    printf("%f seconds\n", (double)(finish - start) / CLOCKS_PER_SEC);


}


版权声明:本文为sxycmzx123原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。