我试图在Visual Studio中的C++中使用正弦模式工具。我在下面放置了要测试的代码。在Visual Studio中,以下行中的参数下的红色花体看起来一切都很好:

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);
}

最佳答案

documentation告诉您params也应该是Ptr,但是您传递了对象...

尝试使用makePtr

更改此行:

structured_light::SinusoidalPattern::Params params;

有了这个:
Ptr<cv::structured_light::SinusoidalPattern::Params> params = makePtr< SinusoidalPattern::Params >();

您必须将.更改为->,以便每次使用参数时都将params.width = 1080;设置为params->width = 1080;,因为它现在是指针。

其余代码应该没问题。

关于c++ - 具有正弦模式生成的OpenCV C++错误-Structural_light库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48321322/

10-11 17:56