找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2619|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

opencv單目標(biāo)定程序源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:146612 發(fā)表于 2016-11-7 14:39 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include <iostream>
#include <iomanip>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>

#include "CameraCalibrator.h"

int main()
{

        cv::namedWindow("Image");
        cv::Mat image;
        std::vector<std::string> filelist;

        // generate list of chessboard image filename
        for (int i=1; i<=20; i++) {

                std::stringstream str;
                str << "../chessboards/chessboard" << std::setw(2) << std::setfill('0') << i << ".jpg";
                std::cout << str.str() << std::endl;

                filelist.push_back(str.str());
                image= cv::imread(str.str(),0);
                cv::imshow("Image",image);
       
                 cv::waitKey(100);
        }

        // Create calibrator object
    CameraCalibrator cameraCalibrator;
        // add the corners from the chessboard
        cv::Size boardSize(7,7);
        cameraCalibrator.addChessboardPoints(
                filelist,        // filenames of chessboard image
                boardSize);        // size of chessboard
                // calibrate the camera
    //        cameraCalibrator.setCalibrationFlag(true,true);
        cameraCalibrator.calibrate(image.size());

    // Image Undistortion
    image = cv::imread(filelist[6]);
        cv::Mat uImage= cameraCalibrator.remap(image);

        // display camera matrix
        cv::Mat cameraMatrix= cameraCalibrator.getCameraMatrix();
        std::cout << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << std::endl;
        std::cout << cameraMatrix.at<double>(0,0) << " " << cameraMatrix.at<double>(0,1) << " " << cameraMatrix.at<double>(0,2) << std::endl;
        std::cout << cameraMatrix.at<double>(1,0) << " " << cameraMatrix.at<double>(1,1) << " " << cameraMatrix.at<double>(1,2) << std::endl;
        std::cout << cameraMatrix.at<double>(2,0) << " " << cameraMatrix.at<double>(2,1) << " " << cameraMatrix.at<double>(2,2) << std::endl;

    imshow("Original Image", image);
    imshow("Undistorted Image", uImage);
        //打印相機(jī)內(nèi)參數(shù)矩陣(3*3矩陣)
   /* cv::  Mat cameraMatrix = cameraCalibrator.getCameraMatrix();
    std::cout << " 相機(jī)內(nèi)參數(shù)矩陣:" << cameraMatrix.rows << "x" << cameraMatrix.cols << std::endl;
    for (int i=0; i for (int j=0; j {
    cout<(i, j);
    if (j==2)
    cout< }*/
    //打印畸變系數(shù)矩陣(1*5矩陣)
    cv:: Mat distCoeffs = cameraCalibrator.getDistCoeffs();
    std::cout << "畸變系數(shù)矩陣:" << distCoeffs.rows << "x" << distCoeffs.cols << std::endl;
    //for (int i=0; i for (int j=0; j cout<(i, j)<<"\t";
        std::cout << distCoeffs.at<double>(0,0) << " " << distCoeffs.at<double>(0,1) << " " << distCoeffs.at<double>(0,2)<<" " << distCoeffs.at<double>(0,3)<<" "<< distCoeffs.at<double>(0,4)<< std::endl;



        cv::waitKey();
        return 0;
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表