2

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.

avm_69
  • 183
  • 2
  • 11

3 Answers3

1

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

Community
  • 1
  • 1
ATul Singh
  • 490
  • 3
  • 15
  • This is perfect. Thank you, – avm_69 May 11 '16 at 10:00
  • 1
    Installing OpenCV 3.1 would be much better. Version 2.4.3 is quite old – Miki May 11 '16 at 10:17
  • Isn't this http://docs.opencv.org/2.4/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html#morphology-1 just completely the opposite? I mean, they say dilation makes the character thinner. Isn't it supposed to act the other way? – avm_69 May 18 '16 at 11:37
1

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.

ELRG
  • 590
  • 4
  • 15
  • I have this code as my points go from 0 to 1 in x/y coordinates. http://pastebin.com/6LgJ4p15 I'm multiplying by 400 as it is my height and width. But the overcome does not match the supposed result. This shows: http://imgur.com/5Rr7bMI And the supposed result is: http://imgur.com/8IncmXy Any guess on what am I doing wrong? – avm_69 May 20 '16 at 11:19
0

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);