• 关于Opencv2.4.x中stitcher类的简单应用


    1.opencv2.4以上版本有stitcher类,可以简单方便的实现图像的拼接,目前只是简单的测试一下stitcher类的拼接功能,也是纠结了好长时间,最终发现是要在链接库中加上opencv_stitching249.lib(对于Release),opencv_stitching249d.lib(对于Debug)才行,不然会出现VS2013编译不成功,错误提示是:(注:红色数字249是当前opencv的版本号,根据你的opencv版本号,更改这个数值)

    1>main.obj : error LNK2019: unresolved external symbol "public: enum cv::Stitcher::Status __thiscall cv::Stitcher::stitch(class cv::_InputArray const &,class cv::_OutputArray const &)" (?stitch@Stitcher@cv@@QAE?AW4Status@12@ABV_InputArray@2@ABV_OutputArray@2@@Z) referenced in function _main 

    1>main.obj : error LNK2019: unresolved external symbol "public: static class cv::Stitcher __cdecl cv::Stitcher::createDefault(bool)" (?createDefault@Stitcher@cv@@SA?AV12@_N@Z) referenced in function _main 1>D:visual studio 2010Projectsstitching20Debugstitching20.exe : fatal error LNK1120: 2 unresolved externals

            下面是测试程序:

    编译环境:

           操作系统:XP

           opencv版本:2.4.9

           编译器版本:VS2013

    程序代码 

    #include <iostream>
    #include <fstream>
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/stitching/stitcher.hpp"
    using namespace std;
    using namespace cv;
    bool try_use_gpu = false;
    vector<Mat> imgs;
    string result_name = "result.jpg"; //void printUsage(); //int parseCmdArgs(int argc, char** argv);
    int main(int argc, char* argv[])
    {
    Mat img=imread("1.jpg");
    imgs.push_back(img);
    img=imread("2.jpg");
    imgs.push_back(img);
    img=imread("3.jpg");
    imgs.push_back(img);
    Mat pano;
    Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
    Stitcher::Status status = stitcher.stitch(imgs, pano);
    if (status != Stitcher::OK)
    {
    cout << "Can't stitch images, error code = " << int(status) << endl;
    return -1;
    }
    imwrite(result_name, pano);
    return 0;
    }

    除了上面的错误之外,还会出现像下面的错误,很多个
    stitchingdetailwarpers_inl.hpp(186): error C2059: 语法错误:“::”
    错误代码示例:
    1. size.Width = std::max(size.Width, elementSize.Width);  

     2.错误原因

       函数模板max与Visual C++中的全局的宏max冲突。 

    3.解决办法

        1.第一种办法:设置项目属性,在预定义处理器中添加定义NOMINMAX来禁止使用Visual C++的min/max宏定义。

                           项目属性   ——> C/C++ ——> 预处理器 ——> 预处理器定义 (此处添加预定义编译开关   NOMINMAX)

    但是visual C++中定义能自动匹配double和int,如果进行了上述设置,代码中手动将int型的数据乘以1.0来达到double的目的。

        2.第二种办法: 加上括号,与Vsual C++的min/max宏定义区分开                  

        size.Width = std::max(size.Width, elementSize.Width);  
        修改为如下内容:

        size.Width = (std::max)(size.Width, elementSize.Width);  



  • 相关阅读:
    2016/11/10 kettle概述
    2016/11/07 线程的创建和启动
    python3 pip使用报错
    django建表报错
    django学习
    前端系列
    git使用标准
    我的Python之路
    nginx优化
    python安装包的时候报错
  • 原文地址:https://www.cnblogs.com/fengting/p/4978364.html
Copyright © 2020-2023  润新知