# Segmentation fault

**URL:** https://forum.opencv.org/t/segmentation-fault/1260
**Category:** Uncategorized
**Tags:** ml
**Created:** [February 1, 2021, 5:36pm UTC](https://forum.opencv.org/t/segmentation-fault/1260 "2021-02-01T17:36:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jan\_Hackenberg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jan_hackenberg/32/797_2.png) [@Jan\_Hackenberg](https://forum.opencv.org/u/Jan_Hackenberg)
#### Post date: [February 1, 2021, 5:36pm UTC](https://forum.opencv.org/t/segmentation-fault/1260/1 "2021-02-01T17:36:24Z")

</div>

I am trying to execute based on [example code](https://programming.vip/docs/gmm-gaussian-mixture-model-method-for-opencv-image-segmentation.html):

```
  using namespace cv;
  using namespace cv::ml;
  // mat is a Mat containing the features computed beforehand
  Ptr<EM> model = EM::create();
  model->setClustersNumber(static_cast<int>(m_numberClusters));
  Mat logs, labels, probs;
  model->trainEM(mat, logs, labels, probs);

```

**setClustersNumber** gives a segmentation fault, if commented out then **trainEM** does. Debugging reveals, that those are pure virtual functions, which is in coincidence with [OpenCV API](https://docs.opencv.org/3.4/d1/dfb/classcv_1_1ml_1_1EM.html).

See here:

[![enter image description here](https://i.stack.imgur.com/BZt8V.png)](https://i.stack.imgur.com/BZt8V.png)

Nevertheless I do not find any implementation class having those pure virtual functions nor other examples for Expectation Maximization by OpenCV with 3.x.x versions.

[![enter image description here](https://i.stack.imgur.com/j2zZx.png)](https://i.stack.imgur.com/j2zZx.png)

[![enter image description here](https://i.stack.imgur.com/g2HZd.png)](https://i.stack.imgur.com/g2HZd.png)

---

<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: [February 1, 2021, 9:11pm UTC](https://forum.opencv.org/t/segmentation-fault/1260/2 "2021-02-01T21:11:08Z")

</div>

related:

> <https://stackoverflow.com/questions/65962508/expectation-maximization-opencv>
