1918 lines
85 KiB
C++
1918 lines
85 KiB
C++
#include <952HalconAlgo.h>
|
||
#include <iostream>
|
||
//������
|
||
//ֱ���ߴ����
|
||
|
||
void _952_15_Distance_Down(HObject ho_in_Image1, HObject ho_in_Image2, HTuple hv_in_Filepath,
|
||
HTuple hv_in_Model, HTuple hv_in_StandaraB_D, HTuple hv_in_Measure_Point, HTuple* hv_out_Line1,
|
||
HTuple* hv_out_Line2, HTuple* hv_out_Distance, HTuple* hv_out_Flag)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_Rectangle1, ho_Rectangle2, ho_Rectangle3;
|
||
HObject ho_ImageMirror, ho_in_MeasureRegion, ho_ObjectsConcat1;
|
||
HObject ho_ObjectsConcat2, ho_ObjectsConcat3;
|
||
|
||
// Local control variables
|
||
HTuple hv_Debug, hv_in_Resolution, hv_in_Product_DPix;
|
||
HTuple hv_Width, hv_Height, hv_in_CameraType, hv_Exception;
|
||
|
||
|
||
//**********************************************************************
|
||
//Function Name: _952_15_Distance_Down
|
||
//Author:
|
||
//Description: ������ص�ֱ��(mm),
|
||
//Input:
|
||
// in_Image1, ������(bmp),
|
||
// in_Image2, �Ҳ����(bmp),
|
||
// in_Filepath, �궨�ļ�·��(tup),
|
||
// in_Model, ģʽ, 1:�������ݽ��б궨, 0:�������ݽ������߲���,
|
||
// in_StandaraB_D, �����ֱ��(mm)
|
||
// in_Measure_Point,
|
||
// in_Measure_Point[0],һ�Ų�����������������(x1)
|
||
// in_Measure_Point[1],һ�Ų�����������������(x2)
|
||
// in_Measure_Point[2],��������������������(x1)
|
||
// in_Measure_Point[3],��������������������(x2)
|
||
// in_Measure_Point[4],��������������������(x1)
|
||
// in_Measure_Point[5],��������������������(x2)
|
||
//output�� out_Line1, ���������Ƶ���(),
|
||
// out_Line2, �Ҳ�������Ƶ���(),
|
||
// out_Distance, ������Բ��ֱ��(D1,D2,D3)
|
||
// out_Flag, �㷨ִ�еı�־λ; 0, �㷨ִ��NG 1,�㷨ִ��OK
|
||
//verion change log: ������ 2024-01-01 V1.1 Create new function
|
||
// ������ 2024-06-05 V1.2 ֱ������ֵ��1�����Ϊ3��.
|
||
// ������ 2024_06_19 V1.3 1, ��̬�궨������λ;
|
||
// 2, ����������λ;
|
||
//
|
||
//**********************************************************************
|
||
hv_Debug = 1;
|
||
(*hv_out_Line1) = HTuple();
|
||
(*hv_out_Line2) = HTuple();
|
||
(*hv_out_Distance) = HTuple();
|
||
(*hv_out_Flag) = 0;
|
||
hv_in_Resolution = 0.0058;
|
||
hv_in_Product_DPix = hv_in_StandaraB_D / 0.0058;
|
||
try
|
||
{
|
||
if (HDevWindowStack::IsOpen())
|
||
SetDraw(HDevWindowStack::GetActive(), "margin");
|
||
GetImageSize(ho_in_Image1, &hv_Width, &hv_Height);
|
||
//�㷨���ɲ�ͬ�IJ�����λ, ���ڿ���������.
|
||
GenRectangle1(&ho_Rectangle1, 20, HTuple(hv_in_Measure_Point[0]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[1]));
|
||
GenRectangle1(&ho_Rectangle2, 20, HTuple(hv_in_Measure_Point[2]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[3]));
|
||
GenRectangle1(&ho_Rectangle3, 20, HTuple(hv_in_Measure_Point[4]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[5]));
|
||
if (0 != hv_Debug)
|
||
{
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle2, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle3, HDevWindowStack::GetActive());
|
||
}
|
||
MirrorImage(ho_in_Image2, &ho_ImageMirror, "column");
|
||
if (0 != hv_Debug)
|
||
{
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ImageMirror, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ImageMirror, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle2, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ImageMirror, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle3, HDevWindowStack::GetActive());
|
||
}
|
||
GenEmptyObj(&ho_in_MeasureRegion);
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle1, &ho_ObjectsConcat1);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat1;
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle2, &ho_ObjectsConcat2);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat2;
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle3, &ho_ObjectsConcat3);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat3;
|
||
//�ô����������Ʒ���ͣ�
|
||
hv_in_CameraType = 3;
|
||
Cal_PP_Distance(ho_in_MeasureRegion, ho_in_Image1, ho_in_Image2, hv_in_Model,
|
||
hv_in_Product_DPix, hv_in_Filepath, hv_in_Resolution, hv_in_CameraType, &(*hv_out_Line1),
|
||
&(*hv_out_Line2), &(*hv_out_Distance), &(*hv_out_Flag));
|
||
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_out_Line1) = HTuple();
|
||
(*hv_out_Line2) = HTuple();
|
||
(*hv_out_Distance) = HTuple();
|
||
(*hv_out_Flag) = 0;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
void _952_15_Distance_MI(HObject ho_in_Image1, HObject ho_in_Image2, HTuple hv_in_Filepath,
|
||
HTuple hv_in_Model, HTuple hv_in_StandaraB_D, HTuple hv_in_Measure_Point, HTuple* hv_out_Line1,
|
||
HTuple* hv_out_Line2, HTuple* hv_out_Distance, HTuple* hv_out_Flag)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_Rectangle1, ho_Rectangle2, ho_Rectangle3;
|
||
HObject ho_in_MeasureRegion, ho_ObjectsConcat1, ho_ObjectsConcat2;
|
||
HObject ho_ObjectsConcat3;
|
||
|
||
// Local control variables
|
||
HTuple hv_Debug, hv_in_Resolution, hv_in_Product_DPix;
|
||
HTuple hv_Width, hv_Height, hv_in_CameraType, hv_Exception;
|
||
|
||
|
||
//**********************************************************************
|
||
//Function Name: _952_15_Distance_MI
|
||
//Author:
|
||
//Description: ������ص�ֱ��(mm),
|
||
//Input:
|
||
// in_Image1, ������(bmp),
|
||
// in_Image2, �Ҳ����(bmp),
|
||
// in_Filepath, �궨�ļ�·��(tup),
|
||
// in_Model, ģʽ, 1:�������ݽ��б궨, 0:�������ݽ������߲���,
|
||
// in_StandaraB_D, �����ֱ��(mm)
|
||
// in_Measure_Point,
|
||
// in_Measure_Point[0],һ�Ų�����������������(x1)
|
||
// in_Measure_Point[1],һ�Ų�����������������(x2)
|
||
// in_Measure_Point[2],��������������������(x1)
|
||
// in_Measure_Point[3],��������������������(x2)
|
||
// in_Measure_Point[4],��������������������(x1)
|
||
// in_Measure_Point[5],��������������������(x2)
|
||
//output�� out_Line1, ���������Ƶ���(),
|
||
// out_Line2, �Ҳ�������Ƶ���(),
|
||
// out_Distance, ������Բ��ֱ��(D1,D2,D3)
|
||
// out_Flag, �㷨ִ�еı�־λ; 0, �㷨ִ��NG 1,�㷨ִ��OK
|
||
//verion change log: ������ 2024-01-01 V1.1 Create new function
|
||
// ������ 2024-06-05 V1.2 ֱ������ֵ��1�����Ϊ3��.
|
||
// ������ 2024-06-19 V1.3 ���ڲ�ͬ�ĵ�λ, �궨�ļ�
|
||
//
|
||
//**********************************************************************
|
||
hv_Debug = 1;
|
||
(*hv_out_Line1) = HTuple();
|
||
(*hv_out_Line2) = HTuple();
|
||
(*hv_out_Distance) = HTuple();
|
||
(*hv_out_Flag) = 0;
|
||
hv_in_Resolution = 0.0058;
|
||
hv_in_Product_DPix = hv_in_StandaraB_D / 0.0058;
|
||
try
|
||
{
|
||
|
||
if (HDevWindowStack::IsOpen())
|
||
SetDraw(HDevWindowStack::GetActive(), "margin");
|
||
GetImageSize(ho_in_Image1, &hv_Width, &hv_Height);
|
||
|
||
//�㷨���ɲ�ͬ�IJ�����λ, ���ڿ���������.
|
||
GenRectangle1(&ho_Rectangle1, 20, HTuple(hv_in_Measure_Point[0]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[1]));
|
||
GenRectangle1(&ho_Rectangle2, 20, HTuple(hv_in_Measure_Point[2]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[3]));
|
||
GenRectangle1(&ho_Rectangle3, 20, HTuple(hv_in_Measure_Point[4]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[5]));
|
||
if (0 != hv_Debug)
|
||
{
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle2, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle3, HDevWindowStack::GetActive());
|
||
}
|
||
//mirror_image (in_Image2, ImageMirror, 'column')
|
||
if (0 != hv_Debug)
|
||
{
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image2, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle2, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Rectangle3, HDevWindowStack::GetActive());
|
||
}
|
||
|
||
GenEmptyObj(&ho_in_MeasureRegion);
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle1, &ho_ObjectsConcat1);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat1;
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle2, &ho_ObjectsConcat2);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat2;
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle3, &ho_ObjectsConcat3);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat3;
|
||
//�ô����������Ʒ���ͣ�
|
||
hv_in_CameraType = 2;
|
||
Cal_PP_Distance(ho_in_MeasureRegion, ho_in_Image1, ho_in_Image2, hv_in_Model,
|
||
hv_in_Product_DPix, hv_in_Filepath, hv_in_Resolution, hv_in_CameraType, &(*hv_out_Line1),
|
||
&(*hv_out_Line2), &(*hv_out_Distance), &(*hv_out_Flag));
|
||
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_out_Line1) = HTuple();
|
||
(*hv_out_Line2) = HTuple();
|
||
(*hv_out_Distance) = HTuple();
|
||
(*hv_out_Flag) = 0;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
void _952_15_Distance_UP(HObject ho_in_Image1, HObject ho_in_Image2, HTuple hv_in_Filepath,
|
||
HTuple hv_in_Model, HTuple hv_in_StandaraB_D, HTuple hv_in_Measure_Point, HTuple* hv_out_Line1,
|
||
HTuple* hv_out_Line2, HTuple* hv_out_Distance, HTuple* hv_out_Flag)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_Region1, ho_RegionOpening, ho_RegionBorder;
|
||
HObject ho_Rectangle1, ho_Rectangle2, ho_Rectangle3, ho_in_MeasureRegion;
|
||
HObject ho_ObjectsConcat1, ho_ObjectsConcat2, ho_ObjectsConcat3;
|
||
|
||
// Local control variables
|
||
HTuple hv_Debug, hv_in_Resolution, hv_in_Product_DPix;
|
||
HTuple hv_Width, hv_Height, hv_in_CameraType, hv_Exception;
|
||
|
||
|
||
//**********************************************************************
|
||
//Function Name: _952_15_Distance_UP
|
||
//Author:
|
||
//Description: �����������ص�ֱ��(mm),
|
||
//Input:
|
||
// in_Image1, ������(bmp),
|
||
// in_Image2, �Ҳ����(bmp),
|
||
// in_Filepath, �궨�ļ�·��(tup),
|
||
// in_Model, ģʽ, 1:�������ݽ��б궨, 0:�������ݽ������߲���,
|
||
// in_StandaraB_D, �����ֱ��(mm)
|
||
// in_Measure_Point,
|
||
// in_Measure_Point[0],һ�Ų�����������������(x1)
|
||
// in_Measure_Point[1],һ�Ų�����������������(x2)
|
||
// in_Measure_Point[2],��������������������(x1)
|
||
// in_Measure_Point[3],��������������������(x2)
|
||
// in_Measure_Point[4],��������������������(x1)
|
||
// in_Measure_Point[5],��������������������(x2)
|
||
//output�� out_Line1, ���������Ƶ���(),
|
||
// out_Line2, �Ҳ�������Ƶ���(),
|
||
// out_Distance, ������Բ��ֱ��(D1,D2,D3)
|
||
// out_Flag, �㷨ִ�еı�־λ; 0, �㷨ִ��NG 1,�㷨ִ��OK
|
||
//verion change log: ������ 2024-01-01 V1.1 Create new function
|
||
// ������ 2024-06-05 V1.2 ֱ������ֵ��1�����Ϊ3��.
|
||
// ������ 2024-06-19 V1.3 �궨�����λ�ø���,
|
||
//**********************************************************************
|
||
hv_Debug = 1;
|
||
(*hv_out_Line1) = HTuple();
|
||
(*hv_out_Line2) = HTuple();
|
||
(*hv_out_Distance) = HTuple();
|
||
(*hv_out_Flag) = 0;
|
||
hv_in_Resolution = 0.0058;
|
||
hv_in_Product_DPix = hv_in_StandaraB_D / 0.0058;
|
||
try
|
||
{
|
||
|
||
if (HDevWindowStack::IsOpen())
|
||
SetDraw(HDevWindowStack::GetActive(), "margin");
|
||
GetImageSize(ho_in_Image1, &hv_Width, &hv_Height);
|
||
Threshold(ho_in_Image1, &ho_Region1, 0, 200);
|
||
OpeningRectangle1(ho_Region1, &ho_RegionOpening, 25, 25);
|
||
Boundary(ho_RegionOpening, &ho_RegionBorder, "inner");
|
||
//gen_rectangle1 (Rectangle1, 130, 1491, Height-30, Width-10)
|
||
//�㷨���ɲ�ͬ�IJ�����λ, ���ڿ���������.
|
||
GenRectangle1(&ho_Rectangle1, 20, HTuple(hv_in_Measure_Point[0]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[1]));
|
||
GenRectangle1(&ho_Rectangle2, 20, HTuple(hv_in_Measure_Point[2]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[3]));
|
||
GenRectangle1(&ho_Rectangle3, 20, HTuple(hv_in_Measure_Point[4]), hv_Height - 20,
|
||
HTuple(hv_in_Measure_Point[5]));
|
||
//if (Debug)
|
||
//dev_display (in_Image1)
|
||
//dev_display (Rectangle1)
|
||
//dev_display (Rectangle2)
|
||
//dev_display (Rectangle3)
|
||
//endif
|
||
//mirror_image (in_Image2, ImageMirror, 'column')
|
||
//if (Debug)
|
||
//* dev_display (ImageMirror)
|
||
//dev_display (Rectangle1)
|
||
//dev_display (Rectangle2)
|
||
//dev_display (Rectangle3)
|
||
//endif
|
||
GenEmptyObj(&ho_in_MeasureRegion);
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle1, &ho_ObjectsConcat1);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat1;
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle2, &ho_ObjectsConcat2);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat2;
|
||
ConcatObj(ho_in_MeasureRegion, ho_Rectangle3, &ho_ObjectsConcat3);
|
||
ho_in_MeasureRegion = ho_ObjectsConcat3;
|
||
|
||
//�ô����������Ʒ���ͣ�
|
||
hv_in_CameraType = 1;
|
||
Cal_PP_Distance(ho_in_MeasureRegion, ho_in_Image1, ho_in_Image2, hv_in_Model,
|
||
hv_in_Product_DPix, hv_in_Filepath, hv_in_Resolution, hv_in_CameraType, &(*hv_out_Line1),
|
||
&(*hv_out_Line2), &(*hv_out_Distance), &(*hv_out_Flag));
|
||
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_out_Line1) = HTuple();
|
||
(*hv_out_Line2) = HTuple();
|
||
(*hv_out_Distance) = HTuple();
|
||
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
|
||
// ¥��¶�ײ���
|
||
void _952_15_Distance(HObject ho_Image, HTuple* hv_Out_Mean, HTuple* hv_Out_Max,
|
||
HTuple* hv_Out_Min, HTuple* hv_Out_Line1, HTuple* hv_Out_Line2, HTuple* hv_Make)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_ImageResult, ho_ImageMedian, ho_ImageEmphasize;
|
||
HObject ho_Region, ho_ConnectedRegions, ho_SelectedRegions;
|
||
HObject ho_RegionDilation, ho_ImageReduced, ho_Region1;
|
||
HObject ho_RegionOpening, ho_ConnectedRegions1, ho_SelectedRegions1;
|
||
HObject ho_SelectedRegions2, ho_RegionUnion, ho_Cross, ho_Regions;
|
||
HObject ho_Line, ho_RegionDilation1, ho_ImageReduced1, ho_Edges;
|
||
HObject ho_SelectedXLD, ho_UnionContours, ho_SelectedXLD1;
|
||
|
||
// Local control variables
|
||
HTuple hv_UsedThreshold, hv_UsedThreshold1, hv_Row1;
|
||
HTuple hv_Column1, hv_Row2, hv_Column2, hv_out_rows, hv_out_cols;
|
||
HTuple hv_ResultRow, hv_ResultColumn, hv_Row11, hv_Column11;
|
||
HTuple hv_Row21, hv_Column21, hv_Length2, hv_RowBegin;
|
||
HTuple hv_ColBegin, hv_RowEnd, hv_ColEnd, hv_Nr, hv_Nc;
|
||
HTuple hv_Dist, hv_Row, hv_Col, hv_Length, hv_Length1;
|
||
HTuple hv_Distance, hv_Sorted, hv_start, hv_end, hv_distSelected;
|
||
HTuple hv_Mean, hv_Max, hv_Min, hv_Exception;
|
||
|
||
(*hv_Out_Mean) = -99;
|
||
(*hv_Out_Max) = -99;
|
||
(*hv_Out_Min) = -99;
|
||
(*hv_Out_Line1).Clear();
|
||
(*hv_Out_Line1)[0] = -99;
|
||
(*hv_Out_Line1)[1] = -99;
|
||
(*hv_Out_Line1)[2] = -99;
|
||
(*hv_Out_Line1)[3] = -99;
|
||
(*hv_Out_Line2).Clear();
|
||
(*hv_Out_Line2)[0] = -99;
|
||
(*hv_Out_Line2)[1] = -99;
|
||
(*hv_Out_Line2)[2] = -99;
|
||
(*hv_Out_Line2)[3] = -99;
|
||
(*hv_Make) = -1;
|
||
try
|
||
{
|
||
MultImage(ho_Image, ho_Image, &ho_ImageResult, 0.01, 0);
|
||
MedianImage(ho_ImageResult, &ho_ImageMedian, "circle", 4, "mirrored");
|
||
Emphasize(ho_ImageMedian, &ho_ImageEmphasize, 117, 117, 1);
|
||
BinaryThreshold(ho_ImageEmphasize, &ho_Region, "max_separability", "light", &hv_UsedThreshold);
|
||
Connection(ho_Region, &ho_ConnectedRegions);
|
||
SelectShapeStd(ho_ConnectedRegions, &ho_SelectedRegions, "max_area", 70);
|
||
DilationRectangle1(ho_SelectedRegions, &ho_RegionDilation, 31, 31);
|
||
ReduceDomain(ho_ImageEmphasize, ho_RegionDilation, &ho_ImageReduced);
|
||
BinaryThreshold(ho_ImageReduced, &ho_Region1, "max_separability", "light", &hv_UsedThreshold1);
|
||
OpeningRectangle1(ho_Region1, &ho_RegionOpening, 20, 20);
|
||
Connection(ho_RegionOpening, &ho_ConnectedRegions1);
|
||
SelectShape(ho_ConnectedRegions1, &ho_SelectedRegions1, "column", "and", 2906.65,
|
||
5000);
|
||
SelectShape(ho_SelectedRegions1, &ho_SelectedRegions2, "area", "and", 3136.53,
|
||
200000);
|
||
Union1(ho_SelectedRegions2, &ho_RegionUnion);
|
||
SmallestRectangle1(ho_RegionUnion, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
|
||
//�ұ�Ե��
|
||
get_rectangle1_corners(hv_Row1, hv_Column1, hv_Row2, hv_Column2, &hv_out_rows,
|
||
&hv_out_cols);
|
||
GenCrossContourXld(&ho_Cross, hv_out_rows, hv_out_cols, 46, 0.785398);
|
||
rake(ho_ImageEmphasize, &ho_Regions, 1300, 60, 15, 1, 20, "all", "max", HTuple(hv_out_rows[1]),
|
||
HTuple(hv_out_cols[1]), HTuple(hv_out_rows[3]), HTuple(hv_out_cols[3]), &hv_ResultRow,
|
||
&hv_ResultColumn);
|
||
pts_to_best_line(&ho_Line, hv_ResultRow, hv_ResultColumn, 2, &hv_Row11, &hv_Column11,
|
||
&hv_Row21, &hv_Column21);
|
||
TupleLength(hv_Row11, &hv_Length2);
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ImageEmphasize, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Line, HDevWindowStack::GetActive());
|
||
//���Ե��
|
||
DilationRectangle1(ho_RegionUnion, &ho_RegionDilation1, 40, 40);
|
||
ReduceDomain(ho_ImageEmphasize, ho_RegionDilation1, &ho_ImageReduced1);
|
||
EdgesColorSubPix(ho_ImageReduced1, &ho_Edges, "canny", 5, 3, 10);
|
||
SelectShapeXld(ho_Edges, &ho_SelectedXLD, "column", "and", 23.11, 3437);
|
||
UnionAdjacentContoursXld(ho_SelectedXLD, &ho_UnionContours, 60, 7, "attr_keep");
|
||
SelectShapeXld(ho_UnionContours, &ho_SelectedXLD1, "contlength", "and", 2486.14,
|
||
10000);
|
||
FitLineContourXld(ho_SelectedXLD1, "tukey", -1, 0, 5, 2, &hv_RowBegin, &hv_ColBegin,
|
||
&hv_RowEnd, &hv_ColEnd, &hv_Nr, &hv_Nc, &hv_Dist);
|
||
GetContourXld(ho_SelectedXLD1, &hv_Row, &hv_Col);
|
||
TupleLength(hv_Row, &hv_Length);
|
||
TupleLength(hv_Row11, &hv_Length1);
|
||
if (0 != (HTuple(int(hv_Length > 0)).TupleAnd(int(hv_Length1 > 0))))
|
||
{
|
||
(*hv_Out_Line1).Clear();
|
||
(*hv_Out_Line1).Append(hv_Row11);
|
||
(*hv_Out_Line1).Append(hv_Column11);
|
||
(*hv_Out_Line1).Append(hv_Row21);
|
||
(*hv_Out_Line1).Append(hv_Column21);
|
||
(*hv_Out_Line2).Clear();
|
||
(*hv_Out_Line2).Append(hv_RowBegin);
|
||
(*hv_Out_Line2).Append(hv_ColBegin);
|
||
(*hv_Out_Line2).Append(hv_RowEnd);
|
||
(*hv_Out_Line2).Append(hv_ColEnd);
|
||
DistancePl(hv_Row, hv_Col, hv_Row11, hv_Column11, hv_Row21, hv_Column21, &hv_Distance);
|
||
TupleSort(hv_Distance, &hv_Sorted);
|
||
TupleLength(hv_Sorted, &hv_Length);
|
||
hv_start = (hv_Length * 0.1).TupleInt();
|
||
hv_end = (hv_Length * (1 - 0.1)).TupleInt();
|
||
//ȥ��ǰ��ٷ�֮2����ֵ
|
||
TupleSelect(hv_Sorted, HTuple::TupleGenSequence(hv_start, hv_end, 1), &hv_distSelected);
|
||
TupleMean(hv_distSelected, &hv_Mean);
|
||
TupleMax(hv_distSelected, &hv_Max);
|
||
TupleMin(hv_distSelected, &hv_Min);
|
||
(*hv_Out_Mean) = hv_Mean;
|
||
(*hv_Out_Max) = hv_Max;
|
||
(*hv_Out_Min) = hv_Min;
|
||
(*hv_Make) = 1;
|
||
}
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_Out_Mean) = -99;
|
||
(*hv_Out_Max) = -99;
|
||
(*hv_Out_Min) = -99;
|
||
(*hv_Out_Line1).Clear();
|
||
(*hv_Out_Line1)[0] = -99;
|
||
(*hv_Out_Line1)[1] = -99;
|
||
(*hv_Out_Line1)[2] = -99;
|
||
(*hv_Out_Line1)[3] = -99;
|
||
(*hv_Out_Line2).Clear();
|
||
(*hv_Out_Line2)[0] = -99;
|
||
(*hv_Out_Line2)[1] = -99;
|
||
(*hv_Out_Line2)[2] = -99;
|
||
(*hv_Out_Line2)[3] = -99;
|
||
(*hv_Make) = -1;
|
||
}
|
||
return;
|
||
}
|
||
//3D��ͼ
|
||
void _952_15_caitu(HObject ho_Image, HObject ho_Image_H, HObject* ho_out_Image,
|
||
HObject* ho_out_Image_H, HTuple hv_In_x, HTuple hv_In_y, HTuple hv_In_z, HTuple* hv_Make)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_EmptyObject, ho_ImageZoom, ho_Region2;
|
||
HObject ho_ConnectedRegions3, ho_SelectedRegions4, ho_ImagePart1;
|
||
HObject ho_ImageZoom_H, ho_ImagePart2;
|
||
|
||
// Local control variables
|
||
HTuple hv_UsedThreshold1, hv_Row11, hv_Column11;
|
||
HTuple hv_Row21, hv_Column21, hv_Number, hv_Number1, hv_Exception;
|
||
|
||
|
||
(*hv_Make) = -1;
|
||
GenEmptyObj(&ho_EmptyObject);
|
||
(*ho_out_Image) = ho_EmptyObject;
|
||
try
|
||
{
|
||
//����ͼƬ
|
||
ZoomImageSize(ho_Image, &ho_ImageZoom, 340, 550, "constant");
|
||
//��λ��о��ͼ
|
||
BinaryThreshold(ho_ImageZoom, &ho_Region2, "max_separability", "light", &hv_UsedThreshold1);
|
||
Connection(ho_Region2, &ho_ConnectedRegions3);
|
||
SelectShapeStd(ho_ConnectedRegions3, &ho_SelectedRegions4, "max_area", 70);
|
||
SmallestRectangle1(ho_SelectedRegions4, &hv_Row11, &hv_Column11, &hv_Row21, &hv_Column21);
|
||
//��ͼ���ڽ�ģ
|
||
CropPart(ho_ImageZoom, &ho_ImagePart1, hv_Row11, hv_Column11, 340, 340);
|
||
////////////////////////////////////////
|
||
//���ͼ
|
||
ZoomImageSize(ho_Image_H, &ho_ImageZoom_H, 340, 550, "constant");
|
||
CropPart(ho_ImageZoom_H, &ho_ImagePart2, hv_Row11, hv_Column11, 340, 340);
|
||
CountObj(ho_ImagePart1, &hv_Number);
|
||
CountObj(ho_ImagePart2, &hv_Number1);
|
||
if (0 != (HTuple(int(hv_Number == 1)).TupleAnd(int(hv_Number1 == 1))))
|
||
{
|
||
(*hv_Make) = 1;
|
||
(*ho_out_Image) = ho_ImagePart1;
|
||
(*ho_out_Image_H) = ho_ImagePart2;
|
||
}
|
||
|
||
|
||
//binary_threshold (Image_H, Region1, 'max_separability', 'dark', UsedThreshold)
|
||
//dilation_circle (Region1, RegionDilation1, 9)
|
||
//connection (RegionDilation1, ConnectedRegions2)
|
||
|
||
//select_shape (ConnectedRegions2, SelectedRegions2, 'circularity', 'and', 0.36, 1)
|
||
//dilation_circle (SelectedRegions2, RegionDilation, 8)
|
||
//smallest_circle (RegionDilation, Row1, Column1, Radius1)
|
||
//gen_circle (Circle1, Row1, Column1, Radius1)
|
||
//dev_display (Image_H)
|
||
//threshold (Image_H, Regions, 23453, 65535)
|
||
//erosion_circle (Regions, RegionErosion1, 25)
|
||
//connection (RegionErosion1, ConnectedRegions1)
|
||
//select_shape_std (ConnectedRegions1, SelectedRegions1, 'max_area', 70)
|
||
//get_image_type (Image_H, Type)
|
||
//if (Type # 'real')
|
||
//convert_image_type (Image_H, ImageConverted1, 'real')
|
||
//else
|
||
//ImageConverted1 := Image_H
|
||
//endif
|
||
|
||
//get_image_size (Image_H, Width, Height)
|
||
//gen_image_surface_first_order (YImageSurface, 'real', 1, 0, 0, 0, 0, Width, Height)
|
||
//gen_image_surface_first_order (XImageSurface, 'real', 0, 1, 0, 0, 0, Width, Height)
|
||
//scale_image (XImageSurface, XImageScaled, In_x, 0)
|
||
//scale_image (YImageSurface, YImageScaled, In_y, 0)
|
||
//scale_image (ImageConverted1, ZImageScaled, In_z, 0)
|
||
|
||
//reduce_domain (XImageScaled, SelectedRegions1, ImageReduced_X)
|
||
//reduce_domain (YImageScaled, SelectedRegions1, ImageReduced_Y)
|
||
//reduce_domain (ZImageScaled, SelectedRegions1, ImageReduced_Z)
|
||
//get_domain (ImageReduced_Z, Domain)
|
||
//xyz_to_object_model_3d (ImageReduced_X, ImageReduced_Y, ImageReduced_Z, ObjectModel3D)
|
||
//���ƽ��
|
||
//ParFitting := ['primitive_type', 'fitting_algorithm', 'output_xyz_mapping']
|
||
//ValFitting := ['plane','least_squares_huber', 'false']
|
||
//fit_primitives_object_model_3d (ObjectModel3D, ParFitting, ValFitting, ObjectModel3DOut)
|
||
//get_object_model_3d_params (ObjectModel3DOut, 'primitive_parameter', GenParamValue)
|
||
//A := GenParamValue[0]
|
||
//B := GenParamValue[1]
|
||
//C := GenParamValue[2]
|
||
//D := GenParamValue[3]
|
||
//get_region_points (Image_H, Rows, Columns)
|
||
//get_grayval (XImageScaled, Rows, Columns, X)
|
||
//get_grayval (YImageScaled, Rows, Columns, Y)
|
||
//get_grayval (ZImageScaled, Rows, Columns, Z)
|
||
//Dist := A* X + B* Y + C * Z - D
|
||
//if (C < 0)
|
||
//Dist := -Dist
|
||
//endif
|
||
//tuple_length (Dist, Length)
|
||
//if (Length==1)
|
||
//selset_value := Dist+0.001
|
||
//else
|
||
//selset_value := 0.0
|
||
//endif
|
||
//tuple_less_elem (Dist, selset_value, Less)
|
||
//tuple_mult (Less, Rows, Prod_X)
|
||
//tuple_mult (Less, Columns, Prod_Y)
|
||
//gen_region_points (Region, Prod_X, Prod_Y)
|
||
//closing_circle (Region, RegionClosing, 0.5)
|
||
//complement (RegionClosing, RegionComplement)
|
||
//connection (RegionComplement, ConnectedRegions)
|
||
|
||
//select_shape (ConnectedRegions, SelectedRegions3, 'rectangularity', 'and', 0, 0.80961)
|
||
//select_shape_std (SelectedRegions3, SelectedRegions, 'max_area', 70)
|
||
|
||
//fill_up (SelectedRegions, RegionFillUp)
|
||
//erosion_circle (RegionFillUp, RegionErosion, 5)
|
||
//smallest_circle (RegionErosion, Row, Column, Radius)
|
||
//gen_circle (Circle, Row, Column, Radius)
|
||
//difference (Circle, Circle1, ROI_0)
|
||
//reduce_domain (Image_H, SelectedRegions, ImageReduced)
|
||
//reduce_domain (Image_H, ROI_0, ImageReduced1)
|
||
// *Get_ROI (XImageScaled, YImageScaled, ZImageScaled, ImageReduced1, ImageReduced1, Out_ROI, 'Pos', -0.01)
|
||
|
||
//scale_image_max (ImageReduced1, ImageScaleMax1)
|
||
//illuminate (ImageScaleMax1, ImageIlluminate, 117, 117, 0.3)
|
||
//threshold (ImageIlluminate, Regions1, 107, 255)
|
||
//smallest_circle (Regions1, Row2, Column2, Radius2)
|
||
//crop_part (ImageIlluminate, ImagePart, Row2-Radius2, Column2-Radius2, 600, 600)
|
||
//count_obj (ImageIlluminate, Number)
|
||
//if (Number>0)
|
||
//Make := 1
|
||
//out_Image := ImagePart
|
||
//endif
|
||
|
||
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_Make) = -1;
|
||
}
|
||
return;
|
||
}
|
||
|
||
// 3D����
|
||
void _952_15_3D_distance(HObject ho_Image_seg, HObject ho_Image_H, HTuple hv_in_x,
|
||
HTuple hv_in_y, HTuple hv_in_z, HTuple* hv_Point, HTuple* hv_out_minValue, HTuple* hv_out_meanValue,
|
||
HTuple* hv_out_maxValue, HTuple* hv_Make)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_Region, ho_ConnectedRegions, ho_ObjectSelected;
|
||
HObject ho_RegionDilation, ho_RegionDifference, ho_ImageReduced;
|
||
HObject ho_ImageConverted1, ho_YImageSurface, ho_XImageSurface;
|
||
HObject ho_XImageScaled, ho_YImageScaled, ho_ZImageScaled;
|
||
HObject ho_ImageReduced_X, ho_ImageReduced_Y, ho_ImageReduced_Z;
|
||
HObject ho_Out_ROI, ho_RegionOpening, ho_detectRegion, ho_zeroRegion;
|
||
|
||
// Local control variables
|
||
HTuple hv_UsedThreshold, hv_Number, hv_Index;
|
||
HTuple hv_Row1, hv_Column1, hv_Row2, hv_Column2, hv_Type;
|
||
HTuple hv_Width, hv_Height, hv_out_meanValue1, hv_out_maxValue1;
|
||
HTuple hv_out_minValue1, hv_Exception;
|
||
|
||
(*hv_Point) = -99;
|
||
(*hv_out_minValue) = -99;
|
||
(*hv_out_meanValue) = -99;
|
||
(*hv_out_maxValue) = -99;
|
||
(*hv_Make) = -1;
|
||
try
|
||
{
|
||
//����Segͼ
|
||
BinaryThreshold(ho_Image_seg, &ho_Region, "max_separability", "dark", &hv_UsedThreshold);
|
||
Connection(ho_Region, &ho_ConnectedRegions);
|
||
CountObj(ho_ConnectedRegions, &hv_Number);
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Image_H, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ConnectedRegions, HDevWindowStack::GetActive());
|
||
(*hv_Point) = HTuple();
|
||
(*hv_out_minValue) = HTuple();
|
||
(*hv_out_meanValue) = HTuple();
|
||
(*hv_out_maxValue) = HTuple();
|
||
//���ͼ
|
||
{
|
||
HTuple end_val17 = hv_Number - 1;
|
||
HTuple step_val17 = 1;
|
||
for (hv_Index = 0; hv_Index.Continue(end_val17, step_val17); hv_Index += step_val17)
|
||
{
|
||
SelectObj(ho_ConnectedRegions, &ho_ObjectSelected, hv_Index + 1);
|
||
SmallestRectangle1(ho_ObjectSelected, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
|
||
(*hv_Point) = ((((*hv_Point).TupleConcat(hv_Row1)).TupleConcat(hv_Column1)).TupleConcat(hv_Row2)).TupleConcat(hv_Column2);
|
||
DilationCircle(ho_ObjectSelected, &ho_RegionDilation, 10);
|
||
Difference(ho_RegionDilation, ho_ObjectSelected, &ho_RegionDifference);
|
||
ReduceDomain(ho_Image_H, ho_RegionDifference, &ho_ImageReduced);
|
||
//
|
||
GetImageType(ho_Image_H, &hv_Type);
|
||
if (0 != (int(hv_Type != HTuple("real"))))
|
||
{
|
||
ConvertImageType(ho_Image_H, &ho_ImageConverted1, "real");
|
||
}
|
||
else
|
||
{
|
||
ho_ImageConverted1 = ho_Image_H;
|
||
}
|
||
GetImageSize(ho_Image_H, &hv_Width, &hv_Height);
|
||
GenImageSurfaceFirstOrder(&ho_YImageSurface, "real", 1, 0, 0, 0, 0, hv_Width,
|
||
hv_Height);
|
||
GenImageSurfaceFirstOrder(&ho_XImageSurface, "real", 0, 1, 0, 0, 0, hv_Width,
|
||
hv_Height);
|
||
ScaleImage(ho_XImageSurface, &ho_XImageScaled, hv_in_x, 0);
|
||
ScaleImage(ho_YImageSurface, &ho_YImageScaled, hv_in_y, 0);
|
||
ScaleImage(ho_ImageConverted1, &ho_ZImageScaled, hv_in_z, 0);
|
||
ReduceDomain(ho_XImageScaled, ho_ImageReduced, &ho_ImageReduced_X);
|
||
ReduceDomain(ho_YImageScaled, ho_ImageReduced, &ho_ImageReduced_Y);
|
||
ReduceDomain(ho_ZImageScaled, ho_ImageReduced, &ho_ImageReduced_Z);
|
||
Get_ROI1(ho_XImageScaled, ho_YImageScaled, ho_ZImageScaled, ho_RegionDifference,
|
||
ho_RegionDifference, &ho_Out_ROI, "Pos", 0.0);
|
||
OpeningCircle(ho_Out_ROI, &ho_RegionOpening, 1.5);
|
||
get_normal_region(ho_Image_H, ho_ObjectSelected, ho_RegionOpening, &ho_detectRegion,
|
||
&ho_zeroRegion);
|
||
cal_height_gap(ho_Image_H, ho_zeroRegion, ho_detectRegion, "single", hv_in_x,
|
||
hv_in_y, hv_in_z, &hv_out_meanValue1, &hv_out_maxValue1, &hv_out_minValue1);
|
||
(*hv_out_minValue) = (*hv_out_minValue).TupleConcat(hv_out_minValue1);
|
||
(*hv_out_meanValue) = (*hv_out_meanValue).TupleConcat(hv_out_meanValue1);
|
||
(*hv_out_maxValue) = (*hv_out_maxValue).TupleConcat(hv_out_maxValue1);
|
||
}
|
||
}
|
||
(*hv_Make) = 1;
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_Point) = -99;
|
||
(*hv_out_minValue) = -99;
|
||
(*hv_out_meanValue) = -99;
|
||
(*hv_out_maxValue) = -99;
|
||
(*hv_Make) = -1;
|
||
}
|
||
return;
|
||
}
|
||
|
||
//�Ӻ���
|
||
void gen_arrow_contour_xld(HObject* ho_Arrow, HTuple hv_Row1, HTuple hv_Column1,
|
||
HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_TempArrow;
|
||
|
||
// Local control variables
|
||
HTuple hv_Length, hv_ZeroLengthIndices, hv_DR;
|
||
HTuple hv_DC, hv_HalfHeadWidth, hv_RowP1, hv_ColP1, hv_RowP2;
|
||
HTuple hv_ColP2, hv_Index;
|
||
|
||
//This procedure generates arrow shaped XLD contours,
|
||
//pointing from (Row1, Column1) to (Row2, Column2).
|
||
//If starting and end point are identical, a contour consisting
|
||
//of a single point is returned.
|
||
//
|
||
//input parameteres:
|
||
//Row1, Column1: Coordinates of the arrows' starting points
|
||
//Row2, Column2: Coordinates of the arrows' end points
|
||
//HeadLength, HeadWidth: Size of the arrow heads in pixels
|
||
//
|
||
//output parameter:
|
||
//Arrow: The resulting XLD contour
|
||
//
|
||
//The input tuples Row1, Column1, Row2, and Column2 have to be of
|
||
//the same length.
|
||
//HeadLength and HeadWidth either have to be of the same length as
|
||
//Row1, Column1, Row2, and Column2 or have to be a single element.
|
||
//If one of the above restrictions is violated, an error will occur.
|
||
//
|
||
//
|
||
//Init
|
||
GenEmptyObj(&(*ho_Arrow));
|
||
//
|
||
//Calculate the arrow length
|
||
DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, &hv_Length);
|
||
//
|
||
//Mark arrows with identical start and end point
|
||
//(set Length to -1 to avoid division-by-zero exception)
|
||
hv_ZeroLengthIndices = hv_Length.TupleFind(0);
|
||
if (0 != (int(hv_ZeroLengthIndices != -1)))
|
||
{
|
||
hv_Length[hv_ZeroLengthIndices] = -1;
|
||
}
|
||
//
|
||
//Calculate auxiliary variables.
|
||
hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length;
|
||
hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length;
|
||
hv_HalfHeadWidth = hv_HeadWidth / 2.0;
|
||
//
|
||
//Calculate end points of the arrow head.
|
||
hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC);
|
||
hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR);
|
||
hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC);
|
||
hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR);
|
||
//
|
||
//Finally create output XLD contour for each input point pair
|
||
{
|
||
HTuple end_val45 = (hv_Length.TupleLength()) - 1;
|
||
HTuple step_val45 = 1;
|
||
for (hv_Index = 0; hv_Index.Continue(end_val45, step_val45); hv_Index += step_val45)
|
||
{
|
||
if (0 != (int(HTuple(hv_Length[hv_Index]) == -1)))
|
||
{
|
||
//Create_ single points for arrows with identical start and end point
|
||
GenContourPolygonXld(&ho_TempArrow, HTuple(hv_Row1[hv_Index]), HTuple(hv_Column1[hv_Index]));
|
||
}
|
||
else
|
||
{
|
||
//Create arrow contour
|
||
GenContourPolygonXld(&ho_TempArrow, ((((HTuple(hv_Row1[hv_Index]).TupleConcat(HTuple(hv_Row2[hv_Index]))).TupleConcat(HTuple(hv_RowP1[hv_Index]))).TupleConcat(HTuple(hv_Row2[hv_Index]))).TupleConcat(HTuple(hv_RowP2[hv_Index]))).TupleConcat(HTuple(hv_Row2[hv_Index])),
|
||
((((HTuple(hv_Column1[hv_Index]).TupleConcat(HTuple(hv_Column2[hv_Index]))).TupleConcat(HTuple(hv_ColP1[hv_Index]))).TupleConcat(HTuple(hv_Column2[hv_Index]))).TupleConcat(HTuple(hv_ColP2[hv_Index]))).TupleConcat(HTuple(hv_Column2[hv_Index])));
|
||
}
|
||
ConcatObj((*ho_Arrow), ho_TempArrow, &(*ho_Arrow));
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
void get_rectangle1_corners(HTuple hv_in_row1, HTuple hv_in_col1, HTuple hv_in_row2,
|
||
HTuple hv_in_col2, HTuple* hv_out_rows, HTuple* hv_out_cols)
|
||
{
|
||
|
||
// Local iconic variables
|
||
|
||
// Local control variables
|
||
HTuple hv_tl_row, hv_tl_col, hv_tr_row, hv_tr_col;
|
||
HTuple hv_dl_row, hv_dl_col, hv_dr_row, hv_dr_col, hv_Exception;
|
||
|
||
//****����˵��*****
|
||
//****��������---get_rectangle1_corners
|
||
|
||
//&&&&&Input
|
||
//%%%inputIconic
|
||
//None
|
||
//$$$inputCtrl
|
||
//in_row1---tl row����
|
||
//in_col1---tl col����
|
||
//in_row2---dr row����
|
||
//in_col2---dr col����
|
||
|
||
|
||
//&&&&&OutPut
|
||
//%%%outputIconic
|
||
//None
|
||
//$$$outputCtrl
|
||
//out_rows---corner row����, tl, tr, dl, dr
|
||
//out_cols---corner col����, tl, tr, dl, dr
|
||
|
||
|
||
//@@@�쳣������˵��
|
||
//None
|
||
|
||
(*hv_out_rows) = HTuple();
|
||
(*hv_out_cols) = HTuple();
|
||
try
|
||
{
|
||
hv_tl_row = hv_in_row1;
|
||
hv_tl_col = hv_in_col1;
|
||
hv_tr_row = hv_in_row1;
|
||
hv_tr_col = hv_in_col2;
|
||
hv_dl_row = hv_in_row2;
|
||
hv_dl_col = hv_in_col1;
|
||
hv_dr_row = hv_in_row2;
|
||
hv_dr_col = hv_in_col2;
|
||
|
||
(*hv_out_rows) = ((((*hv_out_rows).TupleConcat(hv_tl_row)).TupleConcat(hv_tr_row)).TupleConcat(hv_dl_row)).TupleConcat(hv_dr_row);
|
||
(*hv_out_cols) = ((((*hv_out_cols).TupleConcat(hv_tl_col)).TupleConcat(hv_tr_col)).TupleConcat(hv_dl_col)).TupleConcat(hv_dr_col);
|
||
|
||
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_out_rows) = -99;
|
||
(*hv_out_cols) = -99;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
return;
|
||
}
|
||
|
||
void pts_to_best_line(HObject* ho_Line, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ActiveNum,
|
||
HTuple* hv_Row1, HTuple* hv_Column1, HTuple* hv_Row2, HTuple* hv_Column2)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_Contour;
|
||
|
||
// Local control variables
|
||
HTuple hv_Length, hv_Nr, hv_Nc, hv_Dist, hv_Length1;
|
||
|
||
//��ʼ��
|
||
(*hv_Row1) = 0;
|
||
(*hv_Column1) = 0;
|
||
(*hv_Row2) = 0;
|
||
(*hv_Column2) = 0;
|
||
//����һ���յ�ֱ�߶������ڱ�����Ϻ��ֱ��
|
||
GenEmptyObj(&(*ho_Line));
|
||
//�����Ե����
|
||
TupleLength(hv_Cols, &hv_Length);
|
||
//����Ե������С����Ч����ʱ�������
|
||
if (0 != (HTuple(int(hv_Length >= hv_ActiveNum)).TupleAnd(int(hv_ActiveNum > 1))))
|
||
{
|
||
//halcon������ǻ���xld�ģ���Ҫ�ѱ�Ե���ӳ�xld
|
||
GenContourPolygonXld(&ho_Contour, hv_Rows, hv_Cols);
|
||
//���ֱ�ߡ�ʹ�õ��㷨��'tukey'�������㷨��ο�fit_line_contour_xld���������֡�
|
||
FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, &(*hv_Row1), &(*hv_Column1),
|
||
&(*hv_Row2), &(*hv_Column2), &hv_Nr, &hv_Nc, &hv_Dist);
|
||
//�ж���Ͻ���Ƿ���Ч�������ϳɹ���������Ԫ�ص���������0
|
||
TupleLength(hv_Dist, &hv_Length1);
|
||
if (0 != (int(hv_Length1 < 1)))
|
||
{
|
||
return;
|
||
}
|
||
//������Ͻ��������ֱ��xld
|
||
GenContourPolygonXld(&(*ho_Line), (*hv_Row1).TupleConcat((*hv_Row2)), (*hv_Column1).TupleConcat((*hv_Column2)));
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
void rake(HObject ho_Image, HObject* ho_Regions, HTuple hv_Elements, HTuple hv_DetectHeight,
|
||
HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, HTuple hv_Transition,
|
||
HTuple hv_Select, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2,
|
||
HTuple* hv_ResultRow, HTuple* hv_ResultColumn)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_RegionLines, ho_Rectangle, ho_Arrow1;
|
||
|
||
// Local control variables
|
||
HTuple hv_Width, hv_Height, hv_ATan, hv_i, hv_RowC;
|
||
HTuple hv_ColC, hv_Distance, hv_RowL2, hv_RowL1, hv_ColL2;
|
||
HTuple hv_ColL1, hv_MsrHandle_Measure, hv_RowEdge, hv_ColEdge;
|
||
HTuple hv_Amplitude, hv_tRow, hv_tCol, hv_t, hv_Number;
|
||
HTuple hv_j;
|
||
|
||
//��ȡͼ��ߴ�
|
||
GetImageSize(ho_Image, &hv_Width, &hv_Height);
|
||
//����һ������ʾ����������ʾ
|
||
GenEmptyObj(&(*ho_Regions));
|
||
//��ʼ����Ե��������
|
||
(*hv_ResultRow) = HTuple();
|
||
(*hv_ResultColumn) = HTuple();
|
||
//����ֱ��xld
|
||
GenContourPolygonXld(&ho_RegionLines, hv_Row1.TupleConcat(hv_Row2), hv_Column1.TupleConcat(hv_Column2));
|
||
//�洢����ʾ����
|
||
ConcatObj((*ho_Regions), ho_RegionLines, &(*ho_Regions));
|
||
//����ֱ����x��ļнǣ���ʱ�뷽��Ϊ����
|
||
AngleLx(hv_Row1, hv_Column1, hv_Row2, hv_Column2, &hv_ATan);
|
||
|
||
//��Ե��ⷽ��ֱ�ڼ��ֱ�ߣ�ֱ�߷���������ת90��Ϊ��Ե��ⷽ��
|
||
hv_ATan += HTuple(90).TupleRad();
|
||
|
||
//���ݼ��ֱ�߰�˳���������������Σ����洢����ʾ����
|
||
{
|
||
HTuple end_val18 = hv_Elements;
|
||
HTuple step_val18 = 1;
|
||
for (hv_i = 1; hv_i.Continue(end_val18, step_val18); hv_i += step_val18)
|
||
{
|
||
//RowC := Row1+(((Row2-Row1)*i)/(Elements+1))
|
||
//ColC := Column1+(Column2-Column1)*i/(Elements+1)
|
||
//if (RowC>Height-1 or RowC<0 or ColC>Width-1 or ColC<0)
|
||
//continue
|
||
//endif
|
||
//���ֻ��һ���������Σ���Ϊ���߹��ߣ�����Ϊ���ֱ�ߵij���
|
||
if (0 != (int(hv_Elements == 1)))
|
||
{
|
||
hv_RowC = (hv_Row1 + hv_Row2) * 0.5;
|
||
hv_ColC = (hv_Column1 + hv_Column2) * 0.5;
|
||
//�ж��Ƿ�ͼ��,����������Ե
|
||
if (0 != (HTuple(HTuple(HTuple(int(hv_RowC > (hv_Height - 1))).TupleOr(int(hv_RowC < 0))).TupleOr(int(hv_ColC > (hv_Width - 1)))).TupleOr(int(hv_ColC < 0))))
|
||
{
|
||
continue;
|
||
}
|
||
DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, &hv_Distance);
|
||
hv_DetectWidth = hv_Distance;
|
||
GenRectangle2ContourXld(&ho_Rectangle, hv_RowC, hv_ColC, hv_ATan, hv_DetectHeight / 2,
|
||
hv_Distance / 2);
|
||
}
|
||
else
|
||
{
|
||
//����ж���������Σ������ò�������xld
|
||
hv_RowC = hv_Row1 + (((hv_Row2 - hv_Row1) * (hv_i - 1)) / (hv_Elements - 1));
|
||
hv_ColC = hv_Column1 + (((hv_Column2 - hv_Column1) * (hv_i - 1)) / (hv_Elements - 1));
|
||
//�ж��Ƿ�ͼ��,����������Ե
|
||
if (0 != (HTuple(HTuple(HTuple(int(hv_RowC > (hv_Height - 1))).TupleOr(int(hv_RowC < 0))).TupleOr(int(hv_ColC > (hv_Width - 1)))).TupleOr(int(hv_ColC < 0))))
|
||
{
|
||
continue;
|
||
}
|
||
GenRectangle2ContourXld(&ho_Rectangle, hv_RowC, hv_ColC, hv_ATan, hv_DetectHeight / 2,
|
||
hv_DetectWidth / 2);
|
||
}
|
||
|
||
//�Ѳ�������xld�洢����ʾ����
|
||
ConcatObj((*ho_Regions), ho_Rectangle, &(*ho_Regions));
|
||
if (0 != (int(hv_i == 1)))
|
||
{
|
||
//�ڵ�һ���������λ���һ����ͷxld������ֻ�DZ�Ե��ⷽ��
|
||
hv_RowL2 = hv_RowC + ((hv_DetectHeight / 2) * ((-hv_ATan).TupleSin()));
|
||
hv_RowL1 = hv_RowC - ((hv_DetectHeight / 2) * ((-hv_ATan).TupleSin()));
|
||
hv_ColL2 = hv_ColC + ((hv_DetectHeight / 2) * ((-hv_ATan).TupleCos()));
|
||
hv_ColL1 = hv_ColC - ((hv_DetectHeight / 2) * ((-hv_ATan).TupleCos()));
|
||
gen_arrow_contour_xld(&ho_Arrow1, hv_RowL1, hv_ColL1, hv_RowL2, hv_ColL2, 25,
|
||
25);
|
||
//��xld�洢����ʾ����
|
||
ConcatObj((*ho_Regions), ho_Arrow1, &(*ho_Regions));
|
||
}
|
||
//��������������
|
||
GenMeasureRectangle2(hv_RowC, hv_ColC, hv_ATan, hv_DetectHeight / 2, hv_DetectWidth / 2,
|
||
hv_Width, hv_Height, "nearest_neighbor", &hv_MsrHandle_Measure);
|
||
|
||
|
||
//���ü���
|
||
if (0 != (int(hv_Transition == HTuple("negative"))))
|
||
{
|
||
hv_Transition = "negative";
|
||
}
|
||
else
|
||
{
|
||
if (0 != (int(hv_Transition == HTuple("positive"))))
|
||
{
|
||
|
||
hv_Transition = "positive";
|
||
}
|
||
else
|
||
{
|
||
hv_Transition = "all";
|
||
}
|
||
}
|
||
//���ñ�Եλ�á���ǿ���Ǵ����б�Ե��ѡ����Ⱦ���ֵ���㣬��Ҫ����Ϊ'all'
|
||
if (0 != (int(hv_Select == HTuple("first"))))
|
||
{
|
||
hv_Select = "first";
|
||
}
|
||
else
|
||
{
|
||
if (0 != (int(hv_Select == HTuple("last"))))
|
||
{
|
||
|
||
hv_Select = "last";
|
||
}
|
||
else
|
||
{
|
||
hv_Select = "all";
|
||
}
|
||
}
|
||
//����Ե
|
||
MeasurePos(ho_Image, hv_MsrHandle_Measure, hv_Sigma, hv_Threshold, hv_Transition,
|
||
hv_Select, &hv_RowEdge, &hv_ColEdge, &hv_Amplitude, &hv_Distance);
|
||
//�������������
|
||
CloseMeasure(hv_MsrHandle_Measure);
|
||
|
||
//��ʱ������ʼ��
|
||
//tRow��tCol�����ҵ�ָ����Ե������
|
||
hv_tRow = 0;
|
||
hv_tCol = 0;
|
||
//t�����Ե�ķ��Ⱦ���ֵ
|
||
hv_t = 0;
|
||
//�ҵ��ı�Ե��������Ϊ1��
|
||
TupleLength(hv_RowEdge, &hv_Number);
|
||
if (0 != (int(hv_Number < 1)))
|
||
{
|
||
continue;
|
||
}
|
||
//�ж����Եʱ��ѡ����Ⱦ���ֵ���ı�Ե
|
||
{
|
||
HTuple end_val101 = hv_Number - 1;
|
||
HTuple step_val101 = 1;
|
||
for (hv_j = 0; hv_j.Continue(end_val101, step_val101); hv_j += step_val101)
|
||
{
|
||
if (0 != (int((HTuple(hv_Amplitude[hv_j]).TupleAbs()) > hv_t)))
|
||
{
|
||
|
||
hv_tRow = HTuple(hv_RowEdge[hv_j]);
|
||
hv_tCol = HTuple(hv_ColEdge[hv_j]);
|
||
hv_t = HTuple(hv_Amplitude[hv_j]).TupleAbs();
|
||
}
|
||
}
|
||
}
|
||
//���ҵ��ı�Ե�������������
|
||
if (0 != (int(hv_t > 0)))
|
||
{
|
||
(*hv_ResultRow) = (*hv_ResultRow).TupleConcat(hv_tRow);
|
||
(*hv_ResultColumn) = (*hv_ResultColumn).TupleConcat(hv_tCol);
|
||
}
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//3D�Ӻ���
|
||
void cal_height_gap(HObject ho_in_imageH, HObject ho_in_zeroRegion, HObject ho_in_calRegion,
|
||
HTuple hv_in_zeroMode, HTuple hv_in_xResolution, HTuple hv_in_yResolution, HTuple hv_in_zResolution,
|
||
HTuple* hv_out_meanValue, HTuple* hv_out_maxValue, HTuple* hv_out_minValue)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_ImageMedian, ho_ImageReduced, ho_ImageConverted;
|
||
HObject ho_XImageSurface, ho_YImageSurface, ho_XImageScaled;
|
||
HObject ho_YImageScaled, ho_ZImageScaled, ho_zeroObjectSelected;
|
||
HObject ho_calObjectSelected, ho_detectRegion, ho_zeroRegion;
|
||
HObject ho_zeroRegionUnion;
|
||
|
||
// Local control variables
|
||
HTuple hv_Width, hv_Height, hv_Number, hv_i;
|
||
HTuple hv_meanValue, hv_maxValue, hv_minValue, hv_j, hv_Exception;
|
||
|
||
//****����˵��*****
|
||
//****cal_height_gap
|
||
|
||
//&&&&&Input
|
||
//%%%inputIconic
|
||
//in_imageH---16λ�߶�ͼ
|
||
//in_zeroRegion---����ƽ������
|
||
//in_calRegion---����ƽ������
|
||
|
||
//$$$inputCtrl
|
||
//in_zeroMode---'single':zero��detectһһ��Ӧ, 'united': zero��
|
||
//in_xResolution
|
||
//in_yResolution
|
||
//in_zResolution
|
||
|
||
//&&&&&OutPut
|
||
//$Ctrl
|
||
//out_meanValue---���м�������ֵ��+Ϊ��-Ϊ���ӣ����飩
|
||
//out_maxValue---���м������߶Ȳ����ֵ�����飩
|
||
//out_minValue---���м������߶Ȳ���Сֵ�����飩
|
||
|
||
//&&&&&Exception
|
||
//-99---λ�ô���
|
||
//-77---ģʽ�������
|
||
|
||
try
|
||
{
|
||
(*hv_out_meanValue) = HTuple();
|
||
(*hv_out_maxValue) = HTuple();
|
||
(*hv_out_minValue) = HTuple();
|
||
CopyImage(ho_in_imageH, &ho_ImageMedian);
|
||
GetImageSize(ho_ImageMedian, &hv_Width, &hv_Height);
|
||
|
||
//*****����tiff���߶�ͼ��ͼ��ȡx,y,z���꣬��λ��mm
|
||
ReduceDomain(ho_ImageMedian, ho_in_calRegion, &ho_ImageReduced);
|
||
ConvertImageType(ho_ImageMedian, &ho_ImageConverted, "real");
|
||
GetImageSize(ho_in_imageH, &hv_Width, &hv_Height);
|
||
|
||
//ʹ��һ����ʽ������б�Ļ�ɫ����
|
||
GenImageSurfaceFirstOrder(&ho_XImageSurface, "real", 1, 0, 0, 0, 0, hv_Width,
|
||
hv_Height);
|
||
GenImageSurfaceFirstOrder(&ho_YImageSurface, "real", 0, 1, 0, 0, 0, hv_Width,
|
||
hv_Height);
|
||
|
||
//��ȡzeroRegion�е�x,y,z���겢ת����mm
|
||
//������xyz���ؾ�������ͼ��ĻҶ�ֵ��
|
||
ScaleImage(ho_XImageSurface, &ho_XImageScaled, hv_in_xResolution, 0);
|
||
ScaleImage(ho_YImageSurface, &ho_YImageScaled, hv_in_yResolution, 0);
|
||
ScaleImage(ho_ImageConverted, &ho_ZImageScaled, hv_in_zResolution, 0);
|
||
|
||
if (0 != (int(hv_in_zeroMode == HTuple("single"))))
|
||
{
|
||
CountObj(ho_in_zeroRegion, &hv_Number);
|
||
{
|
||
HTuple end_val49 = hv_Number;
|
||
HTuple step_val49 = 1;
|
||
for (hv_i = 1; hv_i.Continue(end_val49, step_val49); hv_i += step_val49)
|
||
{
|
||
SelectObj(ho_in_zeroRegion, &ho_zeroObjectSelected, hv_i);
|
||
SelectObj(ho_in_calRegion, &ho_calObjectSelected, hv_i);
|
||
|
||
//����
|
||
//������ü��ƶ���ĸ߶�ͼ�����ԭ���ĸ߶�ͼ����
|
||
get_normal_region(ho_ImageMedian, ho_calObjectSelected, ho_zeroObjectSelected,
|
||
&ho_detectRegion, &ho_zeroRegion);
|
||
|
||
//3D����߶Ȳ�
|
||
cal_region_gap(ho_XImageScaled, ho_YImageScaled, ho_ZImageScaled, ho_in_calRegion,
|
||
ho_in_zeroRegion, &hv_meanValue, &hv_maxValue, &hv_minValue);
|
||
|
||
(*hv_out_meanValue) = (*hv_out_meanValue).TupleConcat(hv_meanValue);
|
||
(*hv_out_maxValue) = (*hv_out_maxValue).TupleConcat(hv_maxValue);
|
||
(*hv_out_minValue) = (*hv_out_minValue).TupleConcat(hv_minValue);
|
||
}
|
||
}
|
||
}
|
||
else if (0 != (int(hv_in_zeroMode == HTuple("united"))))
|
||
{
|
||
Union1(ho_in_zeroRegion, &ho_zeroRegionUnion);
|
||
CountObj(ho_in_calRegion, &hv_Number);
|
||
{
|
||
HTuple end_val67 = hv_Number;
|
||
HTuple step_val67 = 1;
|
||
for (hv_j = 1; hv_j.Continue(end_val67, step_val67); hv_j += step_val67)
|
||
{
|
||
SelectObj(ho_in_calRegion, &ho_calObjectSelected, hv_j);
|
||
get_normal_region(ho_ImageMedian, ho_calObjectSelected, ho_zeroRegionUnion,
|
||
&ho_detectRegion, &ho_zeroRegion);
|
||
cal_region_gap(ho_XImageScaled, ho_YImageScaled, ho_ZImageScaled, ho_zeroRegion,
|
||
ho_detectRegion, &hv_meanValue, &hv_maxValue, &hv_minValue);
|
||
|
||
(*hv_out_meanValue) = (*hv_out_meanValue).TupleConcat(hv_meanValue);
|
||
(*hv_out_maxValue) = (*hv_out_maxValue).TupleConcat(hv_maxValue);
|
||
(*hv_out_minValue) = (*hv_out_minValue).TupleConcat(hv_minValue);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//ģʽ�������
|
||
(*hv_out_meanValue) = -77;
|
||
(*hv_out_maxValue) = -77;
|
||
(*hv_out_minValue) = -77;
|
||
}
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
(*hv_out_meanValue) = -99;
|
||
(*hv_out_maxValue) = -99;
|
||
(*hv_out_minValue) = -99;
|
||
}
|
||
return;
|
||
}
|
||
|
||
void cal_region_gap(HObject ho_imageX, HObject ho_imageY, HObject ho_imageZ, HObject ho_zeroRegion,
|
||
HObject ho_calRegion, HTuple* hv_meanValue, HTuple* hv_maxValue, HTuple* hv_minValue)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_XImageScaled, ho_YImageScaled, ho_ZImageScaled;
|
||
HObject ho_ObjectSelected;
|
||
|
||
// Local control variables
|
||
HTuple hv_deleteHeightPercent, hv_ObjectModel3D;
|
||
HTuple hv_ObjectModel3DOut, hv_planeParams, hv_A, hv_B;
|
||
HTuple hv_C, hv_D, hv_calNum, hv_Index, hv_Rows, hv_Columns;
|
||
HTuple hv_X, hv_Y, hv_Z, hv_dist, hv_Mean, hv_Max, hv_Min;
|
||
HTuple hv_Length, hv_start, hv_end, hv_Sorted, hv_distSelected;
|
||
HTuple hv_Exception;
|
||
|
||
//****����˵��*****
|
||
//****cal_height_gap
|
||
|
||
//&&&&&Input
|
||
//%%%inputIconic
|
||
//imageX---x����ͼ����λmm
|
||
//imageY---y����ͼ����λmm
|
||
//imageZ---z����ͼ����λmm
|
||
//zeroRegion---��ƽ������
|
||
//calRegion---�������
|
||
|
||
//&&&&&OutPut
|
||
//$Ctrl
|
||
//mean---���м�������ֵ��+�߳����棬-���ڻ��棨���飩
|
||
//max---�������߶Ȳ����ֵ�����飩
|
||
//min---�������߶Ȳ���Сֵ�����飩
|
||
|
||
//@@@�쳣������˵��
|
||
//-9999: �������쳣
|
||
|
||
//# #####����#######
|
||
//read_image (imageX, 'D:/00-lmi/�߶�ͼ-����.tif')
|
||
//get_image_type (imageX, Type)
|
||
//xResolution := 0.095
|
||
//yResolution := 0.1
|
||
//zResolution := 0.0009
|
||
//heightThreshold := 0.15
|
||
//defectAreaThreshold := 35
|
||
//gen_rectangle1 (zeroRegion, 1295.04, 584.588, 2652.38, 1285.88)
|
||
//gen_rectangle1 (detectRegion, 141.372, 1000.53, 195.522, 1136.69)
|
||
|
||
//gen_rectangle1 (detectRegion, 2271.32, 101.122, 2408.83, 177.378)
|
||
//meanValue := 0
|
||
//maxValue := 0
|
||
//minValue := 0
|
||
//# #####����#######
|
||
try
|
||
{
|
||
(*hv_meanValue) = HTuple();
|
||
(*hv_maxValue) = HTuple();
|
||
(*hv_minValue) = HTuple();
|
||
|
||
//#####ȥ����β�����---20221025
|
||
hv_deleteHeightPercent = 0.030;
|
||
|
||
//get_image_type (imageX, Type)
|
||
//* if(Type=='int2' or Type=='uint2')
|
||
if (0 != 1)
|
||
{
|
||
ReduceDomain(ho_imageX, ho_zeroRegion, &ho_XImageScaled);
|
||
ReduceDomain(ho_imageY, ho_zeroRegion, &ho_YImageScaled);
|
||
ReduceDomain(ho_imageZ, ho_zeroRegion, &ho_ZImageScaled);
|
||
|
||
//����x,y,z����3Dģ�Ͳ����ƽ��
|
||
XyzToObjectModel3d(ho_XImageScaled, ho_YImageScaled, ho_ZImageScaled, &hv_ObjectModel3D);
|
||
//��3D��Ԫ���Ϊһ��3D��
|
||
//'primitive_type'��ָ��������� ��Ӧֵ'plane'Ϊ���ƽ��
|
||
//'fitting_algorithm'��ָ��3DͼԪ��ʹ�õ��㷨 ��Ӧֵ��'least_squares_tukey' Tukey�㷨����ȥ���쳣ֵ
|
||
FitPrimitivesObjectModel3d(hv_ObjectModel3D, (HTuple("primitive_type").Append("fitting_algorithm")),
|
||
(HTuple("plane").Append("least_squares_tukey")), &hv_ObjectModel3DOut);
|
||
|
||
//��ȡƽ����Ϣ
|
||
//����3Dģ�͵�����
|
||
//����λ���ߣ�x-��y-��z-������[x��y��z]�Լ���������ϵԭ���ƽ����������루d����
|
||
//˳����[x��y��z��d]�����루d���ķ���ȷ��ԭ������ƽ��IJ��档
|
||
//[x��y��z��d������ƽ��ռ������ij���
|
||
GetObjectModel3dParams(hv_ObjectModel3DOut, "primitive_parameter", &hv_planeParams);
|
||
|
||
//��ʾ����
|
||
//Խ��Խ��Խ��Խ��
|
||
//dev_get_window (WindowHandle)
|
||
//visualize_object_model_3d (WindowHandle, ObjectModel3D, [], [], ['lut','intensity'], ['hsi','coord_z'], ['Edited by AmazingRobot+'], [], [], PoseOut)
|
||
if (0 != (int((hv_planeParams.TupleLength()) == 4)))
|
||
{
|
||
//Ax+By+Cz+D=0��ȡƽ����Ϣ
|
||
hv_A = ((const HTuple&)hv_planeParams)[0];
|
||
hv_B = ((const HTuple&)hv_planeParams)[1];
|
||
hv_C = ((const HTuple&)hv_planeParams)[2];
|
||
hv_D = ((const HTuple&)hv_planeParams)[3];
|
||
//��ȡdetectRegion
|
||
CountObj(ho_calRegion, &hv_calNum);
|
||
{
|
||
HTuple end_val77 = hv_calNum;
|
||
HTuple step_val77 = 1;
|
||
for (hv_Index = 1; hv_Index.Continue(end_val77, step_val77); hv_Index += step_val77)
|
||
{
|
||
SelectObj(ho_calRegion, &ho_ObjectSelected, hv_Index);
|
||
|
||
ReduceDomain(ho_imageX, ho_ObjectSelected, &ho_XImageScaled);
|
||
ReduceDomain(ho_imageY, ho_ObjectSelected, &ho_YImageScaled);
|
||
ReduceDomain(ho_imageZ, ho_ObjectSelected, &ho_ZImageScaled);
|
||
|
||
//������������
|
||
GetRegionPoints(ho_ObjectSelected, &hv_Rows, &hv_Columns);
|
||
//�������ĻҶ�ֵ
|
||
GetGrayval(ho_XImageScaled, hv_Rows, hv_Columns, &hv_X);
|
||
GetGrayval(ho_YImageScaled, hv_Rows, hv_Columns, &hv_Y);
|
||
GetGrayval(ho_ZImageScaled, hv_Rows, hv_Columns, &hv_Z);
|
||
|
||
//����߶Ȳ�
|
||
//����㵽ƽ��ľ��빫ʽ
|
||
hv_dist = (((hv_A * hv_X) + (hv_B * hv_Y)) + (hv_C * hv_Z)) - hv_D;
|
||
if (0 != (int(hv_C < 0)))
|
||
{
|
||
hv_dist = hv_dist * -1;
|
||
}
|
||
//tuple_mean (dist, Mean)
|
||
//tuple_max (dist, Max)
|
||
//tuple_min (dist, Min)
|
||
|
||
//#####ȥ���쳣�㣬��β��3%---20221025wdz
|
||
TupleLength(hv_dist, &hv_Length);
|
||
hv_start = (hv_Length * hv_deleteHeightPercent).TupleInt();
|
||
hv_end = (hv_Length * (1 - hv_deleteHeightPercent)).TupleInt();
|
||
TupleSort(hv_dist, &hv_Sorted);
|
||
//ȥ��ǰ��ٷ�֮3����ֵ
|
||
TupleSelect(hv_Sorted, HTuple::TupleGenSequence(hv_start, hv_end, 1), &hv_distSelected);
|
||
|
||
TupleMean(hv_distSelected, &hv_Mean);
|
||
TupleMax(hv_distSelected, &hv_Max);
|
||
TupleMin(hv_distSelected, &hv_Min);
|
||
|
||
(*hv_meanValue) = (*hv_meanValue).TupleConcat((hv_Mean.TupleString(".4f")).TupleNumber());
|
||
(*hv_maxValue) = (*hv_maxValue).TupleConcat((hv_Max.TupleString(".4f")).TupleNumber());
|
||
(*hv_minValue) = (*hv_minValue).TupleConcat((hv_Min.TupleString(".4f")).TupleNumber());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
//���߶��쳣
|
||
(*hv_meanValue) = -9999;
|
||
(*hv_maxValue) = -9999;
|
||
(*hv_minValue) = -9999;
|
||
}
|
||
return;
|
||
}
|
||
|
||
void get_normal_region(HObject ho_imageH, HObject ho_tmpDetectRegion, HObject ho_tmpZeroRegion,
|
||
HObject* ho_detectRegion, HObject* ho_zeroRegion)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_ImageReduced, ho_Region, ho_ImageReduced1;
|
||
HObject ho_Region1;
|
||
|
||
// Local control variables
|
||
HTuple hv_Area, hv_Row, hv_Column, hv_Area1;
|
||
HTuple hv_Row1, hv_Column1, hv_Exception;
|
||
|
||
//****����˵��*****
|
||
//****��ȡ������������������
|
||
|
||
//&&&&&Input
|
||
//%%%inputIconic
|
||
//imageH---16λ�߶�ͼ
|
||
//tmpDetectRegion---�������
|
||
//tmpZeroRegion---����������
|
||
|
||
//&&&&&OutPut
|
||
//%%%outputIconic
|
||
//detectRegion---�������
|
||
//zeroRegion---����������
|
||
|
||
//# ####For Debugging-S#####
|
||
//read_image (imageH, 'printer_chip/printer_chip_01')
|
||
//threshold (imageH, tmpDetectRegion, 128, 255)
|
||
//threshold (imageH, tmpZeroRegion, 128, 255)
|
||
//# ####For Debugging-E#####
|
||
|
||
try
|
||
{
|
||
//�ü��߶�ͼ��϶����ֱ�ߵľ���
|
||
ReduceDomain(ho_imageH, ho_tmpDetectRegion, &ho_ImageReduced);
|
||
Threshold(ho_ImageReduced, &ho_Region, -32768, -32768);
|
||
AreaCenter(ho_Region, &hv_Area, &hv_Row, &hv_Column);
|
||
if (0 != (int(hv_Area > 0)))
|
||
{
|
||
Difference(ho_tmpDetectRegion, ho_Region, &(*ho_detectRegion));
|
||
}
|
||
else
|
||
{
|
||
(*ho_detectRegion) = ho_tmpDetectRegion;
|
||
}
|
||
|
||
ReduceDomain(ho_imageH, ho_tmpZeroRegion, &ho_ImageReduced1);
|
||
Threshold(ho_ImageReduced1, &ho_Region1, -32768, -32768);
|
||
AreaCenter(ho_Region1, &hv_Area1, &hv_Row1, &hv_Column1);
|
||
if (0 != (int(hv_Area1 > 0)))
|
||
{
|
||
Difference(ho_tmpZeroRegion, ho_Region1, &(*ho_zeroRegion));
|
||
}
|
||
else
|
||
{
|
||
(*ho_zeroRegion) = ho_tmpZeroRegion;
|
||
}
|
||
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
|
||
//�ü��߶�ͼֱ�ߵ�λ�ã��˾���Ϊ�ƶ���
|
||
ReduceDomain(ho_imageH, ho_tmpDetectRegion, &ho_ImageReduced);
|
||
//��ֵ�ָ�ѡ���ɫ����
|
||
Threshold(ho_ImageReduced, &ho_Region, 0, 0);
|
||
AreaCenter(ho_Region, &hv_Area, &hv_Row, &hv_Column);
|
||
if (0 != (int(hv_Area > 0)))
|
||
{
|
||
//��
|
||
Difference(ho_tmpDetectRegion, ho_Region, &(*ho_detectRegion));
|
||
}
|
||
else
|
||
{
|
||
(*ho_detectRegion) = ho_tmpDetectRegion;
|
||
}
|
||
|
||
//����ƶ��������ִ������ͬ���IJ���
|
||
ReduceDomain(ho_imageH, ho_tmpZeroRegion, &ho_ImageReduced1);
|
||
Threshold(ho_ImageReduced1, &ho_Region1, 0, 0);
|
||
AreaCenter(ho_Region1, &hv_Area1, &hv_Row1, &hv_Column1);
|
||
if (0 != (int(hv_Area1 > 0)))
|
||
{
|
||
Difference(ho_tmpZeroRegion, ho_Region1, &(*ho_zeroRegion));
|
||
}
|
||
else
|
||
{
|
||
(*ho_zeroRegion) = ho_tmpZeroRegion;
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
void Cal_PP_Distance(HObject ho_in_MeasureRegion, HObject ho_in_Image1, HObject ho_in_Image2,
|
||
HTuple hv_in_Model, HTuple hv_in_Product_DPix, HTuple hv_in_Filepath, HTuple hv_in_Resolution,
|
||
HTuple hv_in_CameraType, HTuple* hv_out_Line1, HTuple* hv_out_Line2, HTuple* hv_out_Distance,
|
||
HTuple* hv_out_Flag)
|
||
{
|
||
|
||
// Local iconic variables
|
||
HObject ho_ObjectSelected, ho_ImageReduced, ho_Edges;
|
||
HObject ho_UnionContours1, ho_SelectedContours, ho_RegionLines1;
|
||
HObject ho_ImageMirror, ho_ImageResult2, ho_Region2, ho_RegionBorder;
|
||
HObject ho_ImageReduced2, ho_Edges1, ho_UnionContours, ho_RegionLines2;
|
||
|
||
// Local control variables
|
||
HTuple hv_Debug, hv_Width, hv_Height, hv_Number;
|
||
HTuple hv_index, hv_Length3, hv_RowBegin, hv_ColBegin;
|
||
HTuple hv_RowEnd, hv_ColEnd, hv_Nr, hv_Nc, hv_Dist, hv_Row1;
|
||
HTuple hv_Col1, hv_new_Row1, hv_new_Col1, hv_startRow;
|
||
HTuple hv_startCol, hv_endRow, hv_endCol, hv_Distance1;
|
||
HTuple hv_Length1, hv_RowBegin1, hv_ColBegin1, hv_RowEnd1;
|
||
HTuple hv_ColEnd1, hv_Nr1, hv_Nc1, hv_Dist1, hv_Row2, hv_Col2;
|
||
HTuple hv_new_Row2, hv_new_Col2, hv_Distance2, hv_Length2;
|
||
HTuple hv_Lenth, hv_Sum, hv_Newtuple, hv_Diff, hv_Tuple1;
|
||
HTuple hv_Tuple2, hv_Tuple3, hv_Sel_Distance1, hv_Sel_Distance2;
|
||
HTuple hv_Sum1, hv_Diam, hv_Sorted, hv_Length, hv_start;
|
||
HTuple hv_end, hv_distSelected, hv_Mean, hv_Max, hv_Sel_Distance3;
|
||
HTuple hv_Sel_Distance4, hv_Sum2, hv_Sel_Distance5, hv_Sel_Distance6;
|
||
HTuple hv_Sum3, hv_Exception;
|
||
HTupleVector hvec_vector(1);
|
||
|
||
|
||
//**********************************************************************
|
||
//Function Name: _952_15_Distance_UP
|
||
//Author:
|
||
//Description: ������ص�ֱ��(mm),
|
||
//Input:
|
||
// in_MeasureRegion,
|
||
// in_Image1, ������(bmp),
|
||
// in_Image2, �Ҳ����(bmp),
|
||
// in_Model, ģʽ, 1:�������ݽ��б궨, 0:�������ݽ������߲���,
|
||
// in_Product_DPix, �����ֱ��(pix)
|
||
// in_Filepath, �궨�ļ���·��,
|
||
// in_Resolution, �������(mm/pix)
|
||
// in_CameraType, ����(������), 1: �� 2: �� 3�� ��
|
||
//output�� out_Line1, ���������Ƶ���(),
|
||
// out_Line2, �Ҳ�������Ƶ���(),
|
||
// out_Distance, ������Բ��ֱ��(D1,D2,D3)
|
||
// out_Flag, �㷨ִ�еı�־λ; 0, �㷨ִ��NG 1,�㷨ִ��OK
|
||
|
||
//verion change log: ������ 2024-06-19 V1.1 Create new function
|
||
// ������ 2024-06-26 V1.2 �����ͼ���з�ת,
|
||
// ������ 2024-08-10 V1.3 ���������.
|
||
|
||
//**********************************************************************
|
||
(*hv_out_Distance).Clear();
|
||
(*hv_out_Distance)[0] = 0;
|
||
(*hv_out_Distance)[1] = 0;
|
||
(*hv_out_Distance)[2] = 0;
|
||
(*hv_out_Flag) = 0;
|
||
hv_Debug = 1;
|
||
try
|
||
{
|
||
//dev_display (in_Image1)
|
||
//dev_display (in_MeasureRegion)
|
||
GetImageSize(ho_in_Image1, &hv_Width, &hv_Height);
|
||
CountObj(ho_in_MeasureRegion, &hv_Number);
|
||
{
|
||
HTuple end_val32 = hv_Number;
|
||
HTuple step_val32 = 1;
|
||
for (hv_index = 1; hv_index.Continue(end_val32, step_val32); hv_index += step_val32)
|
||
{
|
||
SelectObj(ho_in_MeasureRegion, &ho_ObjectSelected, hv_index);
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ObjectSelected, HDevWindowStack::GetActive());
|
||
ReduceDomain(ho_in_Image1, ho_ObjectSelected, &ho_ImageReduced);
|
||
EdgesSubPix(ho_ImageReduced, &ho_Edges, "canny", 4, 12, 24);
|
||
//�۲�, ��Ʒ��ȡ�������Ƿ�����쳣,
|
||
if (0 != hv_Debug)
|
||
{
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Edges, HDevWindowStack::GetActive());
|
||
//stop ()
|
||
}
|
||
UnionAdjacentContoursXld(ho_Edges, &ho_UnionContours1, 10, 1, "attr_keep");
|
||
LengthXld(ho_UnionContours1, &hv_Length3);
|
||
SelectContoursXld(ho_UnionContours1, &ho_SelectedContours, "contour_length",
|
||
(hv_Length3.TupleMax()) - 1, (hv_Length3.TupleMax()) + 1, -0.5, 0.5);
|
||
FitLineContourXld(ho_SelectedContours, "tukey", -1, 0, 5, 2, &hv_RowBegin,
|
||
&hv_ColBegin, &hv_RowEnd, &hv_ColEnd, &hv_Nr, &hv_Nc, &hv_Dist);
|
||
GetContourXld(ho_SelectedContours, &hv_Row1, &hv_Col1);
|
||
if (0 != (HTuple(hv_Col1[0]) > HTuple(hv_Col1[(hv_Col1.TupleLength()) - 1])))
|
||
{
|
||
TupleInverse(hv_Row1, &hv_new_Row1);
|
||
TupleInverse(hv_Col1, &hv_new_Col1);
|
||
}
|
||
else
|
||
{
|
||
hv_new_Row1 = hv_Row1;
|
||
hv_new_Col1 = hv_Col1;
|
||
}
|
||
//�ô���Ҫ��ͼ������������кŽ��ж�Ӧ.
|
||
if (0 != (hv_in_CameraType == 1))
|
||
{
|
||
hv_startRow = hv_Height - 1;
|
||
hv_startCol = 0;
|
||
hv_endRow = hv_Height - 1;
|
||
hv_endCol = hv_Width - 1;
|
||
}
|
||
else if (0 != (hv_in_CameraType == 2))
|
||
{
|
||
hv_startRow = 0;
|
||
hv_startCol = 0;
|
||
hv_endRow = 0;
|
||
hv_endCol = hv_Width - 1;
|
||
}
|
||
else if (0 != (hv_in_CameraType == 3))
|
||
{
|
||
hv_startRow = 0;
|
||
hv_startCol = 0;
|
||
hv_endRow = 0;
|
||
hv_endCol = hv_Width - 1;
|
||
}
|
||
|
||
if (0 != hv_Debug)
|
||
{
|
||
GenRegionLine(&ho_RegionLines1, hv_startRow, hv_startCol, hv_endRow, hv_endCol);
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_in_Image1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Edges, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_RegionLines1, HDevWindowStack::GetActive());
|
||
//stop ()
|
||
}
|
||
//��Ʒ��Ե��ͼ���Ե�ľ���1,
|
||
DistancePl(hv_new_Row1, hv_new_Col1, hv_startRow, hv_startCol, hv_endRow, hv_endCol,
|
||
&hv_Distance1);
|
||
TupleLength(hv_Row1, &hv_Length1);
|
||
if (0 != (HTuple(hv_Length1 > 0).TupleAnd(hv_index == 1)))
|
||
{
|
||
(*hv_out_Line1).Clear();
|
||
(*hv_out_Line1).Append(hv_RowBegin);
|
||
(*hv_out_Line1).Append(hv_ColBegin);
|
||
(*hv_out_Line1).Append(hv_RowEnd);
|
||
(*hv_out_Line1).Append(hv_ColEnd);
|
||
(*hv_out_Line1).Append(hv_Height - 1);
|
||
(*hv_out_Line1).Append(0);
|
||
(*hv_out_Line1).Append(hv_Height - 1);
|
||
(*hv_out_Line1).Append(hv_Width - 1);
|
||
}
|
||
|
||
ho_ImageMirror = ho_in_Image2;
|
||
MultImage(ho_ImageMirror, ho_ImageMirror, &ho_ImageResult2, 0.006, 0);
|
||
Threshold(ho_ImageResult2, &ho_Region2, 0, 200);
|
||
Boundary(ho_Region2, &ho_RegionBorder, "inner");
|
||
|
||
ReduceDomain(ho_ImageResult2, ho_ObjectSelected, &ho_ImageReduced2);
|
||
EdgesSubPix(ho_ImageReduced2, &ho_Edges1, "canny", 4, 12, 24);
|
||
UnionAdjacentContoursXld(ho_Edges1, &ho_UnionContours, 10, 1, "attr_keep");
|
||
LengthXld(ho_UnionContours, &hv_Length3);
|
||
SelectContoursXld(ho_UnionContours, &ho_SelectedContours, "contour_length",
|
||
(hv_Length3.TupleMax()) - 1, (hv_Length3.TupleMax()) + 1, -0.5, 0.5);
|
||
FitLineContourXld(ho_SelectedContours, "tukey", -1, 0, 5, 2, &hv_RowBegin1,
|
||
&hv_ColBegin1, &hv_RowEnd1, &hv_ColEnd1, &hv_Nr1, &hv_Nc1, &hv_Dist1);
|
||
GetContourXld(ho_SelectedContours, &hv_Row2, &hv_Col2);
|
||
if (0 != (HTuple(hv_Col2[0]) > HTuple(hv_Col2[(hv_Col2.TupleLength()) - 1])))
|
||
{
|
||
TupleInverse(hv_Row2, &hv_new_Row2);
|
||
TupleInverse(hv_Col2, &hv_new_Col2);
|
||
}
|
||
else
|
||
{
|
||
hv_new_Row2 = hv_Row2;
|
||
hv_new_Col2 = hv_Col2;
|
||
}
|
||
|
||
if (0 != (hv_in_CameraType == 1))
|
||
{
|
||
hv_startRow = 0;
|
||
hv_startCol = 0;
|
||
hv_endRow = 0;
|
||
hv_endCol = hv_Width - 1;
|
||
}
|
||
else if (0 != (hv_in_CameraType == 2))
|
||
{
|
||
hv_startRow = hv_Height - 1;
|
||
hv_startCol = 0;
|
||
hv_endRow = hv_Height - 1;
|
||
hv_endCol = hv_Width - 1;
|
||
}
|
||
else if (0 != (hv_in_CameraType == 3))
|
||
{
|
||
hv_startRow = hv_Height - 1;
|
||
hv_startCol = 0;
|
||
hv_endRow = hv_Height - 1;
|
||
hv_endCol = hv_Width - 1;
|
||
}
|
||
if (0 != hv_Debug)
|
||
{
|
||
GenRegionLine(&ho_RegionLines2, hv_startRow, hv_startCol, hv_endRow, hv_endCol);
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_ImageMirror, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_Edges1, HDevWindowStack::GetActive());
|
||
if (HDevWindowStack::IsOpen())
|
||
DispObj(ho_RegionLines2, HDevWindowStack::GetActive());
|
||
//stop ()
|
||
}
|
||
|
||
//��Ʒ��Ե��ͼ���Ե�ľ���2,
|
||
DistancePl(hv_new_Row2, hv_new_Col2, hv_startRow, hv_startCol, hv_endRow, hv_endCol,
|
||
&hv_Distance2);
|
||
TupleLength(hv_Row2, &hv_Length2);
|
||
if (0 != (HTuple(hv_Length2 > 0).TupleAnd(hv_index == 1)))
|
||
{
|
||
(*hv_out_Line2).Clear();
|
||
(*hv_out_Line2).Append(hv_RowBegin1);
|
||
(*hv_out_Line2).Append(1920 - hv_ColBegin1);
|
||
(*hv_out_Line2).Append(hv_RowEnd1);
|
||
(*hv_out_Line2).Append(1920 - hv_ColEnd1);
|
||
(*hv_out_Line2).Append(hv_Height - 1);
|
||
(*hv_out_Line2).Append(0);
|
||
(*hv_out_Line2).Append(hv_Height - 1);
|
||
(*hv_out_Line2).Append(hv_Width - 1);
|
||
}
|
||
hv_Lenth = HTuple(hv_new_Row1.TupleLength()).TupleInt();
|
||
//�����ֳ�������е���,
|
||
if (0 != (hv_index == 1))
|
||
{
|
||
hvec_vector[0] = HTupleVector(hv_Distance1);
|
||
hvec_vector[1] = HTupleVector(hv_Distance2);
|
||
if (0 != (hv_in_Model != 0))
|
||
{
|
||
TupleAdd(hv_Distance1, hv_Distance2, &hv_Sum);
|
||
TupleGenConst(hv_Lenth, hv_in_Product_DPix, &hv_Newtuple);
|
||
TupleSub(hv_Newtuple, hv_Sum, &hv_Diff);
|
||
if (0 != (hv_in_CameraType == 1))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "UP_1.tup");
|
||
}
|
||
else if (0 != (hv_in_CameraType == 2))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "MI_1.tup");
|
||
}
|
||
else if (0 != (hv_in_CameraType == 3))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "Down_1.tup");
|
||
}
|
||
}
|
||
}
|
||
else if (0 != (hv_index == 2))
|
||
{
|
||
hvec_vector[2] = HTupleVector(hv_Distance1);
|
||
hvec_vector[3] = HTupleVector(hv_Distance2);
|
||
if (0 != (hv_in_Model != 0))
|
||
{
|
||
TupleAdd(hv_Distance1, hv_Distance2, &hv_Sum);
|
||
TupleGenConst(hv_Lenth, hv_in_Product_DPix, &hv_Newtuple);
|
||
TupleSub(hv_Newtuple, hv_Sum, &hv_Diff);
|
||
if (0 != (hv_in_CameraType == 1))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "UP_2.tup");
|
||
}
|
||
else if (0 != (hv_in_CameraType == 2))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "MI_2.tup");
|
||
}
|
||
else if (0 != (hv_in_CameraType == 3))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "Down_2.tup");
|
||
}
|
||
}
|
||
}
|
||
else if (0 != (hv_index == 3))
|
||
{
|
||
hvec_vector[4] = HTupleVector(hv_Distance1);
|
||
hvec_vector[5] = HTupleVector(hv_Distance2);
|
||
if (0 != (hv_in_Model != 0))
|
||
{
|
||
TupleAdd(hv_Distance1, hv_Distance2, &hv_Sum);
|
||
TupleGenConst(hv_Lenth, hv_in_Product_DPix, &hv_Newtuple);
|
||
TupleSub(hv_Newtuple, hv_Sum, &hv_Diff);
|
||
if (0 != (hv_in_CameraType == 1))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "UP_3.tup");
|
||
}
|
||
else if (0 != (hv_in_CameraType == 2))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "MI_3.tup");
|
||
}
|
||
else if (0 != (hv_in_CameraType == 3))
|
||
{
|
||
WriteTuple(hv_Diff, hv_in_Filepath + "Down_3.tup");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (0 != (hv_in_Model != 0))
|
||
{
|
||
(*hv_out_Flag) = 1;
|
||
return;
|
||
}
|
||
if (0 != (hv_in_CameraType == 1))
|
||
{
|
||
ReadTuple(hv_in_Filepath + "UP_1.tup", &hv_Tuple1);
|
||
ReadTuple(hv_in_Filepath + "UP_2.tup", &hv_Tuple2);
|
||
ReadTuple(hv_in_Filepath + "UP_3.tup", &hv_Tuple3);
|
||
}
|
||
else if (0 != (hv_in_CameraType == 2))
|
||
{
|
||
ReadTuple(hv_in_Filepath + "MI_1.tup", &hv_Tuple1);
|
||
ReadTuple(hv_in_Filepath + "MI_2.tup", &hv_Tuple2);
|
||
ReadTuple(hv_in_Filepath + "MI_3.tup", &hv_Tuple3);
|
||
}
|
||
else if (0 != (hv_in_CameraType == 3))
|
||
{
|
||
ReadTuple(hv_in_Filepath + "Down_1.tup", &hv_Tuple1);
|
||
ReadTuple(hv_in_Filepath + "Down_2.tup", &hv_Tuple2);
|
||
ReadTuple(hv_in_Filepath + "Down_3.tup", &hv_Tuple3);
|
||
}
|
||
|
||
//********************************************************************************
|
||
//�ô���������, ��������ĵ�
|
||
if (0 != ((hvec_vector[0].T().TupleLength()) != (hv_Tuple1.TupleLength())))
|
||
{
|
||
{
|
||
HTuple ExpTmpOutVar_0;
|
||
TupleRemove(hvec_vector[0].T(), HTuple::TupleGenSequence(hv_Tuple1.TupleLength(), (hvec_vector[0].T().TupleLength()) - 1, 1),
|
||
&ExpTmpOutVar_0);
|
||
hvec_vector[0].T() = ExpTmpOutVar_0;
|
||
}
|
||
}
|
||
if (0 != ((hvec_vector[1].T().TupleLength()) != (hv_Tuple1.TupleLength())))
|
||
{
|
||
{
|
||
HTuple ExpTmpOutVar_0;
|
||
TupleRemove(hvec_vector[1].T(), HTuple::TupleGenSequence(hv_Tuple1.TupleLength(), (hvec_vector[1].T().TupleLength()) - 1, 1),
|
||
&ExpTmpOutVar_0);
|
||
hvec_vector[1].T() = ExpTmpOutVar_0;
|
||
}
|
||
}
|
||
|
||
if (0 != ((hvec_vector[2].T().TupleLength()) != (hv_Tuple2.TupleLength())))
|
||
{
|
||
{
|
||
HTuple ExpTmpOutVar_0;
|
||
TupleRemove(hvec_vector[2].T(), HTuple::TupleGenSequence(hv_Tuple2.TupleLength(), (hvec_vector[2].T().TupleLength()) - 1, 1),
|
||
&ExpTmpOutVar_0);
|
||
hvec_vector[2].T() = ExpTmpOutVar_0;
|
||
}
|
||
}
|
||
if (0 != ((hvec_vector[3].T().TupleLength()) != (hv_Tuple2.TupleLength())))
|
||
{
|
||
{
|
||
HTuple ExpTmpOutVar_0;
|
||
TupleRemove(hvec_vector[3].T(), HTuple::TupleGenSequence(hv_Tuple2.TupleLength(), (hvec_vector[3].T().TupleLength()) - 1, 1),
|
||
&ExpTmpOutVar_0);
|
||
hvec_vector[3].T() = ExpTmpOutVar_0;
|
||
}
|
||
}
|
||
|
||
if (0 != ((hvec_vector[4].T().TupleLength()) != (hv_Tuple3.TupleLength())))
|
||
{
|
||
{
|
||
HTuple ExpTmpOutVar_0;
|
||
TupleRemove(hvec_vector[4].T(), HTuple::TupleGenSequence(hv_Tuple3.TupleLength(), (hvec_vector[4].T().TupleLength()) - 1, 1),
|
||
&ExpTmpOutVar_0);
|
||
hvec_vector[4].T() = ExpTmpOutVar_0;
|
||
}
|
||
}
|
||
if (0 != ((hvec_vector[5].T().TupleLength()) != (hv_Tuple3.TupleLength())))
|
||
{
|
||
{
|
||
HTuple ExpTmpOutVar_0;
|
||
TupleRemove(hvec_vector[5].T(), HTuple::TupleGenSequence(hv_Tuple3.TupleLength(), (hvec_vector[5].T().TupleLength()) - 1, 1),
|
||
&ExpTmpOutVar_0);
|
||
hvec_vector[5].T() = ExpTmpOutVar_0;
|
||
}
|
||
}
|
||
//********************************************************************************
|
||
//����һ������,
|
||
hv_Sel_Distance1 = hvec_vector[0].T();
|
||
hv_Sel_Distance2 = hvec_vector[1].T();
|
||
TupleAdd(hv_Sel_Distance1, hv_Sel_Distance2, &hv_Sum1);
|
||
TupleAdd(hv_Sum1, hv_Tuple1, &hv_Sum1);
|
||
//���������ֱ��(����㼯),
|
||
hv_Diam = hv_Sum1 * hv_in_Resolution;
|
||
//���ݽ�������ȥ������ֵ,
|
||
TupleSort(hv_Diam, &hv_Sorted);
|
||
TupleLength(hv_Sorted, &hv_Length);
|
||
hv_start = (hv_Length * 0.15).TupleInt();
|
||
hv_end = (hv_Length * (1 - 0.15)).TupleInt();
|
||
//ȥ��ǰ��ٷ�֮40����ֵ
|
||
TupleSelect(hv_Sorted, HTuple::TupleGenSequence(hv_start, hv_end, 1), &hv_distSelected);
|
||
TupleMean(hv_distSelected, &hv_Mean);
|
||
TupleMax(hv_distSelected, &hv_Max);
|
||
(*hv_out_Distance)[0] = hv_Max;
|
||
|
||
//������������,
|
||
hv_Sel_Distance3 = hvec_vector[2].T();
|
||
hv_Sel_Distance4 = hvec_vector[3].T();
|
||
TupleAdd(hv_Sel_Distance3, hv_Sel_Distance4, &hv_Sum2);
|
||
TupleAdd(hv_Sum2, hv_Tuple2, &hv_Sum2);
|
||
//���������ֱ��(�����Ʒ),
|
||
hv_Diam = hv_Sum2 * hv_in_Resolution;
|
||
//���ݽ�������ȥ������ֵ,
|
||
TupleSort(hv_Diam, &hv_Sorted);
|
||
TupleLength(hv_Sorted, &hv_Length);
|
||
hv_start = (hv_Length * 0.15).TupleInt();
|
||
hv_end = (hv_Length * (1 - 0.15)).TupleInt();
|
||
//ȥ��ǰ��ٷ�֮40����ֵ
|
||
TupleSelect(hv_Sorted, HTuple::TupleGenSequence(hv_start, hv_end, 1), &hv_distSelected);
|
||
TupleMean(hv_distSelected, &hv_Mean);
|
||
TupleMax(hv_distSelected, &hv_Max);
|
||
(*hv_out_Distance)[1] = hv_Max;
|
||
|
||
//������������,
|
||
hv_Sel_Distance5 = hvec_vector[4].T();
|
||
hv_Sel_Distance6 = hvec_vector[5].T();
|
||
TupleAdd(hv_Sel_Distance5, hv_Sel_Distance6, &hv_Sum3);
|
||
TupleAdd(hv_Sum3, hv_Tuple3, &hv_Sum3);
|
||
//���������ֱ��(�����Ʒ),
|
||
hv_Diam = hv_Sum3 * hv_in_Resolution;
|
||
//���ݽ�������ȥ������ֵ,
|
||
TupleSort(hv_Diam, &hv_Sorted);
|
||
TupleLength(hv_Sorted, &hv_Length);
|
||
hv_start = (hv_Length * 0.15).TupleInt();
|
||
hv_end = (hv_Length * (1 - 0.15)).TupleInt();
|
||
//ȥ��ǰ��ٷ�֮40����ֵ
|
||
TupleSelect(hv_Sorted, HTuple::TupleGenSequence(hv_start, hv_end, 1), &hv_distSelected);
|
||
TupleMean(hv_distSelected, &hv_Mean);
|
||
TupleMax(hv_distSelected, &hv_Max);
|
||
(*hv_out_Distance)[2] = hv_Max;
|
||
if (0 != (((*hv_out_Distance).TupleLength()) == 3))
|
||
{
|
||
(*hv_out_Flag) = 1;
|
||
}
|
||
}
|
||
// catch (Exception)
|
||
catch (HException& HDevExpDefaultException)
|
||
{
|
||
HDevExpDefaultException.ToHTuple(&hv_Exception);
|
||
|
||
}
|
||
|
||
return;
|
||
}
|
||
|