开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
ch09_AvgBackground.cpp 5.96 KB
一键复制 编辑 原始数据 按行查看 历史
v2 提交于 2018年07月31日 16:57 +08:00 . change file name 1 to 01
#include "ch9_AvgBackground.h"
//GLOBALS
IplImage *IavgF[NUM_CAMERAS],*IdiffF[NUM_CAMERAS], *IprevF[NUM_CAMERAS], *IhiF[NUM_CAMERAS], *IlowF[NUM_CAMERAS];
IplImage *Iscratch,*Iscratch2,*Igray1,*Igray2,*Igray3,*Imaskt;
IplImage *Ilow1[NUM_CAMERAS],*Ilow2[NUM_CAMERAS],*Ilow3[NUM_CAMERAS],*Ihi1[NUM_CAMERAS],*Ihi2[NUM_CAMERAS],*Ihi3[NUM_CAMERAS];
float Icount[NUM_CAMERAS];
void AllocateImages(IplImage *I) //I is just a sample for allocation purposes
{
for(int i = 0; i<NUM_CAMERAS; i++){
IavgF[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 3 );
IdiffF[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 3 );
IprevF[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 3 );
IhiF[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 3 );
IlowF[i] = cvCreateImage(cvGetSize(I), IPL_DEPTH_32F, 3 );
Ilow1[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Ilow2[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Ilow3[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Ihi1[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Ihi2[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Ihi3[i] = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
cvZero(IavgF[i] );
cvZero(IdiffF[i] );
cvZero(IprevF[i] );
cvZero(IhiF[i] );
cvZero(IlowF[i] );
Icount[i] = 0.00001; //Protect against divide by zero
}
Iscratch = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 3 );
Iscratch2 = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 3 );
Igray1 = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Igray2 = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Igray3 = cvCreateImage( cvGetSize(I), IPL_DEPTH_32F, 1 );
Imaskt = cvCreateImage( cvGetSize(I), IPL_DEPTH_8U, 1 );
cvZero(Iscratch);
cvZero(Iscratch2 );
}
void DeallocateImages()
{
for(int i=0; i<NUM_CAMERAS; i++){
cvReleaseImage(&IavgF[i]);
cvReleaseImage(&IdiffF[i] );
cvReleaseImage(&IprevF[i] );
cvReleaseImage(&IhiF[i] );
cvReleaseImage(&IlowF[i] );
cvReleaseImage(&Ilow1[i] );
cvReleaseImage(&Ilow2[i] );
cvReleaseImage(&Ilow3[i] );
cvReleaseImage(&Ihi1[i] );
cvReleaseImage(&Ihi2[i] );
cvReleaseImage(&Ihi3[i] );
}
cvReleaseImage(&Iscratch);
cvReleaseImage(&Iscratch2);
cvReleaseImage(&Igray1 );
cvReleaseImage(&Igray2 );
cvReleaseImage(&Igray3 );
cvReleaseImage(&Imaskt);
}
// Accumulate the background statistics for one more frame
// We accumulate the images, the image differences and the count of images for the
// the routine createModelsfromStats() to work on after we're done accumulating N frames.
// I Background image, 3 channel, 8u
// number Camera number
void accumulateBackground(IplImage *I, int number)
{
static int first = 1;
cvCvtScale(I,Iscratch,1,0); //To float;
if (!first){
cvAcc(Iscratch,IavgF[number]);
cvAbsDiff(Iscratch,IprevF[number],Iscratch2);
cvAcc(Iscratch2,IdiffF[number]);
Icount[number] += 1.0;
}
first = 0;
cvCopy(Iscratch,IprevF[number]);
}
// Scale the average difference from the average image high acceptance threshold
void scaleHigh(float scale, int num)
{
cvConvertScale(IdiffF[num],Iscratch,scale); //Converts with rounding and saturation
cvAdd(Iscratch,IavgF[num],IhiF[num]);
cvCvtPixToPlane( IhiF[num], Ihi1[num],Ihi2[num],Ihi3[num], 0 );
}
// Scale the average difference from the average image low acceptance threshold
void scaleLow(float scale, int num)
{
cvConvertScale(IdiffF[num],Iscratch,scale); //Converts with rounding and saturation
cvSub(IavgF[num],Iscratch,IlowF[num]);
cvCvtPixToPlane( IlowF[num], Ilow1[num],Ilow2[num],Ilow3[num], 0 );
}
//Once you've learned the background long enough, turn it into a background model
void createModelsfromStats()
{
for(int i=0; i<NUM_CAMERAS; i++)
{
cvConvertScale(IavgF[i],IavgF[i],(double)(1.0/Icount[i]));
cvConvertScale(IdiffF[i],IdiffF[i],(double)(1.0/Icount[i]));
cvAddS(IdiffF[i],cvScalar(1.0,1.0,1.0),IdiffF[i]); //Make sure diff is always something
scaleHigh(HIGH_SCALE_NUM,i);
scaleLow(LOW_SCALE_NUM,i);
}
}
// Create a binary: 0,255 mask where 255 means forground pixel
// I Input image, 3 channel, 8u
// Imask mask image to be created, 1 channel 8u
// num camera number.
//
void backgroundDiff(IplImage *I,IplImage *Imask, int num) //Mask should be grayscale
{
cvCvtScale(I,Iscratch,1,0); //To float;
//Channel 1
cvCvtPixToPlane( Iscratch, Igray1,Igray2,Igray3, 0 );
cvInRange(Igray1,Ilow1[num],Ihi1[num],Imask);
//Channel 2
cvInRange(Igray2,Ilow2[num],Ihi2[num],Imaskt);
cvOr(Imask,Imaskt,Imask);
//Channel 3
cvInRange(Igray3,Ilow3[num],Ihi3[num],Imaskt);
cvOr(Imask,Imaskt,Imask);
//Finally, invert the results
cvSubRS( Imask, cvScalar(255), Imask);
}
//////////////////////////////////////////////////////////////////////////
/*
//Utility comparision function
gbCmp(IplImage *I1, IplImage *I2, IplImage *Imask, int op)
{
int len = I1->width*I1->height;
int x;
float *fp1 = (float *)I1->imageData;
float *fp2 = (float *)I2->imageData;
char *cp = Imask->imageData;
if(op == CV_CMP_GT)
{
for(x=0;x<len;x++)
{
if(*fp1++ > *fp2++)
*cp++ = 255;
else
*cp++ = 0;
}
}
else
{
for(x=0;x<len;x++)
{
if(*fp1++ < *fp2++)
*cp++ = 255;
else
*cp++ = 0;
}
}
}
void backgroundDiff(IplImage *I,IplImage *Imask, int num) //Mask should be grayscale
{
cvCvtScale(I,Iscratch,1,0); //To float;
cvCvtPixToPlane( Iscratch, Igray1,Igray2,Igray3, 0 );
gbCmp(Igray1,Ihi1[num],Imask,CV_CMP_GT);
gbCmp(Igray2,Ihi2[num],Imaskt,CV_CMP_GT);
cvOr(Imask,Imaskt,Imask);
gbCmp(Igray3,Ihi3[num],Imaskt,CV_CMP_GT);
cvOr(Imask,Imaskt,Imask);
gbCmp(Igray1,Ilow1[num],Imaskt,CV_CMP_LT);
cvOr(Imask,Imaskt,Imask);
gbCmp(Igray2,Ilow2[num],Imaskt,CV_CMP_LT);
cvOr(Imask,Imaskt,Imask);
gbCmp(Igray3,Ilow3[num],Imaskt,CV_CMP_LT);
cvOr(Imask,Imaskt,Imask);
//Some morphology
// cvErode( Imask, Imask, NULL, 1);
// cvMorphologyEx(Imask, Imask, NULL, NULL, CV_MOP_CLOSE, 1);
}
*/
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MarkDownNote/openCV.git
git@gitee.com:MarkDownNote/openCV.git
MarkDownNote
openCV
openCV
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /