I found a implimentation of chamfer Matching here, which seems to have an error in this line:
Point& new_point = Point(model_column,model_row);
The error says the following:
"cannot bind non-const lvalue reference of type ‘cv::Point& {aka cv::Point_<int>&}’ to an rvalue of type ‘cv::Point {aka cv::Point_<int>}’ Point& new_point = Point(model_column,model_row);
If I change this line to
Point new_point = Point(model_column,model_row);
The program runs, but the results are not as i expected.
Can someone give me a hint, what the problem is?
Full code:
void ChamferMatching( Mat& chamfer_image, Mat& model, Mat& matching_image )
{
// Extract the model points (as they are sparse).
vector<Point> model_points;
int image_channels = model.channels();
for (int model_row=0; (model_row < model.rows); model_row++)
{
uchar *curr_point = model.ptr<uchar>(model_row);
for (int model_column=0; (model_column < model.cols); model_column++)
{
if (*curr_point > 0)
{
Point& new_point = Point(model_column,model_row);
model_points.push_back(new_point);
}
curr_point += image_channels;
}
}
int num_model_points = model_points.size();
image_channels = chamfer_image.channels();
// Try the model in every possible position
matching_image = Mat(chamfer_image.rows-model.rows+1, chamfer_image.cols-model.cols+1, CV_32FC1);
for (int search_row=0; (search_row <= chamfer_image.rows-model.rows); search_row++)
{
float *output_point = matching_image.ptr<float>(search_row);
for (int search_column=0; (search_column <= chamfer_image.cols-model.cols); search_column++)
{
float matching_score = 0.0;
for (int point_count=0; (point_count < num_model_points); point_count++)
matching_score += (float) *(chamfer_image.ptr<float>(model_points[point_count].y+search_row) + search_column + model_points[point_count].x*image_channels);
*output_point = matching_score;
output_point++;
}
}
}
for chamfer image i do:
Canny( queryImage, edge_image, 100, 200, 3);
threshold( edge_image, edge_image, 127, 255, THRESH_BINARY_INV );
distanceTransform( edge_image, chamfer_image, CV_DIST_L2, 3);
for the model image a simple canny-routine is used:
Canny( templateImage, model_edge, 100, 200, 3);
Thank you for your help!