下載 Boost C++ Libraries 依照你的Visual Studio 選擇適合的版本
include目錄
加入Boost Library路徑[1],
以我安裝的環境為例
E:\Boost Library\boost_1_60_0
library目錄
加入Boost Library路徑
以我安裝的環境為例
E:\Boost Library\boost_1_60_0\stage\lib
colorInRange.h
不過經過測試發現Boost library似乎不支援/CLR,
這個等之後有空再繼續研究,
目前打算改採由C#掃描某個資料夾下所有的Txt檔案,
並堆疊至一個string型態變數, 每個檔案路徑以分號( ; )區隔,
然後C#傳入該string給C++ DLL進行解析, 並儲存至一個txt檔案,
以便觀察是否正確….
Exceptions環境設定[8]
colorInRange.h
colorInRange.cpp [9]
void ImgProc::loadTxtToMat(wchar_t* fileListPath, wchar_t* fileName)
{
// fileListPath: 掃描某個資料夾下所有的Txt檔案,並堆疊至一個string型態變數, 每個檔案路徑以分號(;)區隔
// fileName: 儲存至一個txt檔案
std::ofstream fout;
wstring savefileName(fileName);
fout.open(savefileName, std::ios_base::out);
wstring ws(fileListPath);
string fileList = ImgProc::WstringToString(ws);
char *s = new char[fileList.length() + 1];
strcpy(s, fileList.c_str());
char *t = strtok(s, ";");
while (t != NULL) {
fout << t << endl;
t = strtok(NULL, ";");
}
fout.close();
delete[]s;
}
C# Form1.cs
private void vectorToolStripMenuItem_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog fbd = new FolderBrowserDialog())
{
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Filter = "Text File|*.txt|Csv File|*.csv";
sfd.Title = "輸出純文字檔案";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
DirectoryInfo d = new DirectoryInfo(fbd.SelectedPath);
StringBuilder sb = new StringBuilder();
foreach (var file in d.GetFiles("*.txt"))
{
sb.Append(fbd.SelectedPath + file.Name + ";");
}
unsafe
{
fixed (char* FileName = sfd.FileName)
fixed (char* dirPath = sb.ToString())
{
m_ip.loadTxtToMat(dirPath, FileName);
}
}
}
}
}
}
}
測試
接下來, 準備讀入一張一張影像路徑(*.txt)讀入暫時的Mat資料格式
並計算全部影像N張的平均和標準差
以下為單一張影像I 的平均和標準差公式
參考資料
1. Boost Library Version 1.60.0
3. Reading next line of a file
4. How can I read specific data columns from a file in c
5. how to read from text file and store in matrix in c
6. C# FolderBrowserDialog 類別
7. C# Find all files in a folder
留言列表