Skip to content
Snippets Groups Projects
Commit b54e3aee authored by Sebastian Gomez-Gonzalez's avatar Sebastian Gomez-Gonzalez
Browse files

The logistic regression validator (not tested)

parent 8516ca06
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,19 @@ namespace ball_tracking { ...@@ -22,6 +22,19 @@ namespace ball_tracking {
*/ */
cv::Mat map_channel_quad(cv::InputArray src, cv::InputArray mean, cv::InputArray S); cv::Mat map_channel_quad(cv::InputArray src, cv::InputArray mean, cv::InputArray S);
/**
* @brief Applies a pixel-wise logistic regression with quadratic features to the source
* image and returns a single-channel image with the log-probabilities
*
* @param[in] src The source image
* @param[in] bkg A background image (Without the ball)
* @param[in] weights Vector of weights of logistic regression
*
* @returns a new image where every pixel corresponds to the log-probability of the
* pixel being a ball according to the trained classifier
*/
cv::Mat quadf_log_reg(cv::InputArray src, cv::InputArray bkg, cv::InputArray weights);
/** /**
* @brief Produces a single channel image highlighting the possible position of the ball * @brief Produces a single channel image highlighting the possible position of the ball
......
...@@ -34,4 +34,31 @@ namespace ball_tracking { ...@@ -34,4 +34,31 @@ namespace ball_tracking {
return ans; return ans;
} }
cv::Mat quadf_log_reg(cv::InputArray _src, cv::InputArray _bkg, cv::InputArray _weights) {
Mat src = _src.getMat(), bkg = _bkg.getMat(), tmp_weight = _weights.getMat();
const unsigned int channels = src.channels();
CV_Assert(channels == 3);
CV_Assert(src.rows == bkg.rows && src.cols == bkg.cols);
double w[28];
copy(tmp_weight.begin<double>(), tmp_weight.end<double>(), w);
Mat ans(src.rows, src.cols, CV_64FC1);
MatIterator_<Vec3b> it=src.begin<Vec3b>(), end=src.end<Vec3b>();
MatIterator_<Vec3b> it_bkg=bkg.begin<Vec3b>();
MatIterator_<double> it_ans = ans.begin<double>();
for (; it != end; it++, it_ans++, it_bkg++) {
double sum = 0.0;
double lfeat[7] = {(*it)[0]/255.0, (*it)[1]/255.0, (*it)[2]/255.0,
(*it_bkg)[0]/255.0, (*it_bkg)[1]/255.0, (*it_bkg)[2]/255.0, 1.0};
double* wptr = w;
for (unsigned int i=0; i<7; i++) {
for (unsigned int j=i; j<channels; j++, wptr++) {
sum += (*wptr) * lfeat[i] * lfeat[j];
}
}
*it_ans = sum;
}
return ans;
}
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment