@@ -890,11 +890,11 @@ class SURF_Descriptor_Upright_64_Invoker : public ParallelLoopBody
890
890
{
891
891
for (int i = range.start ; i < range.end ; i++)
892
892
{
893
- Get_SURF_Descriptor_Upright_64 ((*keypoints_)[i], descriptors_->ptr <float >(i));
893
+ Get_SURF_Descriptor_Upright_64 ((*keypoints_)[i], descriptors_->ptr <float >(i), descriptors_-> cols );
894
894
}
895
895
}
896
896
897
- void Get_SURF_Descriptor_Upright_64 (const KeyPoint& kpt, float * desc) const ;
897
+ void Get_SURF_Descriptor_Upright_64 (const KeyPoint& kpt, float * desc, int desc_size ) const ;
898
898
899
899
private:
900
900
std::vector<KeyPoint>* keypoints_;
@@ -916,11 +916,11 @@ class SURF_Descriptor_64_Invoker : public ParallelLoopBody
916
916
{
917
917
for (int i = range.start ; i < range.end ; i++)
918
918
{
919
- Get_SURF_Descriptor_64 ((*keypoints_)[i], descriptors_->ptr <float >(i));
919
+ Get_SURF_Descriptor_64 ((*keypoints_)[i], descriptors_->ptr <float >(i), descriptors_-> cols );
920
920
}
921
921
}
922
922
923
- void Get_SURF_Descriptor_64 (const KeyPoint& kpt, float * desc) const ;
923
+ void Get_SURF_Descriptor_64 (const KeyPoint& kpt, float * desc, int desc_size ) const ;
924
924
925
925
private:
926
926
std::vector<KeyPoint>* keypoints_;
@@ -942,11 +942,11 @@ class MSURF_Upright_Descriptor_64_Invoker : public ParallelLoopBody
942
942
{
943
943
for (int i = range.start ; i < range.end ; i++)
944
944
{
945
- Get_MSURF_Upright_Descriptor_64 ((*keypoints_)[i], descriptors_->ptr <float >(i));
945
+ Get_MSURF_Upright_Descriptor_64 ((*keypoints_)[i], descriptors_->ptr <float >(i), descriptors_-> cols );
946
946
}
947
947
}
948
948
949
- void Get_MSURF_Upright_Descriptor_64 (const KeyPoint& kpt, float * desc) const ;
949
+ void Get_MSURF_Upright_Descriptor_64 (const KeyPoint& kpt, float * desc, int desc_size ) const ;
950
950
951
951
private:
952
952
std::vector<KeyPoint>* keypoints_;
@@ -968,11 +968,11 @@ class MSURF_Descriptor_64_Invoker : public ParallelLoopBody
968
968
{
969
969
for (int i = range.start ; i < range.end ; i++)
970
970
{
971
- Get_MSURF_Descriptor_64 ((*keypoints_)[i], descriptors_->ptr <float >(i));
971
+ Get_MSURF_Descriptor_64 ((*keypoints_)[i], descriptors_->ptr <float >(i), descriptors_-> cols );
972
972
}
973
973
}
974
974
975
- void Get_MSURF_Descriptor_64 (const KeyPoint& kpt, float * desc) const ;
975
+ void Get_MSURF_Descriptor_64 (const KeyPoint& kpt, float * desc, int desc_size ) const ;
976
976
977
977
private:
978
978
std::vector<KeyPoint>* keypoints_;
@@ -995,11 +995,11 @@ class Upright_MLDB_Full_Descriptor_Invoker : public ParallelLoopBody
995
995
{
996
996
for (int i = range.start ; i < range.end ; i++)
997
997
{
998
- Get_Upright_MLDB_Full_Descriptor ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i));
998
+ Get_Upright_MLDB_Full_Descriptor ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i), descriptors_-> cols );
999
999
}
1000
1000
}
1001
1001
1002
- void Get_Upright_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char * desc) const ;
1002
+ void Get_Upright_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char * desc, int desc_size ) const ;
1003
1003
1004
1004
private:
1005
1005
std::vector<KeyPoint>* keypoints_;
@@ -1030,11 +1030,11 @@ class Upright_MLDB_Descriptor_Subset_Invoker : public ParallelLoopBody
1030
1030
{
1031
1031
for (int i = range.start ; i < range.end ; i++)
1032
1032
{
1033
- Get_Upright_MLDB_Descriptor_Subset ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i));
1033
+ Get_Upright_MLDB_Descriptor_Subset ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i), descriptors_-> cols );
1034
1034
}
1035
1035
}
1036
1036
1037
- void Get_Upright_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char * desc) const ;
1037
+ void Get_Upright_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char * desc, int desc_size ) const ;
1038
1038
1039
1039
private:
1040
1040
std::vector<KeyPoint>* keypoints_;
@@ -1061,11 +1061,11 @@ class MLDB_Full_Descriptor_Invoker : public ParallelLoopBody
1061
1061
{
1062
1062
for (int i = range.start ; i < range.end ; i++)
1063
1063
{
1064
- Get_MLDB_Full_Descriptor ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i));
1064
+ Get_MLDB_Full_Descriptor ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i), descriptors_-> cols );
1065
1065
}
1066
1066
}
1067
1067
1068
- void Get_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char * desc) const ;
1068
+ void Get_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char * desc, int desc_size ) const ;
1069
1069
void MLDB_Fill_Values (float * values, int sample_step, int level,
1070
1070
float xf, float yf, float co, float si, float scale) const ;
1071
1071
void MLDB_Binary_Comparisons (float * values, unsigned char * desc,
@@ -1100,11 +1100,11 @@ class MLDB_Descriptor_Subset_Invoker : public ParallelLoopBody
1100
1100
{
1101
1101
for (int i = range.start ; i < range.end ; i++)
1102
1102
{
1103
- Get_MLDB_Descriptor_Subset ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i));
1103
+ Get_MLDB_Descriptor_Subset ((*keypoints_)[i], descriptors_->ptr <unsigned char >(i), descriptors_-> cols );
1104
1104
}
1105
1105
}
1106
1106
1107
- void Get_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char * desc) const ;
1107
+ void Get_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char * desc, int desc_size ) const ;
1108
1108
1109
1109
private:
1110
1110
std::vector<KeyPoint>* keypoints_;
@@ -1407,23 +1407,25 @@ void AKAZEFeatures::Compute_Keypoints_Orientation(std::vector<KeyPoint>& kpts) c
1407
1407
* from Agrawal et al., CenSurE: Center Surround Extremas for Realtime Feature Detection and Matching,
1408
1408
* ECCV 2008
1409
1409
*/
1410
- void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64 (const KeyPoint& kpt, float *desc) const {
1410
+ void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64 (const KeyPoint& kpt, float *desc, int desc_size) const {
1411
+
1412
+ const int dsize = 64 ;
1413
+ CV_Assert (desc_size == dsize);
1411
1414
1412
1415
float dx = 0.0 , dy = 0.0 , mdx = 0.0 , mdy = 0.0 , gauss_s1 = 0.0 , gauss_s2 = 0.0 ;
1413
1416
float rx = 0.0 , ry = 0.0 , len = 0.0 , xf = 0.0 , yf = 0.0 , ys = 0.0 , xs = 0.0 ;
1414
1417
float sample_x = 0.0 , sample_y = 0.0 ;
1415
1418
int x1 = 0 , y1 = 0 , sample_step = 0 , pattern_size = 0 ;
1416
1419
int x2 = 0 , y2 = 0 , kx = 0 , ky = 0 , i = 0 , j = 0 , dcount = 0 ;
1417
1420
float fx = 0.0 , fy = 0.0 , ratio = 0.0 , res1 = 0.0 , res2 = 0.0 , res3 = 0.0 , res4 = 0.0 ;
1418
- int scale = 0 , dsize = 0 ;
1421
+ int scale = 0 ;
1419
1422
1420
1423
// Subregion centers for the 4x4 gaussian weighting
1421
1424
float cx = -0 .5f , cy = 0 .5f ;
1422
1425
1423
1426
const std::vector<Evolution>& evolution = *evolution_;
1424
1427
1425
1428
// Set the descriptor size and the sample and pattern sizes
1426
- dsize = 64 ;
1427
1429
sample_step = 5 ;
1428
1430
pattern_size = 12 ;
1429
1431
@@ -1466,11 +1468,11 @@ void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64(const
1466
1468
// Get the gaussian weighted x and y responses
1467
1469
gauss_s1 = gaussian (xs - sample_x, ys - sample_y, 2 .50f *scale);
1468
1470
1469
- y1 = (int )(sample_y - .5 );
1470
- x1 = (int )(sample_x - .5 );
1471
+ y1 = (int )(sample_y - .5f );
1472
+ x1 = (int )(sample_x - .5f );
1471
1473
1472
- y2 = (int )(sample_y + .5 );
1473
- x2 = (int )(sample_x + .5 );
1474
+ y2 = (int )(sample_y + .5f );
1475
+ x2 = (int )(sample_x + .5f );
1474
1476
1475
1477
fx = sample_x - x1;
1476
1478
fy = sample_y - y1;
@@ -1514,6 +1516,8 @@ void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64(const
1514
1516
i += 9 ;
1515
1517
}
1516
1518
1519
+ CV_Assert (dcount == desc_size);
1520
+
1517
1521
// convert to unit vector
1518
1522
len = sqrt (len);
1519
1523
@@ -1532,23 +1536,25 @@ void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64(const
1532
1536
* from Agrawal et al., CenSurE: Center Surround Extremas for Realtime Feature Detection and Matching,
1533
1537
* ECCV 2008
1534
1538
*/
1535
- void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64 (const KeyPoint& kpt, float *desc) const {
1539
+ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64 (const KeyPoint& kpt, float *desc, int desc_size) const {
1540
+
1541
+ const int dsize = 64 ;
1542
+ CV_Assert (desc_size == dsize);
1536
1543
1537
1544
float dx = 0.0 , dy = 0.0 , mdx = 0.0 , mdy = 0.0 , gauss_s1 = 0.0 , gauss_s2 = 0.0 ;
1538
1545
float rx = 0.0 , ry = 0.0 , rrx = 0.0 , rry = 0.0 , len = 0.0 , xf = 0.0 , yf = 0.0 , ys = 0.0 , xs = 0.0 ;
1539
1546
float sample_x = 0.0 , sample_y = 0.0 , co = 0.0 , si = 0.0 , angle = 0.0 ;
1540
1547
float fx = 0.0 , fy = 0.0 , ratio = 0.0 , res1 = 0.0 , res2 = 0.0 , res3 = 0.0 , res4 = 0.0 ;
1541
1548
int x1 = 0 , y1 = 0 , x2 = 0 , y2 = 0 , sample_step = 0 , pattern_size = 0 ;
1542
1549
int kx = 0 , ky = 0 , i = 0 , j = 0 , dcount = 0 ;
1543
- int scale = 0 , dsize = 0 ;
1550
+ int scale = 0 ;
1544
1551
1545
1552
// Subregion centers for the 4x4 gaussian weighting
1546
1553
float cx = -0 .5f , cy = 0 .5f ;
1547
1554
1548
1555
const std::vector<Evolution>& evolution = *evolution_;
1549
1556
1550
1557
// Set the descriptor size and the sample and pattern sizes
1551
- dsize = 64 ;
1552
1558
sample_step = 5 ;
1553
1559
pattern_size = 12 ;
1554
1560
@@ -1652,6 +1658,8 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
1652
1658
i += 9 ;
1653
1659
}
1654
1660
1661
+ CV_Assert (dcount == desc_size);
1662
+
1655
1663
// convert to unit vector
1656
1664
len = sqrt (len);
1657
1665
@@ -1667,7 +1675,7 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
1667
1675
* @param kpt Input keypoint
1668
1676
* @param desc Descriptor vector
1669
1677
*/
1670
- void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char *desc) const {
1678
+ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char *desc, int desc_size ) const {
1671
1679
1672
1680
float di = 0.0 , dx = 0.0 , dy = 0.0 ;
1673
1681
float ri = 0.0 , rx = 0.0 , ry = 0.0 , xf = 0.0 , yf = 0.0 ;
@@ -1703,6 +1711,8 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
1703
1711
divUp (pattern_size, 2 )
1704
1712
};
1705
1713
1714
+ memset (desc, 0 , desc_size);
1715
+
1706
1716
// For the three grids
1707
1717
for (int z = 0 ; z < 3 ; z++) {
1708
1718
dcount2 = 0 ;
@@ -1754,15 +1764,16 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
1754
1764
for (int k = 0 ; k < 3 ; ++k) {
1755
1765
if (*(valI + k) > *(valJ + k)) {
1756
1766
desc[dcount1 / 8 ] |= (1 << (dcount1 % 8 ));
1757
- } else {
1758
- desc[dcount1 / 8 ] &= ~(1 << (dcount1 % 8 ));
1759
1767
}
1760
1768
dcount1++;
1761
1769
}
1762
1770
}
1763
1771
}
1764
1772
1765
1773
} // for (int z = 0; z < 3; z++)
1774
+
1775
+ CV_Assert (dcount1 <= desc_size*8 );
1776
+ CV_Assert (divUp (dcount1, 8 ) == desc_size);
1766
1777
}
1767
1778
1768
1779
void MLDB_Full_Descriptor_Invoker::MLDB_Fill_Values (float * values, int sample_step, const int level,
@@ -1848,10 +1859,6 @@ void MLDB_Full_Descriptor_Invoker::MLDB_Binary_Comparisons(float* values, unsign
1848
1859
if (ival > ivalues[chan * j + pos]) {
1849
1860
desc[dpos >> 3 ] |= (1 << (dpos & 7 ));
1850
1861
}
1851
- else {
1852
- desc[dpos >> 3 ] &= ~(1 << (dpos & 7 ));
1853
- }
1854
-
1855
1862
dpos++;
1856
1863
}
1857
1864
}
@@ -1865,7 +1872,7 @@ void MLDB_Full_Descriptor_Invoker::MLDB_Binary_Comparisons(float* values, unsign
1865
1872
* @param kpt Input keypoint
1866
1873
* @param desc Descriptor vector
1867
1874
*/
1868
- void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char *desc) const {
1875
+ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor (const KeyPoint& kpt, unsigned char *desc, int desc_size ) const {
1869
1876
1870
1877
const int max_channels = 3 ;
1871
1878
CV_Assert (options_->descriptor_channels <= max_channels);
@@ -1888,13 +1895,18 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
1888
1895
float co = cos (angle);
1889
1896
float si = sin (angle);
1890
1897
1891
- int dpos = 0 ;
1892
- for (int lvl = 0 ; lvl < 3 ; lvl++) {
1898
+ memset (desc, 0 , desc_size);
1893
1899
1900
+ int dpos = 0 ;
1901
+ for (int lvl = 0 ; lvl < 3 ; lvl++)
1902
+ {
1894
1903
int val_count = (lvl + 2 ) * (lvl + 2 );
1895
1904
MLDB_Fill_Values (values, sample_step[lvl], kpt.class_id , xf, yf, co, si, scale);
1896
1905
MLDB_Binary_Comparisons (values, desc, val_count, dpos);
1897
1906
}
1907
+
1908
+ CV_Assert (dpos == 486 );
1909
+ CV_Assert (divUp (dpos, 8 ) == desc_size);
1898
1910
}
1899
1911
1900
1912
/* ************************************************************************* */
@@ -1905,7 +1917,7 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
1905
1917
* @param kpt Input keypoint
1906
1918
* @param desc Descriptor vector
1907
1919
*/
1908
- void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char *desc) const {
1920
+ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char *desc, int desc_size ) const {
1909
1921
1910
1922
float di = 0 .f , dx = 0 .f , dy = 0 .f ;
1911
1923
float rx = 0 .f , ry = 0 .f ;
@@ -1995,11 +2007,12 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
1995
2007
// Do the comparisons
1996
2008
const int *comps = descriptorBits_.ptr <int >(0 );
1997
2009
2010
+ CV_Assert (divUp (descriptorBits_.rows , 8 ) == desc_size);
2011
+ memset (desc, 0 , desc_size);
2012
+
1998
2013
for (int i = 0 ; i<descriptorBits_.rows ; i++) {
1999
2014
if (values[comps[2 * i]] > values[comps[2 * i + 1 ]]) {
2000
2015
desc[i / 8 ] |= (1 << (i % 8 ));
2001
- } else {
2002
- desc[i / 8 ] &= ~(1 << (i % 8 ));
2003
2016
}
2004
2017
}
2005
2018
}
@@ -2012,7 +2025,7 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
2012
2025
* @param kpt Input keypoint
2013
2026
* @param desc Descriptor vector
2014
2027
*/
2015
- void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char *desc) const {
2028
+ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset (const KeyPoint& kpt, unsigned char *desc, int desc_size ) const {
2016
2029
2017
2030
float di = 0 .0f , dx = 0 .0f , dy = 0 .0f ;
2018
2031
float rx = 0 .0f , ry = 0 .0f ;
@@ -2090,11 +2103,12 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
2090
2103
const float *vals = values.ptr <float >(0 );
2091
2104
const int *comps = descriptorBits_.ptr <int >(0 );
2092
2105
2106
+ CV_Assert (divUp (descriptorBits_.rows , 8 ) == desc_size);
2107
+ memset (desc, 0 , desc_size);
2108
+
2093
2109
for (int i = 0 ; i<descriptorBits_.rows ; i++) {
2094
2110
if (vals[comps[2 * i]] > vals[comps[2 * i + 1 ]]) {
2095
2111
desc[i / 8 ] |= (1 << (i % 8 ));
2096
- } else {
2097
- desc[i / 8 ] &= ~(1 << (i % 8 ));
2098
2112
}
2099
2113
}
2100
2114
}
0 commit comments