Reputation: 13211
The title says everything..
For my little image recognition project, I am doing a matching between my queryDescriptors and the vectorOfTrainingDescriptors.
So, what I would like to add, is first to check if the same image was already used / exists in my training data..
I was thinking this should be a simple task, and tried the following:
int findTheSameMat(const cv::Mat MatQ, const vector<cv::Mat> MatV) {
int result = -1;
for (int i = 0; i < MatV.size(); i++) {
if (cv::countNonZero(MatQ != MatV[i]) == 0) {
result = i;
break;
}
}
return result;
}
.. But I get the following error message:
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array') in compare, file /tmp/opencv-HEsb4m/opencv-2.4.9/modules/core/src/arithm.cpp, line 2465 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-HEsb4m/opencv-2.4.9/modules/core/src/arithm.cpp:2465: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array' in function compare
This is strange, because the types of MatQ && MatV[i] should be the same.. They are defined as
Mat MatQ;
vector<Mat> MatV;
Any ideas? Because I am a C++ noob.
Upvotes: 0
Views: 184
Reputation: 50667
MatQ != MatV[i]
requires that MatQ
and MatV[i]
are with the same size, i.e. same width and height.
To make it work, you can first check whether their sizes are the same. You only need to do the next check if they do have the same size. Like
if (MatQ.size() == MatV[i].size()) {
if (cv::countNonZero(MatQ != MatV[i]) == 0) {
result = i;
break;
}
}
Upvotes: 1