下載 Boost C++ Libraries 依照你的Visual Studio 選擇適合的版本

boost_1_60_0-msvc-14.0-64.exe

boost_1_60_0-msvc-12.0-64.exe

boost_1_60_0-msvc-11.0-64.exe

boost_1_60_0-msvc-10.0-64.exe

boost_1_60_0-msvc-9.0-64.exe

boost_1_60_0-msvc-8.0-64.exe

include目錄

加入Boost Library路徑[1], 

以我安裝的環境為例

E:\Boost Library\boost_1_60_0

image

library目錄

加入Boost Library路徑

以我安裝的環境為例

E:\Boost Library\boost_1_60_0\stage\lib

image

colorInRange.h

image

不過經過測試發現Boost library似乎不支援/CLR,

這個等之後有空再繼續研究,

目前打算改採由C#掃描某個資料夾下所有的Txt檔案,

並堆疊至一個string型態變數, 每個檔案路徑以分號( ; )區隔,

然後C#傳入該string給C++ DLL進行解析, 並儲存至一個txt檔案,

以便觀察是否正確….

Exceptions環境設定[8]

image

image

image

colorInRange.h

image

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);
                              }
                          }
                      }
                  }
              }
 
          }
      }

測試

image

接下來, 準備讀入一張一張影像路徑(*.txt)讀入暫時的Mat資料格式

並計算全部影像N張的平均和標準差

以下為單一張影像I 的平均和標準差公式

\begin{array}{l} N =  \sum _{I, \texttt{mask} (I)  \ne 0} 1 \\ \texttt{mean} _c =  \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c =  \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c -  \texttt{mean} _c \right )^2}{N}} \end{array}
















參考資料

1. Boost Library Version 1.60.0

2. Split a string in C++?

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

8. .NET "LoaderLock was detected" Exception

9. std::string to char*

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()