#include "stdafx.h"
|
#include "InChipDotProcess.h"
|
#include "VisionBufferPro.h"
|
#include "Bspline.h"
|
|
CInChipDotProcess::CInChipDotProcess(){
|
/* code */
|
m_nSampleNumber = 16;
|
m_nLineWidth = 50;
|
m_nChipOffset = -32;
|
m_nChipRange = 30;
|
m_threshold = 20;
|
m_nPointType = 1;
|
m_nPointMode = 2;
|
m_eDir = DIMENSION_NONE;
|
CVisionBufferPro::getLineFrameSize(m_eDir, m_nFrameWidth, m_nFrameHeight);
|
ClsVision::GenEmptyObject(m_hRoiRegion);
|
}
|
|
CInChipDotProcess::CInChipDotProcess(DimensionDir eDir) {
|
/* code */
|
m_nSampleNumber = 16;
|
m_nLineWidth = 100;
|
m_nChipOffset = -32;
|
m_nChipRange = 30;
|
m_threshold = 20;
|
m_nPointType = 1;
|
m_nPointMode = 2;
|
m_eDir = eDir;
|
CVisionBufferPro::getLineFrameSize(m_eDir, m_nFrameWidth, m_nFrameHeight);
|
ClsVision::GenEmptyObject(m_hRoiRegion);
|
}
|
|
CInChipDotProcess::~CInChipDotProcess()
|
{
|
}
|
|
int CInChipDotProcess::Execute(DimensionDir eDir, int index, Point2I ptStart, Point2I ptEnd) {
|
/* code */
|
if (index < 0) return 0;
|
|
return ExeInChip(eDir, index, ptStart, ptEnd);
|
}
|
|
int CInChipDotProcess::ExeInChip(DimensionDir eDir, int index, Point2I ptStart, Point2I ptEnd) {
|
/* code */
|
if (m_nFrameWidth < 1 || m_nFrameHeight < 1) return 0;
|
|
int y1 = index * m_nFrameHeight;
|
int y2 = index * m_nFrameHeight + m_nFrameHeight - 1;
|
int x1 = ptStart.x - m_nLineWidth;
|
int x2 = ptEnd.x + m_nLineWidth;
|
if (ptStart.x > ptEnd.x) {
|
x1 = ptEnd.x - m_nLineWidth;
|
x2 = ptStart.x + m_nLineWidth;
|
}
|
x1 -= 30;
|
x2 += 30;
|
HalconCpp::HObject hImage;
|
if (!CVisionBufferPro::getImageROI(m_eDir, hImage, x1, y1, x2, y2)) return 0;
|
int leftPos = x1;
|
int topPos = y1;
|
|
int width = 0;
|
int height = 0;
|
ClsVision::GetImageSize(hImage, width, height);
|
//HalconCpp::HWindow hDispWin(0, 0, width, height);
|
//hDispWin.SetPart(0, 0, height - 1, width - 1);
|
//hDispWin.SetColored(6);
|
//hDispWin.DispObj(hImage);
|
|
std::vector<Point2D> vEdgePoints;
|
int step = (int)(1.0 * (y2 - y1) / (m_nSampleNumber - 1));
|
for (int i = 0; i < m_nSampleNumber; i++) {
|
int yTarget = y1 + i * step;
|
if (0 == i) {
|
yTarget = y1 + 15;
|
}
|
else if (m_nSampleNumber - 1 == i) {
|
yTarget = y2 - 15;
|
}
|
|
Line2D line;
|
line.pt0.x = 30;
|
line.pt0.y = yTarget - topPos;
|
line.pt1.x = x2 - leftPos - 31;
|
line.pt1.y = yTarget - topPos;
|
Point2D ptStart, ptEnd;
|
if (!CVisionBufferPro::GetMeasurePos(hImage, line, m_threshold, m_nPointMode, 10, ptStart, ptEnd)) continue;
|
if (0 == i) {
|
ptStart.y = 0;
|
ptEnd.y = 0;
|
}
|
else if (m_nSampleNumber - 1 == i) {
|
ptStart.y = height - 1;
|
ptEnd.y = height - 1;
|
}
|
|
if (0 == m_nPointType) {
|
vEdgePoints.push_back(ptStart);
|
}
|
else {
|
vEdgePoints.push_back(ptEnd);
|
}
|
}
|
|
int num = (int)(vEdgePoints.size());
|
if (num < 0.5 * m_nSampleNumber) return 0;
|
|
//1. »ñÈ¡µãÕó
|
std::vector<vec> vStartCtrlPoint;
|
for (int i = 0; i < num; i++) {
|
float x0 = (float)vEdgePoints[i].x;
|
float y0 = (float)vEdgePoints[i].y;
|
vec p0(x0, y0, 0);
|
vStartCtrlPoint.push_back(p0);
|
}
|
|
//2. Ö´ÐÐÑùÌõ²åÖµ
|
CBspline bcurve(vStartCtrlPoint);
|
bcurve.execute();
|
|
int sz = (int)(bcurve.m_vPtResults.size());
|
if (sz < 1) return 0;
|
HalconCpp::HTuple hvY, hvX;
|
for (int i = 0; i < sz; i++) {
|
hvX[i] = bcurve.m_vPtResults[i][0] + m_nChipOffset;
|
hvY[i] = bcurve.m_vPtResults[i][1];
|
}
|
int idx = sz;
|
hvX[idx] = bcurve.m_vPtResults[sz - 1][0] + m_nChipOffset;
|
hvY[idx] = bcurve.m_vPtResults[sz - 1][1];
|
idx += 1;
|
hvX[idx] = bcurve.m_vPtResults[sz - 1][0] + m_nChipOffset + m_nChipRange;
|
hvY[idx] = bcurve.m_vPtResults[sz - 1][1];
|
idx += 1;
|
for (int i = sz - 1; i >= 0; i--) {
|
hvX[idx] = bcurve.m_vPtResults[i][0] + m_nChipOffset + m_nChipRange;
|
hvY[idx] = bcurve.m_vPtResults[i][1];
|
idx += 1;
|
}
|
|
HalconCpp::GenRegionPolygonFilled(&m_hRoiRegion, hvY, hvX);
|
//hDispWin.DispObj(m_hRoiRegion);
|
//hDispWin.Click();
|
|
HalconCpp::HObject hProObject, hRegion, hConnectRegion;
|
HalconCpp::ReduceDomain(hImage, m_hRoiRegion, &hProObject);
|
HalconCpp::Threshold(hProObject, &hRegion, 0, 60);
|
HalconCpp::Connection(hRegion, &hConnectRegion);
|
//hDispWin.ClearWindow();
|
//hDispWin.DispObj(hImage);
|
//hDispWin.DispObj(hConnectRegion);
|
//hDispWin.Click();
|
|
return 0;
|
}
|