From 4395bad911d3a73353af554cfe7358bb8001df15 Mon Sep 17 00:00:00 2001
From: Maria Dimashova <no@email>
Date: Thu, 5 Aug 2010 13:29:43 +0000
Subject: [PATCH] fixed linker errors on Win and some warnings

---
 .../include/opencv2/features2d/features2d.hpp |  4 +--
 modules/features2d/src/descriptors.cpp        | 15 +++++----
 modules/features2d/src/evaluation.cpp         | 28 ++++++++--------
 modules/features2d/src/keypoint.cpp           |  4 +--
 tests/cv/src/acalonder.cpp                    |  4 +--
 .../cv/src/adetectordescriptor_evaluation.cpp | 33 +++++++++++++++++--
 6 files changed, 59 insertions(+), 29 deletions(-)

diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp
index 88aa10566..a0ff4cc05 100644
--- a/modules/features2d/include/opencv2/features2d/features2d.hpp
+++ b/modules/features2d/include/opencv2/features2d/features2d.hpp
@@ -1505,7 +1505,7 @@ void CalonderDescriptorExtractor<T>::compute( const cv::Mat& image,
   int offset = patchSize / 2;
   for (size_t i = 0; i < keypoints.size(); ++i) {
     cv::Point2f pt = keypoints[i].pt;
-    IplImage ipl = image( Rect(pt.x - offset, pt.y - offset, patchSize, patchSize) );
+    IplImage ipl = image( Rect((int)(pt.x - offset), (int)(pt.y - offset), patchSize, patchSize) );
     classifier_.getSignature( &ipl, descriptors.ptr<T>(i));
   }
 }
@@ -1515,7 +1515,7 @@ void CalonderDescriptorExtractor<T>::read( const FileNode& )
 {}
 
 template<typename T>
-void CalonderDescriptorExtractor<T>::write( FileStorage&s ) const
+void CalonderDescriptorExtractor<T>::write( FileStorage& ) const
 {}
 
 CV_EXPORTS Ptr<DescriptorExtractor> createDescriptorExtractor( const string& descriptorExtractorType );
diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp
index b89d68bc0..a8bf2f717 100644
--- a/modules/features2d/src/descriptors.cpp
+++ b/modules/features2d/src/descriptors.cpp
@@ -79,11 +79,11 @@ Mat windowedMatchingMask( const vector<KeyPoint>& keypoints1, const vector<KeyPo
 
 static inline void _drawKeypoint( Mat& img, const KeyPoint& p, const Scalar& color, int flags )
 {
-    Point center( p.pt.x * draw_multiplier, p.pt.y * draw_multiplier );
+    Point center( cvRound(p.pt.x * draw_multiplier), cvRound(p.pt.y * draw_multiplier) );
 
     if( flags & DrawMatchesFlags::DRAW_RICH_KEYPOINTS )
     {
-        int radius = p.size/2 * draw_multiplier; // KeyPoint::size is a diameter
+        int radius = cvRound(p.size/2 * draw_multiplier); // KeyPoint::size is a diameter
 
         // draw the circles around keypoints with the keypoints size
         circle( img, center, radius, color, 1, CV_AA, draw_shift_bits );
@@ -91,8 +91,9 @@ static inline void _drawKeypoint( Mat& img, const KeyPoint& p, const Scalar& col
         // draw orientation of the keypoint, if it is applicable
         if( p.angle != -1 )
         {
-            float srcAngleRad = p.angle*CV_PI/180;
-            Point orient(cos(srcAngleRad)*radius, sin(srcAngleRad)*radius);
+            float srcAngleRad = p.angle*(float)CV_PI/180.f;
+            Point orient(cvRound(cos(srcAngleRad)*radius), 
+						 cvRound(sin(srcAngleRad)*radius));
             line( img, center, center+orient, color, 1, CV_AA, draw_shift_bits );
         }
 #if 0
@@ -175,7 +176,9 @@ static inline void _drawMatch( Mat& outImg, Mat& outImg1, Mat& outImg2 ,
             pt2 = kp2.pt,
             dpt2 = Point2f( std::min(pt2.x+outImg1.cols, float(outImg.cols-1)), pt2.y );
 
-    line( outImg, Point(pt1.x*draw_multiplier, pt1.y*draw_multiplier), Point(dpt2.x*draw_multiplier, dpt2.y*draw_multiplier),
+    line( outImg, 
+		  Point(cvRound(pt1.x*draw_multiplier), cvRound(pt1.y*draw_multiplier)),
+		  Point(cvRound(dpt2.x*draw_multiplier), cvRound(dpt2.y*draw_multiplier)),
           color, 1, CV_AA, draw_shift_bits );
 }
 
@@ -461,7 +464,7 @@ void BruteForceMatcher<L2<float> >::matchImpl( const Mat& query, const Mat& mask
         {
             match.indexQuery = i;
             double queryNorm = norm( query.row(i) );
-            match.distance = sqrt( minVal + queryNorm*queryNorm );
+            match.distance = (float)sqrt( minVal + queryNorm*queryNorm );
             matches.push_back( match );
         }
     }
diff --git a/modules/features2d/src/evaluation.cpp b/modules/features2d/src/evaluation.cpp
index d30ab6140..992c99e02 100644
--- a/modules/features2d/src/evaluation.cpp
+++ b/modules/features2d/src/evaluation.cpp
@@ -46,18 +46,18 @@
 using namespace cv;
 using namespace std;
 
-inline Point2f applyHomography( const Mat_<double>& H, const Point2f& pt )
+static inline Point2f applyHomography( const Mat_<double>& H, const Point2f& pt )
 {
     double z = H(2,0)*pt.x + H(2,1)*pt.y + H(2,2);
     if( z )
     {
         double w = 1./z;
-        return Point2f( (H(0,0)*pt.x + H(0,1)*pt.y + H(0,2))*w, (H(1,0)*pt.x + H(1,1)*pt.y + H(1,2))*w );
+        return Point2f( (float)((H(0,0)*pt.x + H(0,1)*pt.y + H(0,2))*w), (float)((H(1,0)*pt.x + H(1,1)*pt.y + H(1,2))*w) );
     }
-    return Point2f( numeric_limits<double>::max(), numeric_limits<double>::max() );
+    return Point2f( numeric_limits<float>::max(), numeric_limits<float>::max() );
 }
 
-inline void linearizeHomographyAt( const Mat_<double>& H, const Point2f& pt, Mat_<double>& A )
+static inline void linearizeHomographyAt( const Mat_<double>& H, const Point2f& pt, Mat_<double>& A )
 {
     A.create(2,2);
     double p1 = H(0,0)*pt.x + H(0,1)*pt.y + H(0,2),
@@ -110,12 +110,12 @@ EllipticKeyPoint::EllipticKeyPoint( const Point2f& _center, const Scalar& _ellip
     Mat_<double> M = getSecondMomentsMatrix(_ellipse), eval;
     eigen( M, eval );
     assert( eval.rows == 2 && eval.cols == 1 );
-    axes.width = 1.f / sqrt(eval(0,0));
-    axes.height = 1.f / sqrt(eval(1,0));
+    axes.width = 1.f / (float)sqrt(eval(0,0));
+    axes.height = 1.f / (float)sqrt(eval(1,0));
 
-    float ac_b2 = ellipse[0]*ellipse[2] - ellipse[1]*ellipse[1];
-    boundingBox.width = sqrt(ellipse[2]/ac_b2);
-    boundingBox.height = sqrt(ellipse[0]/ac_b2);
+    double ac_b2 = ellipse[0]*ellipse[2] - ellipse[1]*ellipse[1];
+    boundingBox.width = (float)sqrt(ellipse[2]/ac_b2);
+    boundingBox.height = (float)sqrt(ellipse[0]/ac_b2);
 }
 
 Mat_<double> EllipticKeyPoint::getSecondMomentsMatrix( const Scalar& _ellipse )
@@ -223,7 +223,7 @@ static void overlap( const vector<EllipticKeyPoint>& keypoints1, const vector<El
             fac=3;
 
         maxDist = maxDist*4;
-        fac = 1.0/(fac*fac);
+        fac = 1.f/(fac*fac);
 
         EllipticKeyPoint keypoint1a = EllipticKeyPoint( kp1.center, Scalar(fac*kp1.ellipse[0], fac*kp1.ellipse[1], fac*kp1.ellipse[2]) );
 
@@ -246,8 +246,8 @@ static void overlap( const vector<EllipticKeyPoint>& keypoints1, const vector<El
                 float miny = floor((-keypoint1a.boundingBox.height < (diff.y-keypoint2a.boundingBox.height)) ?
                                     -keypoint1a.boundingBox.height : (diff.y-keypoint2a.boundingBox.height));
                 float mina = (maxx-minx) < (maxy-miny) ? (maxx-minx) : (maxy-miny) ;
-                float dr = mina/50.0;
-                float bua = 0, bna = 0;
+                float dr = mina/50.f;
+                float bua = 0.f, bna = 0.f;
                 //compute the area
                 for( float rx1 = minx; rx1 <= maxx; rx1+=dr )
                 {
@@ -256,8 +256,8 @@ static void overlap( const vector<EllipticKeyPoint>& keypoints1, const vector<El
                     {
                         float ry2=ry1-diff.y;
                         //compute the distance from the ellipse center
-                        float e1 = keypoint1a.ellipse[0]*rx1*rx1+2*keypoint1a.ellipse[1]*rx1*ry1+keypoint1a.ellipse[2]*ry1*ry1;
-                        float e2 = keypoint2a.ellipse[0]*rx2*rx2+2*keypoint2a.ellipse[1]*rx2*ry2+keypoint2a.ellipse[2]*ry2*ry2;
+                        float e1 = (float)(keypoint1a.ellipse[0]*rx1*rx1+2*keypoint1a.ellipse[1]*rx1*ry1+keypoint1a.ellipse[2]*ry1*ry1);
+                        float e2 = (float)(keypoint2a.ellipse[0]*rx2*rx2+2*keypoint2a.ellipse[1]*rx2*ry2+keypoint2a.ellipse[2]*ry2*ry2);
                         //compute the area
                         if( e1<1 && e2<1 ) bna++;
                         if( e1<1 || e2<1 ) bua++;
diff --git a/modules/features2d/src/keypoint.cpp b/modules/features2d/src/keypoint.cpp
index 6df98cb15..c5a841e25 100644
--- a/modules/features2d/src/keypoint.cpp
+++ b/modules/features2d/src/keypoint.cpp
@@ -118,7 +118,7 @@ float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 )
 
     Point2f p1 = kp1.pt;
     Point2f p2 = kp2.pt;
-    float c = norm( p1 - p2 );
+    float c = (float)norm( p1 - p2 );
 
     float ovrl = 0.f;
 
@@ -143,7 +143,7 @@ float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 )
         float triangleAreaB = b_2 * sinAlpha * cosAlpha;
 
         float intersectionArea = segmentAreaA + segmentAreaB - triangleAreaA - triangleAreaB;
-        float unionArea = (a_2 + b_2) * CV_PI - intersectionArea;
+        float unionArea = (a_2 + b_2) * (float)CV_PI - intersectionArea;
 
         ovrl = intersectionArea / unionArea;
     }
diff --git a/tests/cv/src/acalonder.cpp b/tests/cv/src/acalonder.cpp
index 4bf85f78d..aa87a1f02 100644
--- a/tests/cv/src/acalonder.cpp
+++ b/tests/cv/src/acalonder.cpp
@@ -125,7 +125,7 @@ void CV_CalonderTest::run(int)
     CalonderDescriptorExtractor<float> fde(dir + "/classifier.rtc");
 
     Mat fdescriptors;
-    double t = getTickCount();
+    double t = (double)getTickCount();
     fde.compute(img, keypoints, fdescriptors);
     t = getTickCount() - t;
     ts->printf(CvTS::LOG, "\nAverage time of computiting float descriptor = %g ms\n", t/((double)cvGetTickFrequency()*1000.)/fdescriptors.rows );
@@ -143,7 +143,7 @@ void CV_CalonderTest::run(int)
 
     CalonderDescriptorExtractor<uchar> cde(dir + "/classifier.rtc");
     Mat cdescriptors;
-    t = getTickCount();
+    t = (double)getTickCount();
     cde.compute(img, keypoints, cdescriptors);
     t = getTickCount() - t;
     ts->printf(CvTS::LOG, "Average time of computiting uchar descriptor = %g ms\n", t/((double)cvGetTickFrequency()*1000.)/cdescriptors.rows );
diff --git a/tests/cv/src/adetectordescriptor_evaluation.cpp b/tests/cv/src/adetectordescriptor_evaluation.cpp
index f00388db0..cb7d4d99b 100644
--- a/tests/cv/src/adetectordescriptor_evaluation.cpp
+++ b/tests/cv/src/adetectordescriptor_evaluation.cpp
@@ -52,8 +52,35 @@ using namespace cv;
 *           Functions to evaluate affine covariant detectors and descriptors.            *
 \****************************************************************************************/
 
-Point2f applyHomography( const Mat_<double>& H, const Point2f& pt );
-void linearizeHomographyAt( const Mat_<double>& H, const Point2f& pt, Mat_<double>& A );
+static inline Point2f applyHomography( const Mat_<double>& H, const Point2f& pt )
+{
+    double z = H(2,0)*pt.x + H(2,1)*pt.y + H(2,2);
+    if( z )
+    {
+        double w = 1./z;
+        return Point2f( (H(0,0)*pt.x + H(0,1)*pt.y + H(0,2))*w, (H(1,0)*pt.x + H(1,1)*pt.y + H(1,2))*w );
+    }
+    return Point2f( numeric_limits<float>::max(), numeric_limits<float>::max() );
+}
+
+static inline void linearizeHomographyAt( const Mat_<double>& H, const Point2f& pt, Mat_<double>& A )
+{
+    A.create(2,2);
+    double p1 = H(0,0)*pt.x + H(0,1)*pt.y + H(0,2),
+           p2 = H(1,0)*pt.x + H(1,1)*pt.y + H(1,2),
+           p3 = H(2,0)*pt.x + H(2,1)*pt.y + H(2,2),
+           p3_2 = p3*p3;
+    if( p3 )
+    {
+        A(0,0) = H(0,0)/p3 - p1*H(2,0)/p3_2; // fxdx
+        A(0,1) = H(0,1)/p3 - p1*H(2,1)/p3_2; // fxdy
+
+        A(1,0) = H(1,0)/p3 - p2*H(2,0)/p3_2; // fydx
+        A(1,1) = H(1,1)/p3 - p2*H(2,1)/p3_2; // fydx
+    }
+    else
+        A.setTo(Scalar::all(numeric_limits<double>::max()));
+}
 
 void calcKeyPointProjections( const vector<KeyPoint>& src, const Mat_<double>& H, vector<KeyPoint>& dst )
 {
@@ -1066,7 +1093,7 @@ int DescriptorQualityTest::processResults( int datasetIdx, int caseIdx )
     Quality valid = validQuality[datasetIdx][caseIdx], calc = calcQuality[datasetIdx][caseIdx];
 
     bool isBadAccuracy;
-    const float rltvEps = 0.001;
+    const float rltvEps = 0.001f;
     ts->printf(CvTS::LOG, "%s: calc=%f, valid=%f", RECALL.c_str(), calc.recall, valid.recall );
     isBadAccuracy = valid.recall - calc.recall > rltvEps;
     testLog( ts, isBadAccuracy );