博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
混合高斯模型不显示背景
阅读量:6928 次
发布时间:2019-06-27

本文共 3663 字,大约阅读时间需要 12 分钟。

sample bgfg_segm.cpp don't display background in 2.1.0 version

The following function fills model->background image when model is MOG (cvCreateGaussianBGModel). I hope this helps those who encounter this problem in the meanwhile

typedef struct MyCvGaussBGValues{    float match_sum;    float weight;    float mean[3];    float variance[3];}MyCvGaussBGValues;static void updateBackground(CvGaussBGModel* bg_model){        int K = bg_model->params.n_gauss;        int nchannels = bg_model->background->nChannels;        int height = bg_model->background->height;        int width = bg_model->background->width;        MyCvGaussBGValues *g_point = (MyCvGaussBGValues *) ((CvMat*)(bg_model->g_point))->data.ptr;        MyCvGaussBGValues *mptr = g_point;    for(int y=0; y
background->widthStep*y + x*nchannels; float mean[3] = {
0.0, 0.0, 0.0}; for(int k=0; k
background->imageData[pos+m] = (uchar) (mean[m]+0.5); } } }}

Call just after cvUpdateBGStatModel(), as this:

cvUpdateBGStatModel( tmp_frame, bg_model, update_bg_model ? -1 : 0 );updateBackground((CvGaussBGModel*)bg_model);

Improved previous version:

typedef struct MixData1{        float match_sum;        float weight;        float mean;        float variance;}MixData1;typedef struct MixData3{        float match_sum;        float weight;        float mean[3];        float variance[3];}MixData3;void BackgroundThread::update8uC1(CvGaussBGModel* bg_model){        int K = bg_model->params.n_gauss;        float T = bg_model->params.bg_threshold;        int height = bg_model->background->height;        int width = bg_model->background->width;        MixData1 *g_point = (MixData1 *) ((CvMat*)(bg_model->g_point))->data.ptr;        MixData1 *mptr = g_point;        for(int y=0; y
background->widthStep*y + x; float mean = 0.0; float wsum = 0.0; int kForeground = K; for(int k=0; k
T) { kForeground = k+1; break; } } for(int k=0; k
background->imageData[pos] = (uchar) (mean/wsum); } }}void BackgroundThread::update8uC3(CvGaussBGModel* bg_model){ int K = bg_model->params.n_gauss; float T = bg_model->params.bg_threshold; int nchannels = bg_model->background->nChannels; int height = bg_model->background->height; int width = bg_model->background->width; MixData3 *g_point = (MixData3 *) ((CvMat*)(bg_model->g_point))->data.ptr; MixData3 *mptr = g_point; for(int y=0; y
background->widthStep*y + x*nchannels; float mean[3] = {
0.0, 0.0, 0.0}; float wsum = 0.0; int kForeground = K; for(int k=0; k
T) { kForeground = k+1; break; } } for(int k=0; k
background->imageData[pos+m] = (uchar) (mean[m]/wsum); //+0.5 } } }}

Call just after cvUpdateBGStatModel(), as this:

cvUpdateBGStatModel(image, model, -1);update8uC3((CvGaussBGModel*)model);

文章摘自上面链接,本人测试还没有通过,程序编译没问题,但运行时会崩溃。可能是内存或指针的问题吧,检查中.....

转载地址:http://ngzjl.baihongyu.com/

你可能感兴趣的文章
MYSQL错误:You can't specify target table for update in FROM clause
查看>>
Java-输入输出流
查看>>
'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique
查看>>
Java知多少(87)选择框和单选按钮(转)
查看>>
股票作手回忆录Digest(转)
查看>>
Java Date API demo
查看>>
SPOJ SUBST1 后缀数组
查看>>
C#中,使用正则表达式匹配获取所需数据
查看>>
Codeforces #270 D. Design Tutorial: Inverse the Problem
查看>>
Recurrent Neural Network 学习笔记【二】RNN-LSTM
查看>>
css 使div垂直、水平居中
查看>>
android ListView几个比较特别的属性
查看>>
7、正则表达式
查看>>
android设备适配
查看>>
算法题:整形数组找a和b使得a+b=n
查看>>
mysql优化建议大全
查看>>
C#.Net Mvc运营监控,计算方法/接口/action/页面执行时间
查看>>
存储过程分页方案
查看>>
扫盲 Linux:如何选择发行版
查看>>
色版黑莓Bold9900已经登岸香港市场
查看>>