正弦模式生成的 OpenCV C++ 错误 - structured_light 库
OpenCV C++ Error with sinusoidal pattern generation - structured_light library
我正在尝试通过 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;
,因为它现在将是一个指针。
剩下的代码应该没问题。
我正在尝试通过 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;
,因为它现在将是一个指针。
剩下的代码应该没问题。