Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:46:36+00:00 2026-06-12T23:46:36+00:00

I am using opencv EM algorithm to obtain GMM models with the help of

  • 0

I am using opencv EM algorithm to obtain GMM models with the help of example code in opencv documentation as follows:

cv::Mat capturedFrame
const int N = 5; 
int nsamples = 100;
cv::Mat samples ( nsamples, 2, CV_32FC1 );
samples = samples.reshape ( 2, 0 );
cv::Mat sample ( 1, 2, CV_32FC1 );
CvEM em_model;
CvEMParams params;

for ( i = 0; i < N; i++ )
{           
//from the training samples
cv::Mat samples_part = samples.rowRange ( i*nsamples/N, (i+1)*nsamples/N);
cv::Scalar mean (((i%N)+1)*img.rows/(N1+1),((i/N1)+1)*img.rows/(N1+1));
cv::Scalar sigma (30,30);
cv::randn(samples_part,mean,sigma);                     

}
samples = samples.reshape ( 1, 0 );
//initialize model parameters
params.covs         = NULL;
params.means        = NULL;
params.weights      = NULL;
params.probs        = NULL;
params.nclusters    = N;
params.cov_mat_type = CvEM::COV_MAT_SPHERICAL;
params.start_step   = CvEM::START_AUTO_STEP;
params.term_crit.max_iter = 300;
params.term_crit.epsilon  = 0.1;
params.term_crit.type   = CV_TERMCRIT_ITER|CV_TERMCRIT_EPS;     
//cluster the data
em_model.train ( samples, Mat(), params, &labels );

As being a fresh to GMM and openCV, now I have some questions:

Firstly, after performing above code, I can get the probs like:

cv::Mat probs = em_model.getProbs();

Then how can I get the models which are having the most and least elements, that is, the biggest and smallest models?

Secondly, my sample data is only 100 here, as in the example code of opencv, but I am reading a frame with size 600×800, and I want to sample all those pixels in it, which is 480000. But it takes about 10 ms for these 100 samples, that means it would be too much slow if I set:

int nsamples = 480000;

Am I on the right way here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:46:38+00:00Added an answer on June 12, 2026 at 11:46 pm

    If I get your question right, what you call your “biggest” and “smallest” models refers to the weights of each gaussian in the mixture. You can get the weights associated to the gaussians using EM::getWeights.

    Concerning second question, if you train your model using 480000 samples instead of 100, yes, it will be definitely longer. Being “too slow” depends on your requirements. But EM is a classification model, so what is usually done is that you must train the model, using a sufficient amount of sample. This is a long process, but usually done “offline”. Then, you can use the model to “predict” new samples, i.e. get the probabilities associated with new input samples. When you call getProbs() function, you get the probabilities associated with your training samples. If you want to get probabilities for unknown samples, typically pixels in your video frame, call the function predict.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an algorithm using opencv library on an embedded processor (NIOS 2)
I am trying to implement the eigenface algorithm using OpenCV in VS2010. I am
I'm using OpenCV v2.4.1 And this is the code I'm using #include opencv2/opencv.hpp #include
I am trying to use opencv EM algorithm to do color extraction.I am using
I am using OpenCV Haar Algorithm to track the Head and overlay an image
I'm implementing the component labelling algorithm as in this paper using python and opencv.
I am implementing an image analysis algorithm using openCV and c++, but I found
I am implementing an image processing algorithm in C++ using openCV, in which the
I have to code an object detector (in this case, a ball) using OpenCV.
I'm using opencv and I need to obtain a single region of white pixels

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.