c++ - knnsearch taking lot of time for large number of features -
i using flann based knnsearch. feature-set contains 4 images of size 500*500. want nearest neighbors points in 4 images(the query set same feature set) taking lot of time run in opencv cpp. there can done reduce run-time. have set num_features = 500*500 , dimensionality = 4. want distance , nearest neighbors each point in 4 images, dists , index matrix should have same no.of elements features. here code
mat features,temp[4]; //input array of 4 images contain features. int num_data = input[0].rows * input[0].cols; int num_queries = input[0].rows * input[0].cols; temp[0] = input[0].clone(); temp[1] = input[1].clone(); temp[2] = input[2].clone(); temp[3] = input[3].clone(); temp[0] = temp[0].reshape(0, num_data); transpose(temp[0], temp[0]); temp[1] = temp[1].reshape(0, num_data); transpose(temp[1], temp[1]); temp[2] = temp[2].reshape(0, num_data); transpose(temp[2], temp[2]); temp[3] = temp[3].reshape(0, num_data); transpose(temp[3], temp[3]); vconcat(temp[0],temp[1],features); vconcat(temp[2], features, features); vconcat(temp[3], features, features); mat query = features.clone(); flann::kdtreeindexparams indexparams(5); flann::index kdtree(features, indexparams); mat indices; mat dists; int k = 3; kdtree.knnsearch(query, indices, dists, k, flann::searchparams(10)); mat avg; reduce(dists, avg, 1, cv_reduce_avg);
size of features 250000*4.
size of dists , indices 250000*3 , size of avg 250000*1.
am doing wrong here? tried find not detailed explanation of knnsearch in opencv.
Comments
Post a Comment