任務(wù)
因為實現(xiàn)代碼相對簡單,然后又沒有使用Opencv,所以就直接用C#實現(xiàn),C#調(diào)用。
1.創(chuàng)建類庫
1.1新建一個類庫
vs2015 => 文件 => 新建 => 項目
using System;
using System.Collections.Generic;
using System.Linq;
namespace YourLibraryName
{
public class OutlierRemoval:IOutlierRemoval
{
public List<int> RemoveOutliers(List<double> y, out List<double> outliers)
{
// 將代碼移動到此處
// ...
return outlierIndices;
}
public List<List<double>> RemoveOutliersAndGetYMaxResults(List<double> y, out List<double> y_max_results)
{
// 將代碼移動到此處
// ...
return outliers_results;
}
}
}
1.2添加一個接口
為了方便后續(xù)可維護,我還添加了接口,而不是直接調(diào)用類中的方法;在上述類庫中 => 添加 => 接口
using System.Collections.Generic;
namespace YourLibraryName
{
public interface IOutlierRemoval
{
List<int> RemoveOutliers(List<double> y, out List<double> outliers);
List<List<double>> RemoveOutliersAndGetYMaxResults(List<double> y, out List<double> y_max_results);
}
}
2.創(chuàng)建一個demo
告訴軟開怎么用這個函數(shù)
首先點擊解決方案,然后點擊添加 => 新建項目 => 控制臺應(yīng)用程序
2.1引用
打開引用 點擊“項目”添加引用
2.2 編寫demo
第一步:using 命名空間
第二步:創(chuàng)建接口實例
IOutlierRemoval outlierRemoval = new OutlierRemoval();
第三步:調(diào)用接口文章來源:http://www.zghlxwxcb.cn/news/detail-631810.html
// 調(diào)用接口方法
List<double> y = new List<double> { 1.2, 3.4, 5.6, 100.0, 7.8, 9.0 }; // 示例輸入數(shù)據(jù)
// 調(diào)用函數(shù) RemoveOutliers
List<double> outliers;
List<int> outlierIndices = outlierRemoval.RemoveOutliers(y, out outliers);
// 調(diào)用函數(shù) RemoveOutliersAndGetYMaxResults
List<double> y_max_results;
List<List<double>> outliers_results = outlierRemoval.RemoveOutliersAndGetYMaxResults(y, out y_max_results);
問題
文章來源地址http://www.zghlxwxcb.cn/news/detail-631810.html
到了這里,關(guān)于【傳統(tǒng)視覺】C#創(chuàng)建、封裝、調(diào)用類庫的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!