Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I find a distance between the contour pixels of an irregular image and the center of mass of that image?

I have a binarized image by Otsu Threshold. I'm new in C++ and Opencv

How do I find a distance between the contour pixels of an irregular image and the center of mass of that image?

I have a binarized image by Otsu Threshold. I'm new in C++ and OpencvOpencv I try this, but don't work

  #include <iostream>
#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/highgui/highgui.hpp" #include <stdlib.h> #include <stdio.h>

using namespace cv; using namespace std;

int main(int argc, char** argv) { cv::Mat img = cv::imread("melanoma_abertura_cortada_NAOINVERT.png");

if (img.empty())
{
    std::cout << "!!! imread() failed to open target image" << std::endl;
    return -1;
}
cv::Mat img_canny;

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

Canny(img, img_canny, 80, 20);


findContours(img_canny, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, Point(0, 0));

// Get the moments vector<moments> mu(contours.size()); for (int i = 0; i < contours.size(); i++) { mu[i] = moments(contours[i], false); }

///  Get the mass centers:
vector<Point2f> mc(contours.size());
for (int i = 0; i < contours.size(); i++)
{
    mc[i] = Point2d(mu[i].m10 / mu[i].m00, mu[i].m01 / mu[i].m00);


}

for (size_t cC = 0; cC < contours.size(); ++cC)  
    for (size_t cP = 0; cP < contours[cC].size(); cP++)
    {
        Point currentContourPixel = contours[cC][cP];
    }

    Mat  magnitudee;

    magnitude(mc, contours.size(), magnitudee);

cv::waitKey(0);
return 0;

}

How do I find a distance between the contour pixels of an irregular image and the center of mass of that image?

I have a binarized image by Otsu Threshold. I'm new in C++ and Opencv Opencv. I try this, but don't workwork.

  #include <iostream>
#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/highgui/highgui.hpp" #include <stdlib.h> #include <stdio.h>

using namespace cv; using namespace std;

int main(int argc, char** argv) { cv::Mat img = cv::imread("melanoma_abertura_cortada_NAOINVERT.png");

if (img.empty())
{
    std::cout << "!!! imread() failed to open target image" << std::endl;
    return -1;
}
cv::Mat img_canny;

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

Canny(img, img_canny, 80, 20);


findContours(img_canny, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, Point(0, 0));

// Get the moments vector<moments> mu(contours.size()); for (int i = 0; i < contours.size(); i++) { mu[i] = moments(contours[i], false); }

///  Get the mass centers:
vector<Point2f> mc(contours.size());
for (int i = 0; i < contours.size(); i++)
{
    mc[i] = Point2d(mu[i].m10 / mu[i].m00, mu[i].m01 / mu[i].m00);


}

for (size_t cC = 0; cC < contours.size(); ++cC)  
    for (size_t cP = 0; cP < contours[cC].size(); cP++)
    {
        Point currentContourPixel = contours[cC][cP];
    }

    Mat  magnitudee;

    magnitude(mc, contours.size(), magnitudee);

cv::waitKey(0);
return 0;

}

How do I find a distance between the contour pixels of an irregular image and the center of mass of that image?

I have a binarized image by Otsu Threshold. I'm new in C++ and Opencv. I try this, but don't work.

  #include <iostream>
 #include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/highgui/highgui.hpp" #include <stdlib.h> #include <stdio.h>

<stdio.h> using namespace cv; using namespace std;

std; int main(int argc, char** argv) { cv::Mat img = cv::imread("melanoma_abertura_cortada_NAOINVERT.png");

cv::imread("melanoma_abertura_cortada_NAOINVERT.png");

    if (img.empty())
 {
     std::cout << "!!! imread() failed to open target image" << std::endl;
     return -1;
 }
 cv::Mat img_canny;

 vector<vector<Point> > contours;
 vector<Vec4i> hierarchy;

 Canny(img, img_canny, 80, 20);


 findContours(img_canny, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, Point(0, 0));

// Get the moments vector<moments> vector<Moments> mu(contours.size()); for (int i = 0; i < contours.size(); i++) { mu[i] = moments(contours[i], false); }

}

    ///  Get the mass centers:
 vector<Point2f> mc(contours.size());
 for (int i = 0; i < contours.size(); i++)
 {
     mc[i] = Point2d(mu[i].m10 / mu[i].m00, mu[i].m01 / mu[i].m00);


 }

 for (size_t cC = 0; cC < contours.size(); ++cC)  
     for (size_t cP = 0; cP < contours[cC].size(); cP++)
     {
         Point currentContourPixel = contours[cC][cP];
     }

     Mat  magnitudee;

     magnitude(mc, contours.size(), magnitudee);

 cv::waitKey(0);
 return 0;
}

}