0

I am trying to create a linear structuring element in EmguCv and rotate it based on an agle for use in morphological operations. I am familiar with morphological operations and I have tried using the GetStructuringElement function which lets me create a square, ellipse or cross kernel and specify its size.

Mat kernelTest = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Custom, new Size(6, 6), new Point(-1, -1));

I can also choose custom, but the problem is that I have no idea how to create a matrix of a certain size containing a line of ones and use that as a structuring element.

Example: [0 0 0 0]
         [1 1 1 1]
         [0 0 0 0]
         [0 0 0 0]

I would be very grateful if anyone knows how to do this in EmguCv or opencv.

1 Answers1

0

You can get a single row with kernelTest.Row(int). More info on the EmguCV Documentation.

With this method, you can cycle every row of your kernel mat, get the row and compare the values in that row with 1.

erik7854
  • 150
  • 1
  • 16
  • Thanks. I will look into it. Would it be possible to use this to set the value of a certain element in the row to one and keep the rest as zeroes? I would like to be able to create matrices with lines of ones, possibly diagonal lines also – Estin Myrhaug Mar 07 '22 at 14:55
  • To set or get specific values in your Mat you'll have to do it manually. In this answer(https://stackoverflow.com/a/32559496/17667233) you can find an extesion to the Mat class that can help you doing wha you mentioned. And ofcourse, you can iterate your matrix with that and create mat from diagonal lines too. – erik7854 Mar 08 '22 at 09:33