You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.8 KiB
C++
112 lines
3.8 KiB
C++
#ifndef COUTLINEDETECTOR_H
|
|
#define COUTLINEDETECTOR_H
|
|
//轮廓线识别
|
|
#include <opencv2\opencv.hpp>
|
|
#include <QImage>
|
|
#include <vector>
|
|
using namespace cv;
|
|
using std::vector;
|
|
class GSurface;
|
|
class COutlineDetector
|
|
{
|
|
public:
|
|
COutlineDetector();
|
|
void clear(void);
|
|
|
|
void setSurface(GSurface* pSurf, float zlower = 0, float zupper = 0, unsigned int nIters = 1);
|
|
//膨胀迭代次数
|
|
void setIterations(unsigned int nIterations);
|
|
//设置目标区域z值范围
|
|
void setTargetZRange(float zlower, float zupper);
|
|
//设置最小轮廓线面积
|
|
void setContourMinArea(float area);
|
|
//设置输出轮廓线平滑次数
|
|
void setContourSmoothTimes(unsigned int times);
|
|
|
|
|
|
//执行图像处理,生成初始轮廓线,并进行光滑
|
|
bool ProcessImage(void);
|
|
|
|
////输出轮廓线
|
|
//bool WriteContours(const char* path);
|
|
|
|
////合并轮廓线,需先进行图像处理
|
|
//void CombineContours(std::vector<cv::Point2f>& dstContour);
|
|
|
|
|
|
//生成沉积相轮廓线,局部合并内部包含孔洞的轮廓线
|
|
int CreateFaciesContours(void);
|
|
|
|
|
|
|
|
//输出轮廓线
|
|
bool WriteContours( std::vector<std::vector<cv::Point>>& contous, const char* path);
|
|
//输出轮廓线
|
|
bool WriteContours( std::vector<std::vector<cv::Point2f>>& contous, const char* path);
|
|
Mat& getResultMat(); //返回结果图片
|
|
|
|
//曲面转换成mat 黑白图
|
|
static void convertSurfaceToMat(GSurface* pSrcSurf, float zlower, float zupper, Mat& dstMat);
|
|
//mat 转换为 surface
|
|
static bool convertMatToSurface(Mat& srcMat, float x0, float y0, float deltX, float deltY, GSurface* pDstSurf);
|
|
|
|
//Mat 转换为QImage
|
|
static bool ConvertMatToQImage(cv::Mat& src, QImage& dst, QImage::Format format = QImage::Format_ARGB32_Premultiplied);
|
|
//QImage转换为Mat
|
|
static bool ConvertQImageToMat(const QImage &image, cv::Mat& mat);
|
|
//五点三次平滑
|
|
static bool Smooth53(double* val, int n, int stimes=1);
|
|
//图片中轮廓线转换为曲面坐标 dstContour, smoothTimes转换后为平滑次数
|
|
void multiContourToRealCoords(const std::vector< std::vector<cv::Point2f> >& inputContour, std::vector< std::vector<cv::Point2f> > & dstContour, int smoothTimes);
|
|
|
|
//五点三次平滑
|
|
void SmoothContours();
|
|
//获取初始轮廓线
|
|
std::vector<std::vector<cv::Point2f>>& GetOriginalContours(void);
|
|
//获取沉积相轮廓线
|
|
std::vector<std::vector<cv::Point2f>>& GetFaciesContours(void);
|
|
private:
|
|
|
|
void morphologySolve(void);
|
|
//由matMorp生成轮廓线
|
|
void createContours(void);
|
|
//面积过滤输出等值线,不符合条件的剔除
|
|
void FilterContours(float minArea, std::vector<std::vector<cv::Point2f>>& ReservedContours);
|
|
|
|
|
|
//图片中轮廓线转换为曲面坐标 dstContour, smoothTimes转换后为平滑次数
|
|
void contourToRealCoords(const std::vector<cv::Point2f>& inputContour, std::vector<cv::Point2f>& dstContour, int smoothTimes);
|
|
|
|
//平滑轮廓线
|
|
void SmoothContour( std::vector<cv::Point2f>& inputContour, int nTimes);
|
|
//平滑跟轮廓线,可能部分在边界上
|
|
void SmoothRootContour(std::vector<cv::Point2f>& inputContour, int nTimes);
|
|
//点是否在边界线上
|
|
bool isPtOnBorder(const Point &pt);
|
|
|
|
|
|
|
|
//生成边界轮廓线
|
|
void TraceBorder(void);
|
|
|
|
GSurface* m_pSurface;
|
|
Mat m_matSrc; //原始图片(黑白图)
|
|
Mat m_matMorp; // 形态学处理后的图片
|
|
Mat m_matBorder; //用来追踪边界轮廓的黑白图
|
|
|
|
int m_nIterations;
|
|
float m_zlower;
|
|
float m_zupper;
|
|
double m_minArea;
|
|
int m_smoothTimes;
|
|
//图像处理后 生成的初始轮廓线
|
|
std::vector<std::vector<cv::Point2f>> m_originalContours;
|
|
std::vector<cv::Vec4i> m_hierarchy;
|
|
std::vector<std::vector<cv::Point2f>> m_faciesContours;
|
|
std::vector<cv::Point2f> m_border;
|
|
|
|
|
|
};
|
|
|
|
#endif // COUTLINEDETECTOR_H
|