Ask Your Question

eld1e6o's profile - activity

2018-12-20 21:28:06 -0600 commented question Correct way to make library with priv / public header and pass cv::Mat

I have created a branch (badsolution), that is working but it is only conceptual. I reserve static memory inside public

2018-12-20 21:27:16 -0600 commented question Correct way to make library with priv / public header and pass cv::Mat

I have created a branch (badsolution), that is working but it is only conceptual. I reserve static memory inside the pub

2018-12-20 21:15:06 -0600 commented question Correct way to make library with priv / public header and pass cv::Mat

@sturkmen, very thanks for your time and to test my code. I'm advancing and seing that I'm making some type of ODR (http

2018-12-20 21:08:27 -0600 commented question Correct way to make library with priv / public header and pass cv::Mat

@berak, thanks for your reply, my old post was an entire disaster and to maintain some level, I redo it. It is not neces

2018-12-20 13:11:24 -0600 commented question Problem to pass cv::Mat as argument trough library

@sturkmen @berak Thanks fo your comments, I have re wrotten my code and pushed to a public repo also, following your com

2018-12-20 13:09:54 -0600 edited question Correct way to make library with priv / public header and pass cv::Mat

Correct way to make priv / public header and pass cv::Mat Hello! I need to make a .so or .a library and different heade

2018-12-20 13:08:44 -0600 asked a question Correct way to make library with priv / public header and pass cv::Mat

Correct way to make priv / public header and pass cv::Mat Hello! I need to make a .so or .a library and different heade

2018-12-19 14:41:54 -0600 commented question Problem to pass cv::Mat as argument trough library

@sturkmen @berak Thanks for all, that's right, I made a lot of mistakes, will delete my post and make it again. Thanksfo

2018-12-19 13:33:21 -0600 asked a question Problem to pass cv::Mat as argument trough library

Problem to pass cv::Mat as argument trough library Hello! I need to make a library and pass a cv::Mat as argument of a

2017-12-08 19:42:20 -0600 edited question CMake cross compiler problem with pkg_check_modules for some packages

CMake cross compiler problem with pkg_check_modules for some packages Hello! Introduction I'm trying to cross compile

2017-12-08 13:49:46 -0600 edited question CMake cross compiler problem with pkg_check_modules for some packages

CMake cross compiler problem with pkg_check_modules for some packages Hello! Introduction I'm trying to cross compile

2017-12-08 13:49:46 -0600 received badge  Editor (source)
2017-12-08 13:31:46 -0600 asked a question CMake cross compiler problem with pkg_check_modules for some packages

CMake cross compiler problem with pkg_check_modules for some packages Hello! Introduction I'm trying to cross compile

2016-06-16 16:21:27 -0600 received badge  Scholar (source)
2016-06-16 15:47:13 -0600 received badge  Nice Question (source)
2016-06-16 14:46:26 -0600 commented question Error in mass center calculation through moments()

Very thanks! (I am sorry for my mistake)

2016-06-16 14:23:29 -0600 received badge  Student (source)
2016-06-16 14:20:32 -0600 asked a question Error in mass center calculation through moments()

I'm trying to calculate the mass center of images using OpenCV and I got errors, as you can see in the images (the mass center must not be to closest of any side in this cases). Also, I got mass centers that depends of the rotation and that's incorrect. I have tried with official example code and I got the same results

Next, you can see the code, input image and output image. Only the "0" triangle seems to be right.

I tried with different example codes, and the results are the same.

Output image: Mass center calculated by the program Input image: Image Input

Waited results: Image mass center

Example code:

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

using namespace cv;
using namespace std;

Mat src; Mat srcGray;
RNG rng(12345);

int main(int argc, char **argv)
{
    // Load source image and convert it to gray
    src = imread(argv[1], 1);

    // Convert image to gray and blur it
    cvtColor(src, srcGray, CV_BGR2GRAY);
    blur(srcGray, srcGray, Size(3, 3));

    Mat srcThresh;
    double otsu;

    otsu = threshold(srcGray, srcThresh, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);

    Mat cannyOut;
    Canny(srcGray, cannyOut, otsu, otsu * 1 / 2, 3, 1);

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

    findContours(cannyOut, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, 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] = Point2f(mu[i].m10 / mu[i].m00, mu[i].m01 / mu[i].m00);
    }

    // Draw contours
    Mat drawing = Mat::zeros(cannyOut.size(), CV_8UC3);
    string sObjectNumber;          // string which will contain the result
    ostringstream sContourNumber;   // stream used for the conversion

    for (int i = 0; i< contours.size(); i++)
    {
//        drawing.setTo(Scalar(0.0,0.0,0.0));
        sContourNumber << i;
        sObjectNumber = sContourNumber.str();   // Convert int to string
        Point pCoordinates(mc[i].x + 3, mc[i].y - 3);   // Text's coordinates (A little bit off from mass center)
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
        circle(drawing, mc[i], 4, color, -1, 8, 0);     // Draw mass center
        putText(drawing, sObjectNumber, pCoordinates, CV_FONT_HERSHEY_COMPLEX, 1, color, 2, 8); // Write object number
        sContourNumber.str("");     // Clear string
        sContourNumber.clear();     // Clear any error flags

//        imshow("Contours", drawing);
//        waitKey();
    }

    double hu[7];
    for (int i = 0; i < contours.size(); i++)
    {
        cout << "Contour: " << i << " Area: " << contourArea(contours[i]) << " Length: " << arcLength(contours[i], true) << "\n";

        for (int j = 0; j < 7; j++)
        {
            HuMoments(mu[i], hu);
            cout << "Contour: " << i << " Hu: " << j << " Result: " << hu[j] << "\n";
        }
        cout << "\n";
    }

    imshow("Contours", drawing);

    waitKey(0);
    return(0);
}

Can somebody helpme?

Very thanks for all! Diego