|
|
/*
|
|
|
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
|
|
*/
|
|
|
#ifndef ImageMerge_H_
|
|
|
#define ImageMerge_H_
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
#include "CheckUtil.hpp"
|
|
|
#include "CheckErrorCodeDefine.hpp"
|
|
|
#include "ImageDetConfig.h"
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace cv;
|
|
|
|
|
|
// 图片特征定位
|
|
|
class ImageMerge
|
|
|
{
|
|
|
public:
|
|
|
// 搜索方向
|
|
|
enum Edge_DirectSign
|
|
|
{
|
|
|
DirectSign_UP,
|
|
|
DirectSign_DOWN,
|
|
|
DirectSign_Left,
|
|
|
DirectSign_Right,
|
|
|
};
|
|
|
// 搜索边缘了下,黑还是白
|
|
|
enum Search_Value_Type
|
|
|
{
|
|
|
Search_Value_White,
|
|
|
Search_Value_Black,
|
|
|
};
|
|
|
// 边缘搜索参数
|
|
|
struct Edge_Search_Config
|
|
|
{
|
|
|
cv::Rect roi; // 边缘搜索区域
|
|
|
Search_Value_Type searchValueType; // 搜索边缘了下,黑还是白
|
|
|
Edge_DirectSign directSign; // 搜索方向
|
|
|
int nValueThreshold; // 灰度阈值
|
|
|
int nSearchCount; // 搜索点的个数 把roi 均分成多少个点。
|
|
|
int nSearchrange; // 搜索范围,一般为单数,如果 1表示 搜索当前点,如果3表示 除了当前点,还有左右 点。5表示 从-2到2
|
|
|
int stepCount; // 每个搜索点的步数
|
|
|
int nLimit; // 连续搜索多个满足阈值的点后,停止搜索,当前搜索点 搜索成功。
|
|
|
std::string strchannel;
|
|
|
Edge_Search_Config()
|
|
|
{
|
|
|
roi = cv::Rect(0, 0, 0, 0);
|
|
|
directSign = DirectSign_UP;
|
|
|
searchValueType = Search_Value_White;
|
|
|
nValueThreshold = 25;
|
|
|
nSearchCount = 30;
|
|
|
nSearchrange = 1;
|
|
|
stepCount = 2;
|
|
|
nLimit = 3;
|
|
|
strchannel = "";
|
|
|
}
|
|
|
bool CheckConfigValid()
|
|
|
{
|
|
|
bool bRet = true;
|
|
|
if (roi.width <= 0 || roi.height <= 0)
|
|
|
{
|
|
|
printf("s1 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (searchValueType < Search_Value_White || searchValueType > Search_Value_Black)
|
|
|
{
|
|
|
printf("s2 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (directSign < 0 || directSign > 4)
|
|
|
{
|
|
|
printf("s3 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (nValueThreshold < 0 || nValueThreshold > 255)
|
|
|
{
|
|
|
printf("s4 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (nSearchCount < 0)
|
|
|
{
|
|
|
printf("s5 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (stepCount < 0)
|
|
|
{
|
|
|
printf("s6 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (nLimit < 0)
|
|
|
{
|
|
|
printf("s7 \n");
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
};
|
|
|
struct Line
|
|
|
{
|
|
|
cv::Point p1;
|
|
|
cv::Point p2;
|
|
|
Line()
|
|
|
{
|
|
|
p1 = cv::Point(0, 0);
|
|
|
p2 = cv::Point(0, 0);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
public:
|
|
|
struct DetConfig
|
|
|
{
|
|
|
bool bSaveImg;
|
|
|
bool bSave_Process; // 存储过程图片
|
|
|
std::string strcam;
|
|
|
std::string strchannel;
|
|
|
DetConfig()
|
|
|
{
|
|
|
bSaveImg = false;
|
|
|
bSave_Process = false;
|
|
|
strcam = "";
|
|
|
strchannel = "";
|
|
|
}
|
|
|
};
|
|
|
|
|
|
public:
|
|
|
ImageMerge(/* args */);
|
|
|
~ImageMerge();
|
|
|
int CalMergeRoi(DetConfig *pDetConfig, cv::Mat &img1, const cv::Mat &img2);
|
|
|
int detMergeImg(cv::Mat &img1, const cv::Mat &img2);
|
|
|
|
|
|
private:
|
|
|
int GetRectAndPoint(const cv::Mat &img, cv::Rect &roi, cv::Point &merg_p_up, cv::Point &merg_p_down, bool bleft, std::string strcam, std::string strchannel);
|
|
|
|
|
|
// 边缘点搜索函数
|
|
|
int GetEdgePoint(const cv::Mat &img, Edge_Search_Config *pEdge_Search_Config, int &outP);
|
|
|
|
|
|
int GetLine(const cv::Mat &img, std::vector<cv::Point> &pointList, int lineNum, int xory, int &outP);
|
|
|
|
|
|
// 产品的位置
|
|
|
bool ProductSide_left(const cv::Mat &img);
|
|
|
|
|
|
private:
|
|
|
cv::Mat showimg;
|
|
|
bool bshowimg;
|
|
|
PRINT_LOG_ m_PrintLog;
|
|
|
|
|
|
bool m_bleft_img1;
|
|
|
cv::Rect m_roi_right_img;
|
|
|
cv::Rect m_roi_left_img;
|
|
|
cv::Rect m_roi_right_ALLimg;
|
|
|
cv::Rect m_roi_left_ALLimg;
|
|
|
bool m_bcalSucc;
|
|
|
cv::Size m_ALLImgSize;
|
|
|
|
|
|
private:
|
|
|
/* data */
|
|
|
};
|
|
|
|
|
|
#endif |