Commit dc8110e9 authored by Michele Porta's avatar Michele Porta

–fourth commit

parent c25b75d3
......@@ -50,7 +50,7 @@ void imageIntoFloat(const cv::Mat& input, cv::Mat& output){
output = cv::Mat (input.rows, input.cols, CV_32FC1);
float* output_float = reinterpret_cast<float * >(output.data);
for(int y=0; y<input.rows; y++){
for(int y=0; y< input.rows; y++){
for(int x=0; x< input.cols; x++){
output_float[(x+y*input.cols)] = float(input.data[(x+y*input.cols)])/float(255);
}
......@@ -60,6 +60,7 @@ void imageIntoFloat(const cv::Mat& input, cv::Mat& output){
void rescale (const cv:: Mat& input, cv:: Mat& output_scale) {
output_scale = cv::Mat (input.rows, input.cols, CV_32FC1);
float max=0;
float min=0;
......@@ -125,6 +126,7 @@ void non_maximu_suppression(cv:: Mat image, std::vector<cv::KeyPoint> & keypoint
}
}
}
for (int y=0; y< image.cols; y++) {
for (int x=0; x< image.rows; x++) {
if (image.at<float> (x,y) > 0) {
......@@ -138,6 +140,7 @@ void harrisCornerDetector(const cv::Mat image, std::vector<cv::KeyPoint> & keypo
{
Mat dst1,dst2, product, square_vert, square_oriz,kernel_oriz, kernel_vert, gaussian,square_oriz_gaus, square_vert_gaus, product_gaus, formula, formula_res;
Point anchor;
double delta;
int ddepth;
int kernel_size;
......@@ -161,7 +164,8 @@ void harrisCornerDetector(const cv::Mat image, std::vector<cv::KeyPoint> & keypo
GaussianBlur( product, product_gaus, Size( 5, 5 ), 0, 0 );
formula = square_oriz_gaus.mul(square_vert_gaus) - (product_gaus.mul(product_gaus)) - alpha * ((square_oriz_gaus + square_vert_gaus).mul(square_oriz_gaus + square_vert_gaus));
rescale (formula, formula_res);
rescale (formula, formula_res); //porto tutto nel range (0:1)
non_maximu_suppression(formula_res, keypoints0, harrisTh);
......@@ -179,6 +183,7 @@ void harrisCornerDetector(const cv::Mat image, std::vector<cv::KeyPoint> & keypo
void findHomographyRansac(const std::vector<cv::Point2f> & points1, const std::vector<cv::Point2f> & points0, int N, float epsilon, int sample_size, cv::Mat & H, std::vector<cv::Point2f> & inliers_best0, std::vector<cv::Point2f> & inliers_best1)
{
srand(time(NULL));
cv:: Point2f p1;
cv:: Point2f p0;
......@@ -205,7 +210,7 @@ void findHomographyRansac(const std::vector<cv::Point2f> & points1, const std::v
points0_ransac.push_back(p0);
}
H_test= cv::findHomography(cv::Mat (points1_ransac), cv::Mat (points0_ransac), 0);
H_test= cv::findHomography(cv::Mat (points1_ransac), cv::Mat (points0_ransac), 0); //Calcolo omografia con i 4 keypoints associati e presi casualmente
for (unsigned int u=0; u< points1.size();u++) {
......@@ -215,9 +220,8 @@ void findHomographyRansac(const std::vector<cv::Point2f> & points1, const std::v
product = H_test*p1_omog;
cv::Point2d product_point(product.at<double> (0,0)/product.at<double>(2,0), product.at<double> (1,0)/product.at<double>(2,0));
res= sqrt(pow(points0[u].x - product_point.x,2)+ pow(points0[u].y - product_point.y,2));
res= sqrt(pow(points0[u].x - product_point.x,2)+ pow(points0[u].y - product_point.y,2)); //calcolo della distanza euclidea
if (res < epsilon) {
inliers_best1_test.push_back(points1[u]);
......@@ -249,7 +253,7 @@ void findHomographyRansac(const std::vector<cv::Point2f> & points1, const std::v
points0_ransac.clear();
}
H= cv::findHomography(cv::Mat (inliers_best1), cv::Mat (inliers_best0), 0);
H= cv::findHomography(cv::Mat (inliers_best1), cv::Mat (inliers_best0), 0); //calcolo omografia con il gruppo di inliers più numeroso trovato
}
int main(int argc, char **argv)
......@@ -314,8 +318,7 @@ int main(int argc, char **argv)
/// HARRIS CORNER
//
float alpha = 0.04;
float harrisTh1=0.2;
float harrisTh2=0.25; //da impostare in base alla propria implementazione
float harrisTh=0.22; //impostato in modo tale da avere un buon numero di punti
std::vector<cv::KeyPoint> keypoints0, keypoints1;
cv:Mat temp1, temp2;
......@@ -323,8 +326,8 @@ int main(int argc, char **argv)
imageIntoFloat(image_v[0], temp1);
imageIntoFloat(image_v[1], temp2);
harrisCornerDetector(temp1, keypoints0, alpha, harrisTh1);
harrisCornerDetector(temp2, keypoints1, alpha, harrisTh2);
harrisCornerDetector(temp1, keypoints0, alpha, harrisTh);
harrisCornerDetector(temp2, keypoints1, alpha, harrisTh);
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment