我有矩阵,其中每一行都是64维的SURF描述符。对于每一行,我需要:
我出来的唯一方法是:
template <typename T> int sgn(T val) {
return (T(0) < val) - (val < T(0));
}
void SURFOpenCV::ComputeDescriptors(cv::Mat &img, cv::Mat1f &descriptors){
descriptors.release();
std::vector<cv::KeyPoint> pts;
surf->detectAndCompute(img, cv::Mat(), pts, descriptors);
//if there is at least one keypoint
if(pts.size()){
// For each row
for (int i = 0; i < descriptors.rows; ++i) {
// Perform L1 normalization on the whole descriptor
cv::normalize(descriptors.row(i), descriptors.row(i), 1.0, 0.0, cv::NORM_L1);
for (int j = 0; j<descriptors.cols; j++) {
float val = descriptors.at<float>(i,j);
descriptors.at<float>(i,j) = sgn(val) * std::sqrt(val);
}
}
}
}
但由于表现至关重要,这对我来说效率低下。任何更好(更快)的解决方案?