@Override public double score(NccFeature a, NccFeature b) { return -DescriptorDistance.ncc(a, b); }
/** * Computes the hamming score between two descriptions. Larger the number better the fit */ protected int hamming(short[] a, short[] b) { int distance = 0; for (int i = 0; i < a.length; i++) { distance += DescriptorDistance.hamming((a[i]&0xFFFF) ^ (b[i]&0xFFFF)); } return distance; }
@Override public double score(TupleDesc_F64 a, TupleDesc_F64 b) { return -DescriptorDistance.correlation(a, b); }
@Override public double score(TupleDesc_S8 a, TupleDesc_S8 b) { return DescriptorDistance.sad(a, b); }
@Override public double score(TupleDesc_F64 a, TupleDesc_F64 b) { return DescriptorDistance.euclideanSq(a, b); }
@Override public double score(TupleDesc_F64 a, TupleDesc_F64 b) { return DescriptorDistance.euclidean(a,b); }
@Override public double score(TupleDesc_F64 a, TupleDesc_F64 b) { return DescriptorDistance.sad(a, b); }
@Override public double score(TupleDesc_F32 a, TupleDesc_F32 b) { return DescriptorDistance.euclideanSq(a, b); }
/** * Computes the best distance to 'observed' from the candidate list. * @param observed Feature being matched * @param candidates Set of candidate matches * @return score from 0 to 1, where lower is closer */ public double distance( NccFeature observed , List<NccFeature> candidates ) { double maximum = -Double.MAX_VALUE; // The feature which has the best fit will maximize the score for( NccFeature f : candidates ) { double score = DescriptorDistance.ncc(observed, f); if( score > maximum ) maximum = score; } return 1-0.5*(maximum + 1); }
@Override public double score(TupleDesc_B a, TupleDesc_B b) { return DescriptorDistance.hamming(a,b); }
@Override public double score(TupleDesc_F32 a, TupleDesc_F32 b) { return DescriptorDistance.sad(a, b); }
private void printDescriptions() { TldTemplateMatching<T> matching = tracker.getTemplateMatching(); FastQueue<TldRegion> detected = tracker.getDetection().getLocalMaximums(); NccFeature t = matching.createDescriptor(); NccFeature f = matching.createDescriptor(); matching.computeNccDescriptor(t, target.x0, target.y0, target.x1, target.y1); System.out.println("Target:"); printDescription(t); for( int i = 0; i < detected.size; i++ ) { TldRegion r = detected.get(i); matching.computeNccDescriptor(f,r.rect.x0,r.rect.y0,r.rect.x1,r.rect.y1); System.out.println("Detected:"); System.out.println(" "+r.rect); printDescription(f); System.out.println(" NCC score = "+ DescriptorDistance.ncc(t,f)); System.out.println(" Confidence = "+ matching.computeConfidence(r.rect)); System.out.println(" Distance = "+ matching.distance(f,matching.getTemplatePositive())); } }
/** * Computes the hamming distance between two binary feature descriptors * * @param a First variable * @param b Second variable * @return The hamming distance */ public static int hamming( TupleDesc_B a, TupleDesc_B b ) { int score = 0; final int N = a.data.length; for( int i = 0; i < N; i++ ) { score += hamming(a.data[i] ^ b.data[i]); } return score; }
@Override public double score(TupleDesc_U8 a, TupleDesc_U8 b) { return DescriptorDistance.sad(a, b); }