How to copy keypoints to another vector
-
19-02-2021 - |
Question
I have this variable
std::vector <cv::KeyPoint> X[e];
with e as the number of files processed, and a similar "filtered" vector variable
std::vector <cv::KeyPoint< Y[e];
I used vector X as container of detected features
int minHessian = 400;
cv::SurfFeatureDetector deteC( minHessian );
deteC.detect(f[z], X[z]);
where
cv::Mat f[e]
is the container of the images, and z is just a counter.
Then this sequence is started
int kd = 0;
for(int dk = 0; dk < X[z].size(); dk++)
{
cv::KeyPoint s = X[z].at(dk);
qDebug() << fT << "KEYPOINT" << dk << "\nCLASS ID: " << s.class_id << "\nRESPONSE: "
<< s.response << "\nOCTAVE: " << s.octave
<< "\nSIZE: " << s.size << "\nANGLE: " << s.angle
<< "\nX: " << s.pt.x << " Y: " << s.pt.y;
if(s.octave > 2 && s.response > 5000.00)
{
s.class_id = e;
kd++;
// I plan to COPY s to Y[e].at(kd)
}
}
How can I copy s to Y[e].at(kd) ? Thanks for responses! =)
Solution
// I plan to COPY s to Y[e].at(kd)
If you know, before the loop begins, what size Y[e]
will become, then you can put this before the loop:
Y[e].resize(size_that_Ye_vector_will_be);
and this inside the loop:
Y[e].at(kd) = s;
On the other hand, if you don't know how large Y[e]
will become, you should use push_back
inside the loop to grow the vector one item at a time:
Y[e].push_back(s);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow