3

I am trying to use the sinusoidal pattern tool in C++ with Visual Studio. I have placed the code that I am testing this with below. In visual studio everything looks fine bar the red squiggle under params in the following line:

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

When I try to build I get the following error message:

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

I would be very grateful if anyone could offer some advice on how I could get round this issue or suggest another method.

CODE:

#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);
}
api55
  • 11,070
  • 4
  • 41
  • 57

1 Answers1

1

The documentation tells you that params should also be a Ptr but you passed the object...

try using makePtr

Change this line:

structured_light::SinusoidalPattern::Params params;

with this:

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

you will have to change . to -> for each use of params like params.width = 1080; would be params->width = 1080;, since it will be a pointer now.

The rest of the code should be ok.

api55
  • 11,070
  • 4
  • 41
  • 57
  • 1
    @IanCoghill can you provide me the link to this tutorial?, just as a small test, does it compiles without passing the params? which version of OpenCV are you using? maybe they change the function... does the error change? or is the same? just in case, I was talking about changing this line `structured_light::SinusoidalPattern::Params params;` – api55 Jan 18 '18 at 15:00
  • Thank you for the help. I am still getting errors. I took this piece of code from the OpenCV Sinusoidal Pattern tutorial: "https://docs.opencv.org/3.3.0/d0/de8/tutorial_capture_sinusoidal_pattern.html" Even trying the full code provided there comes up with the same error. My changes resulted in the following: `Ptr sinus = makePtr< cv::structured_light::SinusoidalPattern::Params >(); // Storage for patterns vector patterns; //Generate sinusoidal patterns sinus->generate(patterns); ` Error: class has no member "generate" – Ian Coghill Jan 18 '18 at 15:02
  • It worked, I am sorry I misunderstood. Thanks very much again. – Ian Coghill Jan 18 '18 at 15:10
  • @IanCoghill good to here that, I edited the question to make it more clear for the next reader :) – api55 Jan 18 '18 at 15:12