opencv3.2+vs2017使用LSD算法时Error: image.type() == CV_8UC1
如题,代码如下
#include "stdafx.h"
#include <iostream>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat image1 = imread("t2.jpg",CV_8SC2);//读入原图,需为灰度图像
//Canny(image1, image1, 50, 200, 3);
Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_STD);
double start = double(getTickCount());
vector<Vec4f> lines_std;
// Detect the lines
if (!image1.empty()) {
ls->detect(image1, lines_std);//这里把检测到的直线线段都存入了lines_std中,4个float的值,分别为起止点的坐标
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
std::cout << "It took " << duration_ms << " ms." << std::endl;
// Show found lines
Mat drawnLines(image1);
ls->drawSegments(drawnLines, lines_std);
imshow("Standard refinement", drawnLines);
}
imshow("p1", image1);
waitKey(0);
return 0;
}
图片载入没有问题,在
ls->detect(image1, lines_std);这里报错