4 Replies - 283 Views - Last Post: 05 August 2014 - 11:16 PM Rate Topic: -----

#1 dd_shidei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 14

Can somebody tell me this code mean?

Posted 05 August 2014 - 07:44 AM

This is my first time using python and video processing, I use opencv 2.4.9, python 2.7.6..
I want to apply vibe algorithm (background subtraction) in my video.. I found code in c language, and I want to convert it to python manually..
Here the code in c:

/**************** Assign space and init ***************************/  
void ViBe_BGS::init(const Mat _image)  
{  
     for(int i = 0; i < NUM_SAMPLES; i++)  
     {  
         m_samples[i] = Mat::zeros(_image.size(), CV_8UC1);  
     }  
     m_mask = Mat::zeros(_image.size(),CV_8UC1);  
     m_foregroundMatchCount = Mat::zeros(_image.size(),CV_8UC1);  
}  



I know that Mat::zeros(_image.size(), CV_8UC1) is array with type 8 bit unsigned int and fill with 0 value and if I convert it to image it'll give image with black color..
what I want to know is m_samples[i], doesn't [i] is array, , so an array of image save to variable m_samples array??

Is This A Good Question/Topic? 0
  • +

Replies To: Can somebody tell me this code mean?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4359
  • View blog
  • Posts: 12,176
  • Joined: 18-April 07

Re: Can somebody tell me this code mean?

Posted 05 August 2014 - 10:42 AM

Well without seeing the Mat::zeros() function definition, and assuming you are right about it returning an array, then yes, m_samples[i] would be an array of arrays (aka a jagged array). It is really hard to say about any of this since we can't see the definition for Mat or ViBe_BGS and how these variables were defined. Their definitions would tell you more about what they are and how they are being used here.

If you need more info then post where many of these variables are defined and perhaps we can get a better picture of what is going on here.
Was This Post Helpful? 0
  • +
  • -

#3 dd_shidei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 14

Re: Can somebody tell me this code mean?

Posted 05 August 2014 - 11:03 AM

The complete code is in here here... If really array in array so is that possible convert it to python?
Was This Post Helpful? 0
  • +
  • -

#4 dd_shidei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 14

Re: Can somebody tell me this code mean?

Posted 05 August 2014 - 10:41 PM

Vibe.h code:

#pragma once  
#include <iostream>  
#include "opencv2/opencv.hpp"  
  
using namespace cv;  
using namespace std;  
  
#define NUM_SAMPLES 20      //每个像素点的样本个数  
#define MIN_MATCHES 2       //#min指数  
#define RADIUS 20       //Sqthere半径  
#define SUBSAMPLE_FACTOR 16 //子采样概率  
  
  
class ViBe_BGS  
{  
public:  
    ViBe_BGS(void);  
    ~ViBe_BGS(void);  
  
    void init(const Mat _image);   //初始化  
    void processFirstFrame(const Mat _image);  
    void testAndUpdate(const Mat _image);  //更新  
    Mat getMask(void){return m_mask;};  
  
private:  
    Mat m_samples[NUM_SAMPLES];  
    Mat m_foregroundMatchCount;  
    Mat m_mask;  
};  



Vibe.cpp code:

#include <opencv2/opencv.hpp>  
#include <iostream>  
#include "ViBe.h"  
  
using namespace std;  
using namespace cv;  
  
int c_xoff[9] = {-1,  0,  1, -1, 1, -1, 0, 1, 0};  //x的邻居点  
int c_yoff[9] = {-1,  0,  1, -1, 1, -1, 0, 1, 0};  //y的邻居点  
  
ViBe_BGS::ViBe_BGS(void)  
{  
  
}  
ViBe_BGS::~ViBe_BGS(void)  
{  
  
}  
  
/**************** Assign space and init ***************************/  
void ViBe_BGS::init(const Mat _image)  
{  
     for(int i = 0; i < NUM_SAMPLES; i++)  
     {  
         m_samples[i] = Mat::zeros(_image.size(), CV_8UC1);  
     }  
     m_mask = Mat::zeros(_image.size(),CV_8UC1);  
     m_foregroundMatchCount = Mat::zeros(_image.size(),CV_8UC1);  
}  
  


Vibe.h code:

#pragma once  
#include <iostream>  
#include "opencv2/opencv.hpp"  
  
using namespace cv;  
using namespace std;  
  
#define NUM_SAMPLES 20      
#define MIN_MATCHES 2         
#define RADIUS 20         
#define SUBSAMPLE_FACTOR 16 
  
  
class ViBe_BGS  
{  
public:  
    ViBe_BGS(void);  
    ~ViBe_BGS(void);  
  
    void init(const Mat _image);    
    void processFirstFrame(const Mat _image);  
    void testAndUpdate(const Mat _image);   
    Mat getMask(void){return m_mask;};  
  
private:  
    Mat m_samples[NUM_SAMPLES];  
    Mat m_foregroundMatchCount;  
    Mat m_mask;  
};  



Vibe.cpp code:

#include <opencv2/opencv.hpp>  
#include <iostream>  
#include "ViBe.h"  
  
using namespace std;  
using namespace cv;  
  
int c_xoff[9] = {-1,  0,  1, -1, 1, -1, 0, 1, 0};  
int c_yoff[9] = {-1,  0,  1, -1, 1, -1, 0, 1, 0};   
  
ViBe_BGS::ViBe_BGS(void)  
{  
  
}  
ViBe_BGS::~ViBe_BGS(void)  
{  
  
}  
  
/**************** Assign space and init ***************************/  
void ViBe_BGS::init(const Mat _image)  
{  
     for(int i = 0; i < NUM_SAMPLES; i++)  
     {  
         m_samples[i] = Mat::zeros(_image.size(), CV_8UC1);  
     }  
     m_mask = Mat::zeros(_image.size(),CV_8UC1);  
     m_foregroundMatchCount = Mat::zeros(_image.size(),CV_8UC1);  
}  
  

Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10648
  • View blog
  • Posts: 39,548
  • Joined: 27-December 08

Re: Can somebody tell me this code mean?

Posted 05 August 2014 - 11:16 PM

We're not explaining someone else's project, nor are we translating the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1