# Manipulating and accessing Mat data in EmguCV: how to get array elements and apply scalar?

**URL:** <https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418>\
**Category:** C++\
**Tags:** csharp\
**Created:** [April 15, 2022, 4:33pm UTC](https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418 "2022-04-15T16:33:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FupaTroopa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/fupatroopa/32/5042_2.png) [@FupaTroopa](https://forum.opencv.org/u/FupaTroopa)\
**Post date:** [April 15, 2022, 4:33pm UTC](https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418/1 "2022-04-15T16:33:31Z")

</div>

I’ve started using EmguCV in C# and there is a bit of an adjustment, as method calls here are not all 1-to-1 as they are in C++.

If I have a histogram image to work with I call “hist”, and I wanted to access its elements to push to another vector, I would simply:  
d.push\_back(hist.at(i - 1));

There does not seem to be a .at method available in the emgu wrapper. Does anyone have experience with this, and would this be its C# equivalent?:  
var histMatData = hist.GetData();  
d.Add((float)histMatData.GetValue(i-1, 0)); //crashes when doing (0, i-1)

While I am at it, I want to make a new image with a Scalar specified. But there is no option in any constructor in EmguCV’s Mat object. How could I do this?

I can make two separate topics if that is considered more appropriate. Thanks in advance for any advice.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 15, 2022, 7:42pm UTC](https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418/2 "2022-04-15T19:42:40Z")

</div>

if you want my 2 ct. - dont use emgu

it’s not supported from opencv (3rd party wrapper), their forum is dead, and once you have an **API** problem, – you’re dead in the water.

---

<div class="post-metadata">

**Author:** ![FupaTroopa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/fupatroopa/32/5042_2.png) [@FupaTroopa](https://forum.opencv.org/u/FupaTroopa)\
**Post date:** [April 15, 2022, 7:54pm UTC](https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418/3 "2022-04-15T19:54:31Z")

</div>

Thanks! I’m glad the solution is to just not do it. I’ll go tell my boss that.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [April 15, 2022, 10:02pm UTC](https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418/4 "2022-04-15T22:02:02Z")

</div>

look at “opencvsharp” instead.

but yes, bosses need to be told “no” more often or else they go on believing this “mind over matter” nonsense and walk off the holodeck.

---

<div class="post-metadata">

**Author:** ![FupaTroopa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/fupatroopa/32/5042_2.png) [@FupaTroopa](https://forum.opencv.org/u/FupaTroopa)\
**Post date:** [April 15, 2022, 10:42pm UTC](https://forum.opencv.org/t/manipulating-and-accessing-mat-data-in-emgucv-how-to-get-array-elements-and-apply-scalar/8418/5 "2022-04-15T22:42:16Z")

</div>

Thank you, that is helpful. I will look at it.

It’s kind of my fault, I jumped into what looked like an easier project. When working with a certain package/api you won’t get the best idea of its shortcomings until you hit a wall.
