Skip to content

Commit

Permalink
Fix a bug in KAZE/kaze_features.cpp to get the correct orientation of…
Browse files Browse the repository at this point in the history
… keypoints

Show keypoints' size and orientation in sample code KazeOpenCV.cpp
  • Loading branch information
yuhuazou committed Mar 23, 2013
1 parent 0b2ae9a commit a5121f4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
38 changes: 26 additions & 12 deletions KAZE/kaze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ int KAZE::Create_Nonlinear_Scale_Space(const cv::Mat &img)
int64 start_t1 = cv::getTickCount();

// Copy the original image to the first level of the evolution
if( verbosity == true )
{
std::cout << "-> Perform the Gaussian smoothing." << std::endl;
}

img.copyTo(evolution[0].Lt);
Gaussian_2D_Convolution(evolution[0].Lt,evolution[0].Lt,0,0,soffset);
Gaussian_2D_Convolution(evolution[0].Lt,evolution[0].Lsmooth,0,0,sderivatives);
Expand Down Expand Up @@ -299,10 +304,6 @@ void KAZE::Compute_Multiscale_Derivatives(void)

int64 t2 = cv::getTickCount();
tmderivatives = 1000.0 * (t2-t1) / cv::getTickFrequency();
if( verbosity == true )
{
std::cout << "--> Computed multiscale derivatives. Execution time (ms): " << tmderivatives << std::endl;
}

}

Expand All @@ -328,7 +329,7 @@ void KAZE::Compute_Detector_Response(void)
// Determinant of the Hessian
if( verbosity == true )
{
std::cout << "--> Computing detector response. Evolution time: " << evolution[i].etime << std::endl;
std::cout << "--> Computing Hessian determinant. Evolution time: " << evolution[i].etime << std::endl;
}

for( int ix = 0; ix < img_height; ix++ )
Expand Down Expand Up @@ -406,6 +407,8 @@ void KAZE::Feature_Detection(std::vector<Ipoint> &kpts)
*/
void KAZE::Determinant_Hessian_Parallel(std::vector<Ipoint> &kpts)
{
int64 t1 = cv::getTickCount();

unsigned int level = 0;
float dist = 0.0, smax = 3.0;
int npoints = 0, id_repeated = 0;
Expand Down Expand Up @@ -436,7 +439,7 @@ void KAZE::Determinant_Hessian_Parallel(std::vector<Ipoint> &kpts)
{
if( verbosity == true )
{
std::cout << "--> Computing Feature Detection. Evolution time: " << evolution[i].etime << std::endl;
std::cout << "--> Finding scale space extrema. Evolution time: " << evolution[i].etime << std::endl;
}

// Create the thread for finding extremum at i scale level
Expand All @@ -449,6 +452,11 @@ void KAZE::Determinant_Hessian_Parallel(std::vector<Ipoint> &kpts)
//mthreads.join_all();

// Now fill the vector of keypoints!!!
if( verbosity == true )
{
std::cout << "--> Fill the vector of keypoints. " << std::endl;
}

for( unsigned int i = 0; i < kpts_par.size(); i++ )
{
for( unsigned int j = 0; j < kpts_par[i].size(); j++ )
Expand All @@ -458,7 +466,7 @@ void KAZE::Determinant_Hessian_Parallel(std::vector<Ipoint> &kpts)
is_repeated = false;
is_out = false;

// Check in case we have the same point as maxima in previous evolution levels
// Check in case we have the same point as maxima in previous evolution levels (ONLY work when kpts is not empty)
for( unsigned int ik = 0; ik < kpts.size(); ik++ )
{
if( kpts[ik].level == level || kpts[ik].level == level+1 || kpts[ik].level == level-1 )
Expand Down Expand Up @@ -510,6 +518,15 @@ void KAZE::Determinant_Hessian_Parallel(std::vector<Ipoint> &kpts)
}
}
}

int64 t2 = cv::getTickCount();
double thessian = 1000.0 * (t2-t1) / cv::getTickFrequency();

if( verbosity == true )
{
std::cout << "-> Computed Hessian determinant. Execution time (ms):" << thessian << std::endl;
}

}

//*************************************************************************************
Expand Down Expand Up @@ -593,10 +610,6 @@ void KAZE::Find_Extremum_Threading(int level)
*/
void KAZE::Do_Subpixel_Refinement(std::vector<Ipoint> &keypts)
{
if( verbosity == true )
{
std::cout << "-> Subpixel refinement. " << std::endl;
}

float Dx = 0.0, Dy = 0.0, Ds = 0.0, dsc = 0.0;
float Dxx = 0.0, Dyy = 0.0, Dss = 0.0, Dxy = 0.0, Dxs = 0.0, Dys = 0.0;
Expand Down Expand Up @@ -665,7 +678,8 @@ void KAZE::Do_Subpixel_Refinement(std::vector<Ipoint> &keypts)
cv::solve(A,b,dst,cv::DECOMP_LU);

if( fabs(*(dst.ptr<float>(0))) <= 1.0
&& fabs(*(dst.ptr<float>(1))) <= 1.0 && fabs(*(dst.ptr<float>(2))) <= 1.0 )
&& fabs(*(dst.ptr<float>(1))) <= 1.0
&& fabs(*(dst.ptr<float>(2))) <= 1.0 )
{
keypts[i].xf += *(dst.ptr<float>(0));
keypts[i].yf += *(dst.ptr<float>(1));
Expand Down
17 changes: 10 additions & 7 deletions KAZE/kaze_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ namespace cv
{
runByPixelsMask(kazePoints, _mask.getMat());
}

_keypoints.resize(kazePoints.size());
for (size_t i = 0; i < kazePoints.size(); i++)
{
convertPoint(kazePoints[i], _keypoints[i]);
}

}
else
{
Expand All @@ -195,6 +188,16 @@ namespace cv
{
std::copy(kazePoints[i].descriptor.begin(), kazePoints[i].descriptor.end(), (float*)descriptors.row(i).data);
}
}

// Transfer from KAZE::Ipoint to cv::KeyPoint
if (do_keypoints)
{
_keypoints.resize(kazePoints.size());
for (size_t i = 0; i < kazePoints.size(); i++)
{
convertPoint(kazePoints[i], _keypoints[i]);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion KazeOpenCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main(int argc, char** argv[])

toptions opt;
opt.extended = true; // 1 - 128-bit vector, 0 - 64-bit vector, default: 0
opt.verbosity = false; // 1 - show detail information while caculating KAZE, 0 - unshow, default: 0
opt.verbosity = true; // 1 - show detail information while caculating KAZE, 0 - unshow, default: 0

KAZE detector_1(opt);
KAZE detector_2(opt);
Expand Down Expand Up @@ -96,6 +96,11 @@ int main(int argc, char** argv[])
}
}

//-- Draw Keypoints
Mat img_1k, img_2k;
drawKeypoints(img_1, keypoints_1, img_1k, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(img_2, keypoints_2, img_2k, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

//-- Draw inliers
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
Expand Down Expand Up @@ -128,7 +133,11 @@ int main(int argc, char** argv[])

//-- Show detected matches
cout << "-- Show detected matches." << endl;
namedWindow("Image 1",CV_WINDOW_NORMAL);
namedWindow("Image 2",CV_WINDOW_NORMAL);
namedWindow("Good Matches",CV_WINDOW_NORMAL);
imshow( "Image 1", img_1k );
imshow( "Image 2", img_2k );
imshow( "Good Matches", img_matches );
waitKey(0);
destroyAllWindows();
Expand Down

0 comments on commit a5121f4

Please sign in to comment.