Ask Your Question
0

std::pow Problem

asked 2015-09-01 10:20:49 -0600

sarmad gravatar image

Hi

In this code I'm trying to detect eye pupil but there is an error I would be grateful if you help me

Error : 1>source.cpp(36): error C2668: 'std::pow' : ambiguous call to overloaded function

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<cmath>;

int main(int argc, char** argv)
{
// Load image
cv::Mat src = cv::imread("1.jpg");
if (src.empty())
    return -1;

// Invert the source image and convert to grayscale
cv::Mat gray;
cv::cvtColor(~src, gray, CV_BGR2GRAY);

// Convert to binary image by thresholding it
cv::threshold(gray, gray, 220, 255, cv::THRESH_BINARY);

// Find all contours
std::vector<std::vector<cv::Point> > contours;
cv::findContours(gray.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

// Fill holes in each contour
cv::drawContours(gray, contours, -1, CV_RGB(255,255,255), -1);

for (int i = 0; i < contours.size(); i++)
{
    double area = cv::contourArea(contours[i]);
    cv::Rect rect = cv::boundingRect(contours[i]);
    int radius = rect.width/2;

    // If contour is big enough and has round shape
    // Then it is the pupil
    if (area >= 30 && 
        std::abs(1 - ((double)rect.width / (double)rect.height)) <= 0.2 &&
            std::abs(1 - (area / (CV_PI * std::pow(radius, 2)))) <= 0.2)    
    {
        cv::circle(src, cv::Point(rect.x + radius, rect.y + radius), radius, CV_RGB(255,0,0), 2);
    }
}

cv::imshow("image", src);
cv::waitKey(0);

return 0;

}

edit retag flag offensive close merge delete

Comments

(older) ms compilers are extremly picky about the type of math functions, try :

std::pow(radius, 2.0)

if it still does not help, go one further:

std::pow(double(radius), 2.0)
berak gravatar imageberak ( 2015-09-01 10:30:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-09-01 18:47:33 -0600

darenw gravatar image

If all you're doing is just squaring a variable, there's no need to haul in a fancy math function. I'd just replace std::pow(radius, 2) with radius*radius. This is done all the time in real-world code. The compiler will handle this faster, not having to look up "pow()". You may even be able to ditch use of <cmath> if there's no other math functions or constants in use, reducing dependencies

edit flag offensive delete link more

Comments

voice of reason .. ;)

berak gravatar imageberak ( 2015-09-01 23:57:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-01 10:20:49 -0600

Seen: 1,004 times

Last updated: Sep 01 '15