我試圖比較16幅圖像(N = 4,M = 4)的大小和方向,並檢查它們之間的連續性。比較set_intersection(公共元素)的大小和方向使用?
所以,我比較像0與圖像1,圖像2 ...圖像15.
然後,圖像1,用圖像2,圖像3 ..image 15
每一個形象,尺寸200x200和CV_32F類型。
我有一個:
vector<Mat> smallImages;
smallImages.reserve(N * M); //(N = 4 , M = 4)
我已經計算出了梯度:
vector<Mat> grad_x;
vector<Mat> grad_y;
grad_x.resize(N*M);
grad_y.resize(N*M);
// gradients x and y
for (int idx = 0; idx < N*M; idx++)
{
Sobel(smallImages[ idx ], grad_x[ idx ], ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT);
Sobel(smallImages[ idx ], grad_y[ idx ], ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT);
}
然後,大小和方向:
// magnitude and direction
vector<Mat> magnitude;
vector<Mat> direction;
magnitude.resize(N*M);
direction.resize(N*M);
for (int idx = 0; idx < N*M; idx++)
{
cartToPolar(grad_x[ idx ], grad_y[ idx ], magnitude[ idx ], direction[ idx ]);
}
然後,我想比較(例如像[this]那樣的幅度)1:
vector<Mat> MagnitudeComp;
MagnitudeComp.resize(N*M * N*M);
std::vector<cv::Mat>::iterator it;
std::sort(magnitude.begin(), magnitude.end());
it = std::set_intersection(magnitude.begin(), magnitude.end(), direction.begin(), direction.end(), MagnitudeComp.begin());
MagnitudeComp.resize(it - MagnitudeComp.begin());
我不知道爲什麼的std ::排序不起作用(錯誤很多喜歡:)
/usr/include/c++/5.2.0/bits/predefined_ops.h:71:25: error: cannot convert ‘cv::MatExpr’ to ‘bool’ in return
{ return __val < *__it; }
我不知道是否有更好的方法來獲得我想要的(用於保持幅度和方向差異的矩陣)。
我知道我能做到:
CV ::排序(大小,數量,CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);
但我不確定是否可以做std::set_intersection
。
:我可以使用CV ::排序。我的問題是如何找到2個矩陣(幅度[0]和幅度[1])之間的共同元素。 – George
你能更清楚地定義「共同元素」嗎?單個矩陣中的兩個元素是共同的嗎?兩個矩陣中的不同位置上的兩個元素是共同的嗎? –
我想找到2個矩陣(例如幅度[0]和幅度[1])之間的元素(也可能是它們的位置)。但是,正如我在帖子的開始部分所說的那樣。我想要比較例如幅度[1],幅度[2]等。然後,幅度[1]與幅度[2],幅度[3]等等。 – George