Reputation: 903
All the open CV examples I can find seem to relate to a 2D kernel over a 2D image.
I have a 1d kernel and am looking for an operation which will return, per row the value and offset which results in the maximum correlation.
Straight C++ my code would look like:
vector<int> offset(img.rows);
vector<int> amp(img.rows);
std::vector<double> corrs(MAX_SEARCH);
for(int row = 0; row< img.rows; row++){
row_data = img.row(row)
for (int i = 0; i < MAX_SEARCH; i++) {
double correlation = 0;
for (int j = 0; j < wfm.size(); j++) {
correlation += (wfm[j] * row_data[i+j]);
}
corrs[i] = correlation;
}
amp[row] = *std::max_element(corrs.begin(), corrs.end());
offest[row] = std::max_element(corrs.begin(), corrs.end()) - corrs.begin();
}
The key thing I'm looking for, is to be able to take advantage of some Single Instruction Multiple Data optimizations which I think OpenCV should be able to do, or if OpenCV won't achieve this, how could this code be rewritten to do so.
Upvotes: 0
Views: 271
Reputation: 613
If you are using OpenCV functions, then you need to build OpenCV for your machine with the SIMD support. Or you can follow this solution on OpenCV forums.
For your code, might I recommend OpenMP. It's easy to add. You would just add #pragma omp simd
before the last for loop. Then compile with -fopenmp. Here is a simple tutorial to understand OpenMP. And their documentation on the simd option.
Upvotes: 1