3

我正在尝试将 C++ 中的正弦模式工具与 Visual Studio 一起使用。我已经将我正在测试的代码放在下面。在 Visual Studio 中,除了以下行中 params 下的红色曲线外,一切看起来都很好:

Ptr<structured_light::SinusoidalPattern> sinus = structured_light::SinusoidalPattern::create(params);

当我尝试构建时,我收到以下错误消息:

Severity    Code    Description Project File    Line    Suppression State Error (active)        
no suitable user-defined conversion from 
"cv::structured_light::SinusoidalPattern::Params" to 
"cv::Ptr<cv::structured_light::SinusoidalPattern::Params>" exists   Structured_Light_Test   
c:\Users\ianco\Desktop\CPlusPlus_Programming\Structured_Light_Test\Structured_Light_Test\Main.cpp   70

如果有人能就如何解决这个问题或提出另一种方法提供一些建议,我将不胜感激。

代码:

#include <opencv2/highgui.hpp>
#include <vector>
#include <iostream>
#include <fstream>
#include <opencv2/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/structured_light.hpp>
#include <opencv2/phase_unwrapping.hpp>

using namespace cv;
using namespace std;

int main(int argc, char **argv)
{
    structured_light::SinusoidalPattern::Params params;
    params.width = 1080;
    params.height = 700;
    params.nbrOfPeriods = 5;
    params.setMarkers = true;
    params.horizontal = false;
    params.methodId = 2;
    params.shiftValue = static_cast<float>(2 * CV_PI / 3);
    params.nbrOfPixelsBetweenMarkers = 70;
    String outputPatternPath = "C:/Users/ianco/Desktop/CPlusPlus_Programming";
    String outputWrappedPhasePath = "C:/Users/ianco/Desktop/CPlusPlus_Programming";
    String outputUnwrappedPhasePath = "C:/Users/ianco/Desktop/CPlusPlus_Programming";

    Ptr<structured_light::SinusoidalPattern> sinus = structured_light::SinusoidalPattern::create(params);
    // Storage for patterns
    vector<Mat> patterns;
    //Generate sinusoidal patterns
    sinus->generate(patterns);


    cv::Mat blue, green, red;
    std::vector<cv::Mat> images(3);

    // OpenCV works natively with BGR ordering
    images.at(0) = patterns[0];
    images.at(1) = patterns[1];
    images.at(2) = patterns[2];

    cv::Mat color;
    cv::merge(images, color);

    namedWindow("pattern", WINDOW_NORMAL);
    setWindowProperty("pattern", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
    imshow("pattern", color);
    waitKey(3000);
}
4

1 回答 1

1

文档告诉你它也params应该是一个 Ptr 但你传递了对象......

尝试使用makePtr

更改此行:

structured_light::SinusoidalPattern::Params params;

有了这个:

Ptr<cv::structured_light::SinusoidalPattern::Params> params = makePtr< SinusoidalPattern::Params >();

每次使用 params时,您都必须更改为.,因为它现在将是一个指针。->params.width = 1080;params->width = 1080;

其余的代码应该没问题。

于 2018-01-18T12:46:31.747 回答