Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I want to plot my mouse location

I am newbie in OpenCV, so I don't know can I ask this kind of question here or not? I like to draw a sequence of points as a line on OpenCV3.3.0. I think I can collect this sequence by "vector<point>" although I don't know is this the best idea or not? Lets consider I have these points vector:

 vector<Point> vec = { Point(0,0),Point(10,10),Point(20,20), Point(30,30), Point(40,40), Point(50,50) };

And like to draw them in an empty Mat as an 50*50 pixel image. So it would be the images diameter. But I don't know how can I do this? I searched and found the "line" function, but it has only to "starting and end" points. should I use many line functions in sequence? there isn't better solution for this?

I want to plot my mouse location

I am newbie in OpenCV, so I don't know can I ask this kind of question here or not? I like to draw a sequence of points as a line on OpenCV3.3.0. I think I can collect this sequence by "vector<point>" although I don't know is this the best idea or not? Lets consider I have these points vector:

 vector<Point> vec = { Point(0,0),Point(10,10),Point(20,20), Point(30,30), Point(40,40), Point(50,50) };

And like to draw them in an empty Mat as an 50*50 pixel image. So it would be the images diameter. But I don't know how can I do this? I searched and found the "line" function, but it has only to "starting and end" points. should I use many line functions in sequence? there isn't better solution for this?

I want to plot my mouse locationdraw a line of points

I am newbie in OpenCV, so I don't know can I ask this kind of question here or not? I like to draw a sequence of points as a line on OpenCV3.3.0. I think I can collect this sequence by "vector<point>" although I don't know is this the best idea or not? Lets consider I have these points vector:

 vector<Point> vec = { Point(0,0),Point(10,10),Point(20,20), Point(30,30), Point(40,40), Point(50,50) };

And like to draw them in an empty Mat as an 50*50 pixel image. So it would be the images diameter. But I don't know how can I do this? I searched and found the "line" function, but it has only to "starting and end" points. should I use many line functions in sequence? there isn't better solution for this?

I tried to do it by this code but it thrown in an exception:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

void MyLine(Mat img, Point start, Point end);
Mat im = Mat::zeros(100, 100, CV_8UC1);
Mat img = Mat::zeros(100, 100, CV_8UC1);
vector<Point> vec = { Point(0,0),Point(10,10),Point(20,20), Point(30,30), Point(40,40), Point(50,50) };

    int main()
    {

        Point start= Point(0, 0);
        Point end = Point(50, 50);

        MyLine(img, start, end);
        namedWindow("image", WINDOW_AUTOSIZE);
        imshow("image", im);
        waitKey(0);
        return 0;
    }

    void MyLine(Mat img, Point start, Point end)
    {
        int thickness = 2;
        int lineType = 8;
        for (int i = 0; i < 7; i++)
        {
            line(img,
                vec[i],
                vec[i+1],
                Scalar(255, 255, 255),
                thickness,
                lineType);
            im += img;

        }
    }