Ask Your Question

justrookie's profile - activity

2021-04-22 08:31:33 -0600 received badge  Notable Question (source)
2020-07-22 07:26:24 -0600 received badge  Popular Question (source)
2019-05-27 18:36:43 -0600 received badge  Popular Question (source)
2017-02-04 03:16:01 -0600 received badge  Famous Question (source)
2016-06-10 14:19:08 -0600 received badge  Notable Question (source)
2016-02-26 10:02:27 -0600 received badge  Popular Question (source)
2014-08-11 04:00:13 -0600 received badge  Self-Learner (source)
2014-08-10 08:31:24 -0600 answered a question how to delete repeating coordinates of vector<Point2f>

I have got a solution from StackOverflow, see the post:

#include <vector>
#include <unordered_set>


struct Point2f
{
    float x;
    float y;
    Point2f(float a, float b) : x(a), y(b) {}
    Point2f() : x(0), y(0) {}
};

bool operator==(const Point2f& pt1, const Point2f& pt2)
{
    return ((pt1.x == pt2.x) && (pt1.y == pt2.y));
}

namespace std
{
    template<>
    struct hash<Point2f>
    {
        size_t operator()(Point2f const& pt) const
        {
            return (size_t)(pt.x*100 + pt.y);
        }
    };
}


void removedupes(std::vector<Point2f> & vec)
{
    std::unordered_set<Point2f> pointset;

    auto itor = vec.begin();
    while (itor != vec.end())
    {
        if (pointset.find(*itor) != pointset.end())
        {
            itor = vec.erase(itor);
        }
        else
        {
            pointset.insert(*itor);
            itor++;
        }
    }
}


int main(int argc, char* argv[])
{
    std::vector<Point2f>  pointTemp;

    pointTemp.resize(6);

    pointTemp[0]=Point2f(1,1);
    pointTemp[1]=Point2f(2,3);
    pointTemp[2]=Point2f(1,1);
    pointTemp[3]=Point2f(2,3);
    pointTemp[4]=Point2f(1,1);
    pointTemp[5]=Point2f(4,1);

    removedupes(pointTemp);

    return 0;
}
2014-08-08 19:46:18 -0600 received badge  Critic (source)
2014-08-08 03:35:57 -0600 asked a question how to delete repeating coordinates of vector<Point2f>

I passed coordinates of points into vector, and there are some repeating points, so I want to delete other repeating points and just keep the only points.

for example:

vector<Point2f>  points;

points[0]=Point2f(1,1); 
points[1]=Point2f(2,3); 
points[2]=Point2f(1,1); 
points[3]=Point2f(2,3); 
points[4]=Point2f(1,1); 
points[5]=Point2f(4,1);

I want to get the result like this:

points[0]=Point2f(1,1);
points[1]=Point2f(2,3);
points[2]=Point2f(4,1);

PS The order of remaining elements is unchanged.

2014-08-07 21:49:11 -0600 received badge  Scholar (source)
2014-08-07 21:47:54 -0600 commented answer how to detect ellipse and get centers of ellipse

@Haris Thank you for your solution, your method is a bit more complicated, but anyway it is a approach to get the problem done.

2014-08-07 21:42:36 -0600 commented answer how to detect ellipse and get centers of ellipse

Wow!!!!!The method is so amazing ! Thank you for your great idea.

2014-08-07 12:34:21 -0600 received badge  Student (source)
2014-08-07 08:13:37 -0600 commented question how to detect ellipse and get centers of ellipse

@Haris and @StevenPuttemans Thank you for your reply, I know we can use the Hough method to detect circles and get center of circle, but what I want is the four centers of ellipse. Obviously, there are some differences between the two kinds of centers.

2014-08-07 04:00:42 -0600 commented question how to detect ellipse and get centers of ellipse

@ Haris Yes, we can get the ellipse center from the box.center method. As we can see from the result image, we got more than four ellipses, but I just want the four ellipses located on corners.

2014-08-07 03:38:22 -0600 asked a question how to detect ellipse and get centers of ellipse

image description

I want to detect the four ellipses from the image above and get centers of each ellipse. I followed the page, and got the result show as follow bellow:image description

My question is how to get the four centers of ellipse.

2014-08-06 21:42:57 -0600 received badge  Supporter (source)
2014-08-02 02:56:00 -0600 received badge  Editor (source)
2014-08-02 02:54:21 -0600 asked a question Return coordinate values from mouse callback function and save values to txt

I want to return point coordinates from mouse callback function and save it to txt file, but the txt file is empty. I have checked the code and found that the vector<point> is empty, but I do not know how to fix it. Any help?

My code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <stdio.h>
#include <vector>
#include <iostream>
#include <fstream>

using namespace std;
using namespace cv;


Mat org;
int n=0;
vector<Point> capturePoint;// point coordinates, global variable;

void on_mouse(int event,int x,int y,int flags,void *ustc)
{
    Point pt;//mouse position;
    char coordinate[16];

    if (event == CV_EVENT_LBUTTONDOWN)
    {
        pt = Point(x,y);
        cout<<x<<" "<<y<<endl;
        capturePoint.push_back(pt);
        n++;

        circle(org,pt,2,Scalar(255,0,0,0),CV_FILLED,CV_AA,0);
        sprintf(coordinate,"(%d,%d)",x,y);
        putText(org,coordinate,pt,FONT_HERSHEY_SIMPLEX,0.5,Scalar(0,0,0,255),1,8);

        //imshow("org",org);

        if(n>=4)//only four points are needed;
        {
            imshow("org",org);
            cvDestroyAllWindows();
        }
    }
}

int main()
{
    org = imread("1-3.jpg",1);

    namedWindow("org",1);
    setMouseCallback("org",on_mouse,0);//mouse callback function;

    imshow("org",org);
    //cout<<n<<endl;

    cout<<capturePoint.size()<<endl;
    ofstream file("sample.txt");//save coordinates to txt file;
    if(!file)
    {
        cout << "open file error!";
        return 1;
    }
    vector<Point>::iterator it=capturePoint.begin();
    for(;it!=capturePoint.end();++it)
    {
        file<< it->x<<','<<it->y<<endl;
    }
    //file<<endl;
    file.close();

    waitKey(0);
    return 0;
}