avm_69
avm_69

Reputation: 183

Create image from 2D point array

I have a 2D array of the form (x,y) coordinates. My goal is to create an image of those 2D points.

How could I achieve that?

Thank you, Alex.

Upvotes: 2

Views: 1553

Answers (3)

ELRG
ELRG

Reputation: 630

Using OpenCV, this is roughly how I'd do it (fill in your own variables):

vector<Point> points {Point(x1,y1), Point(x2,y2) ... };
Mat plot(height, width, CV_8U, 255);
for (int i = 0; i < points.size(); i++) {
    plot.at<int>(points[i]) = 0;
}

Draws black pixels at specified points on white background on a canvas that's width x height large. Your 2D points are stored as Point variables, which is a handy OpenCV way of storing, well, 2D points. (Can access individual x/y coords via point.x/point.y as needed). If you want to be fancier you could add set-up validation where the height & width of your canvas is guaranteed larger than your most far-out point - I won't write that out, though.

Upvotes: 1

John Wiggles
John Wiggles

Reputation: 11

If you're using OpenCV, then,

int arr_TU_DI[size_rows][size_cols] = bla bla values; // pseudocode

Mat imag = Mat(size_rows,size_cols,&arr_TU_DI);

Upvotes: 0

ATul Singh
ATul Singh

Reputation: 522

Installing OpenCV 2.4.3 in Visual C++ 2010 Express

This is setting up on Windows Visual Studio 2010 and OpenCV 2.4.3. you can figure out the steps if you want to upgrade on newer version of OpenCV or Visual Studio. Steps will be similar.

Above links provides a good starting point.

After that you need a basic understanding of Mat http://docs.opencv.org/2.4/doc/tutorials/tutorials.html

You can start with Core Module : The Core Functionality this explains Mat and other related operations in detail.

You can find Erode and Dilate tutorial http://docs.opencv.org/2.4/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html#morphology-1

Upvotes: 1

Related Questions