-1
我在txt文件2個的灰度圖像,其中之一是主圖像的較小塊。我已經將圖像讀入兩個不同的2d向量矩陣。C++圖像處理數據塊到陣列/指針
行和圖像的列是:
主:M = 768 N = 1024
SubImg:R = 49 C = 36
INT R = 49; int C = 36; //子圖像行/列
INT M = 768; int N = 1024; //主圖像行/列
我已經通過寬度爲49和高度爲36的塊遍歷主圖像,並且我想將每個塊放入一個數組,因此我可以將該數組與Sub圖像進行比較(使用最近鄰搜索),以查看哪個塊具有最接近結果提供給子圖像。
這是主圖像的循環代碼:一氣呵成
for (double bx = 0; bx < M; bx += R)
for (double by = 0; by < N; by += C)
{
for (int x = 0; ((x < R) && ((bx + x) < M)); ++x)
{
for (int y = 0; ((y < C) && ((by + y) < N)); ++y)
{
if ((bx + x) >= M)
{
std::cout << (bx + x) << (by + y) << " ";
}
cout << MainIMG_2DVector[bx + x][by + y] << " ";
}
}
cout << "\n\n\n" << endl;
}
這個循環顯示所有的塊。我遇到的問題是我不知道如何將每個塊放入數組,因此我可以比較數據。 也就是它更好地使用指針,而不是一個數組來做到這一點?
感謝
你好,謝謝你的回答,但如何我可以申報Block嗎?我繼續得到這個錯誤信息(沒有默認構造函數存在類「塊」。對不起,我是新來的C++。乾杯。 – QWERTY
有幾種不同的方法可以做到這一點,通常類定義在自己的頭文件和在一個相應的.cpp文件中實現。一個通用的C++對象教程是[here](http://www.cplusplus.com/doc/tutorial/classes/)幫助你入門。 –