This semester I studying about image processing using opencv, I never used c++ before, and I encounter problem to understand some codes.. Hope someone can explained to me..
and what I want to ask is:
1. in bg.hpp file line 9-11 there's
cv::Mat*** samples;
cv::Mat** fgch;
cv::Mat* fg;
I know cv::Mat is using for make matrix storage from image, but what is *,
**, *** mean?
2. in bg.cpp line 13-15
rndp[i]=rnd(phi), in bg.cpp phi=0 so generate random number of 0?
3. in bg.cpp line 36-37
model->fgch= new cv::Mat*[channels.size()];
model->samples=new cv::Mat**[N];
[N] is that array?
3. in bg.cpp line 85
rand= rndp[rdx], what rdx mean in here? I search in google and say that
rdx is to create or modify registry key..
bg.hpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#ifndef bgf_hpp
#define bgf_hpp
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
struct Model {
cv::Mat*** samples;
cv::Mat** fgch;
cv::Mat* fg;
};
class bgf
{
#define rndSize 256
unsigned char ri;
#define rdx ri++
public:
bgf();
int N,R,noMin,phi;
void init_model(cv::Mat& firstSample);
void setphi(int phi);
cv::Mat* fg(cv::Mat& frame);
private:
bool initDone;
cv::RNG rnd;
Model* model;
void init();
void fg1ch(cv::Mat& frame,cv::Mat** samples,cv::Mat* fg);
int rndp[rndSize],rndn[rndSize],rnd8[rndSize];
};
#endif
|
bg.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include "bgf.hpp"
bgf::bgf():R(20),N(20),noMin(2),phi(0)
{
initDone=false;
rnd=cv::theRNG();
ri=0;
}
void bgf::init()
{
for(int i=0;i<rndSize;i++)
{
rndp[i]=rnd(phi);
rndn[i]=rnd(N);
rnd8[i]=rnd(8);
}
}
void bgf::setphi(int phi)
{
this->phi=phi;
for(int i=0;i<rndSize;i++)
{
rndp[i]=rnd(phi);
}
}
void bgf::init_model(cv::Mat& firstSample)
{
std::vector<cv::Mat> channels;
split(firstSample,channels);
if(!initDone)
{
init();
initDone=true;
}
model=new Model;
model->fgch= new cv::Mat*[channels.size()];
model->samples=new cv::Mat**[N];
model->fg=new cv::Mat(cv::Size(firstSample.cols,firstSample.rows), CV_8UC1);
for(size_t s=0;s<channels.size();s++)
{
model->fgch[s]=new cv::Mat(cv::Size(firstSample.cols,firstSample.rows), CV_8UC1);
cv::Mat** samples= new cv::Mat*[N];
for(int i=0;i<N;i++)
{
samples[i]= new cv::Mat(cv::Size(firstSample.cols,firstSample.rows), CV_8UC1);
}
for(int i=0;i<channels[s].rows;i++)
{
int ioff=channels[s].step.p[0]*i;
for(int j=0;j<channels[0].cols;j++)
{
for(int k=0;k<1;k++)
{
(samples[k]->data + ioff)[j]=channels[s].at<uchar>(i,j);
}
(model->fgch[s]->data + ioff)[j]=0;
if(s==0)(model->fg->data + ioff)[j]=0;
}
}
model->samples[s]=samples;
}
}
void bgf::fg1ch(cv::Mat& frame,cv::Mat** samples,cv::Mat* fg)
{
int step=frame.step.p[0];
for(int i=1;i<frame.rows-1;i++)
{
int ioff= step*i;
for(int j=1;j<frame.cols-1;j++)
{
int count =0,index=0;
while((count<noMin) && (index<N))
{
int dist= (samples[index]->data + ioff)[j]-(frame.data + ioff)[j];
if(dist<=R && dist>=-R)
{
count++;
}
index++;
}
if(count>=noMin)
{
((fg->data + ioff))[j]=0;
int rand= rndp[rdx];
if(rand==0)
{
rand= rndn[rdx];
(samples[rand]->data + ioff)[j]=(frame.data + ioff)[j];
}
|