const FLOAT_DMEM * cSmileUtilWindowedMagnitudeSpectrum::getMagnitudes( const FLOAT_DMEM *in, long Nin, bool allowWinSmaller = false) { copyInputAndZeropad(in, Nin, allowWinSmaller); doFFT(); computeMagnitudes(); // TODO: convert fftWork to right pointer type upon return!!!! // This is a temp hack to make the compiler happy, but it breaks the compontnt!! return (FLOAT_DMEM*)fftWork_; }
cv::Point EyeTracker::computePupilLocation(cv::Mat eye) { cv::Mat x_gradient = computeMaxGradient(eye); cv::Mat y_gradient = computeMaxGradient(eye.t()).t(); cv::Mat magnitude = computeMagnitudes(x_gradient, y_gradient); double gradient_threshold = computeDynamicThreshold(magnitude, 50.0); resizeAndRender(magnitude, "sample_eye_gradient_mag"); DEBUG("Gradient threshold: " << gradient_threshold); for (int y = 0; y < eye.rows; ++y) { double* x_row = x_gradient.ptr<double>(y); double* y_row = y_gradient.ptr<double>(y); const double* mag_row = magnitude.ptr<double>(y); for (int x = 0; x < eye.cols; ++x) { double gX = x_row[x]; double gY = y_row[x]; double m = mag_row[x]; if (m > gradient_threshold) { x_row[x] = gX / m; y_row[x] = gY / m; } else { x_row[x] = 0; y_row[x] = 0; } } } resizeAndRender(x_gradient, "sample_eye_gradient_x"); resizeAndRender(y_gradient, "sample_eye_gradient_y"); cv::Mat weight; cv::GaussianBlur(eye, weight, cv::Size(5, 5), 0, 0); for (int y = 0; y < weight.rows; ++y) { unsigned char* row = weight.ptr<unsigned char>(y); for (int x = 0; x < weight.cols; ++x) { row[x] = (255 - row[x]); } } resizeAndRender(weight, "sample_eye_weight"); cv::Mat out_sum = cv::Mat::zeros(eye.rows, eye.cols, CV_64F); for (int y = 0; y < weight.rows; ++y) { const double* Xr = x_gradient.ptr<double>(y); const double* Yr = y_gradient.ptr<double>(y); for (int x = 0; x < weight.cols; ++x) { double gX = Xr[x]; double gY = Yr[x]; if (gX == 0.0 && gY == 0.0) { continue; } test_center(x, y, weight, gX, gY, out_sum); } } double gradients_num = weight.rows * weight.cols; cv::Mat out; out_sum.convertTo(out, CV_32F, 1.0 / gradients_num); cv::Point max_point; double max_value; cv::minMaxLoc(out, NULL, &max_value, NULL, &max_point); cv::Mat flood_clone; double flood_thresh = max_value * 0.97; cv::threshold(out, flood_clone, flood_thresh, 0.0f, cv::THRESH_TOZERO); cv::Mat mask = floodKillEdges(flood_clone); cv::minMaxLoc(out, NULL, &max_value, NULL, &max_point, mask); resizeAndRender(mask, "sample_eye_mask"); resizeAndRender(out, "sample_eye_possible_centers"); return max_point; }