用opencvsharp4.6 实现以下函数 vector<Edge1D_Result> Extract1DEdge::Get1DEdge(Mat inputMat, Point2d pdCenter, double dMeasureLength, double dMeasureHeight, double dMeasureAngle,double sigma, int threshold, Translation traslation, Selection selection) { if (inputMat.empty()) { return vector<Edge1D_Result>(); } if (inputMat.channels() > 1) { cvtColor(inputMat, inputMat, COLOR_BGR2GRAY); } m_vEdgesResult.clear(); inputMat.copyTo(m_mInputMat); m_pdCenter = pdCenter; m_dLength = dMeasureLength; m_dHeight = dMeasureHeight; m_dAngle = dMeasureAngle; m_dSigma = sigma; m_nThreshold = threshold * (m_dSigma * sqrt(2 * PI)); GetEndPointsOfLine(pdCenter, dMeasureAngle, dMeasureLength, m_pdStart, m_pdEnd); m_dK = GetLineSlope(m_pdStart, m_pdEnd); m_dB = m_pdStart.y - m_dK * m_pdStart.x; GetProfieMat(); FilterMat(); GetGradientMat(); GetEdgePoint(threshold, traslation, selection); return m_vEdgesResult; }
时间: 2024-03-09 10:45:17 浏览: 53
以下是使用 OpenCvSharp4.6 实现的代码:
```csharp
public List<Edge1D_Result> Get1DEdge(Mat inputMat, Point2d pdCenter, double dMeasureLength, double dMeasureHeight, double dMeasureAngle, double sigma, int threshold, Translation traslation, Selection selection)
{
if (inputMat.Empty())
{
return new List<Edge1D_Result>();
}
if (inputMat.Channels() > 1)
{
Cv2.CvtColor(inputMat, inputMat, ColorConversionCodes.BGR2GRAY);
}
m_vEdgesResult.Clear();
inputMat.CopyTo(m_mInputMat);
m_pdCenter = pdCenter;
m_dLength = dMeasureLength;
m_dHeight = dMeasureHeight;
m_dAngle = dMeasureAngle;
m_dSigma = sigma;
m_nThreshold = (int)(threshold * (m_dSigma * Math.Sqrt(2 * Math.PI)));
GetEndPointsOfLine(pdCenter, dMeasureAngle, dMeasureLength, m_pdStart, m_pdEnd);
m_dK = GetLineSlope(m_pdStart, m_pdEnd);
m_dB = m_pdStart.Y - m_dK * m_pdStart.X;
GetProfieMat();
FilterMat();
GetGradientMat();
GetEdgePoint(threshold, traslation, selection);
return m_vEdgesResult;
}
```
请注意,这只是一个参考实现,可能需要根据实际情况进行修改。同时,这段代码中的一些变量和函数定义可能需要根据原代码进行调整。
阅读全文