Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C++ to VB.net

NasujoNasujo Member Posts: 5
Hi guys I need help translating the following to vb.net. I'm a relatively new programmer to both and I would highly appreciate any help offered. It is not complete but I would like to get an idea of how to use classes. Thanks in advance!


[code]

#include
#include
#include "classfaces.h"

//------------------------------------------------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------------------------------------------------
classfaces::classfaces()
{
initialised=false;
}


//------------------------------------------------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------------------------------------------------
classfaces::~classfaces()
{
}


//------------------------------------------------------------------------------------------------------------------------
// initialise
//------------------------------------------------------------------------------------------------------------------------
void classfaces::init()
{
createImage(width,height);
initialised=true;

vertical = new int[width];
toppos = new int[width];
}



//------------------------------------------------------------------------------------------------------------------------
// returns true is the given colour is a skin tone
//------------------------------------------------------------------------------------------------------------------------
bool classfaces::isSkinTone(int r,int g,int b)
{
int max;
bool isSkin;

isSkin=true;
//isSkin = (2*r) > (b+g);


if ((r < 80) || (r>250))
isSkin=false;
else
{
if (r < 1.1 * g)
isSkin=false;
else
{
if (r < 0.9 * b)
isSkin=false;
else
{
if (g > b) max = g; else max = b;
if (r > 2 * max) isSkin=false;
}
}
}


return(isSkin);
}



//------------------------------------------------------------------------------------------------------------------------
// detect faces based on skin colour
//------------------------------------------------------------------------------------------------------------------------
void classfaces::colourDetect(classimage *img)
{
int x,y,c,r,g,b;

for (x=0;ximage[x][y][2]>0)
{
r = (int)(img->image[x][y][0]);
g = (int)(img->image[x][y][1]);
b = (int)(img->image[x][y][2]);

if (isSkinTone(r,g,b))
{
for (c=0;c<3;c++) image[x][y][c] = img->image[x][y][c];
}
else
for (c=0;c<3;c++) image[x][y][c]=0;
}
else
for (c=0;c<3;c++) image[x][y][c]=0;
}
}
}


//------------------------------------------------------------------------------------------------------------------------
// detect person-like shapes from stereo data
// this looks for a 'head and shoulders' pattern, the isolates the head part
//------------------------------------------------------------------------------------------------------------------------
void classfaces::stereoDetect(classimage *img, classimage *img_raw)
{
int x,y,p1,p2,v,c;
int min_vertical = height / 4;
int i,av_top,max_top,bottom;
float ratio;

//look for vertical lines
for (x=0;x<width;x++)
{
v=0;
toppos[x]=-1;
for (y=height-1;y>0;y--)
{
p1 = img->image[x][y][0];
p2 = img->image[x][y-1][0];

if ((p1>0) && (p2>0))
{
v++;
if (toppos[x]==-1) toppos[x] = y;
}
}

vertical[x] = v;
}


av_top=0;
max_top=0;
i=1;
for (x=0;xmin_vertical)
{
av_top += height - toppos[x];
i++;
if (toppos[x]>max_top) max_top = toppos[x];
}

av_top /= i;
bottom = (av_top * 3) / 4;


for (x=0;xmin_vertical) && (max_top - bottom > 0))
{
ratio = ((float)(toppos[x] - bottom)) / ((float)(max_top - bottom));
if ((y>bottom) && (y0.7))
for (c=0;c<3;c++) image[x][y][c] = img_raw->image[x][y][c];
}
}
}

}



//------------------------------------------------------------------------------------------------------------------------
// update
//------------------------------------------------------------------------------------------------------------------------
void classfaces::update(classimage *stereoimage, classimage *rawimage)
{
if (stereoimage->width>0)
{
width = stereoimage->width;
height = stereoimage->height;
if (initialised==false) init();

//colourDetect(img);
stereoDetect(stereoimage,rawimage);
}
}


#ifndef CLASSFACES_H
#define CLASSFACES_H

#include "classimage.h"

class classfaces : public classimage
{

private:

int *vertical;
int *toppos;

void init();
bool initialised;

//detect faces based on skin colour
void colourDetect(classimage *img);

//detect person-like shapes using stereo
void stereoDetect(classimage *img, classimage *img_raw);

//function used for detecting skin tones
bool isSkinTone(int r,int g,int b);

public:

void update(classimage *stereoimage, classimage *rawimage);

classfaces();
~classfaces();
};

#endif


[/code]


Comments

  • bmiller1222bmiller1222 Member Posts: 107
    [b][red]This message was edited by bmiller1222 at 2005-5-31 12:35:2[/red][/b][hr]
    : Hi guys I need help translating the following to vb.net. I'm a relatively new programmer to both and I would highly appreciate any help offered. It is not complete but I would like to get an idea of how to use classes. Thanks in advance!
    :
    :
    : [code]
    :
    : #include
    : #include
    : #include "classfaces.h"
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // constructor
    : //------------------------------------------------------------------------------------------------------------------------
    : classfaces::classfaces()
    : {
    : initialised=false;
    : }
    :
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // destructor
    : //------------------------------------------------------------------------------------------------------------------------
    : classfaces::~classfaces()
    : {
    : }
    :
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // initialise
    : //------------------------------------------------------------------------------------------------------------------------
    : void classfaces::init()
    : {
    : createImage(width,height);
    : initialised=true;
    :
    : vertical = new int[width];
    : toppos = new int[width];
    : }
    :
    :
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // returns true is the given colour is a skin tone
    : //------------------------------------------------------------------------------------------------------------------------
    : bool classfaces::isSkinTone(int r,int g,int b)
    : {
    : int max;
    : bool isSkin;
    :
    : isSkin=true;
    : //isSkin = (2*r) > (b+g);
    :
    :
    : if ((r < 80) || (r>250))
    : isSkin=false;
    : else
    : {
    : if (r < 1.1 * g)
    : isSkin=false;
    : else
    : {
    : if (r < 0.9 * b)
    : isSkin=false;
    : else
    : {
    : if (g > b) max = g; else max = b;
    : if (r > 2 * max) isSkin=false;
    : }
    : }
    : }
    :
    :
    : return(isSkin);
    : }
    :
    :
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // detect faces based on skin colour
    : //------------------------------------------------------------------------------------------------------------------------
    : void classfaces::colourDetect(classimage *img)
    : {
    : int x,y,c,r,g,b;
    :
    : for (x=0;ximage[x][y][2]>0)
    : {
    : r = (int)(img->image[x][y][0]);
    : g = (int)(img->image[x][y][1]);
    : b = (int)(img->image[x][y][2]);
    :
    : if (isSkinTone(r,g,b))
    : {
    : for (c=0;c<3;c++) image[x][y][c] = img->image[x][y][c];
    : }
    : else
    : for (c=0;c<3;c++) image[x][y][c]=0;
    : }
    : else
    : for (c=0;c<3;c++) image[x][y][c]=0;
    : }
    : }
    : }
    :
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // detect person-like shapes from stereo data
    : // this looks for a 'head and shoulders' pattern, the isolates the head part
    : //------------------------------------------------------------------------------------------------------------------------
    : void classfaces::stereoDetect(classimage *img, classimage *img_raw)
    : {
    : int x,y,p1,p2,v,c;
    : int min_vertical = height / 4;
    : int i,av_top,max_top,bottom;
    : float ratio;
    :
    : //look for vertical lines
    : for (x=0;x<width;x++)
    : {
    : v=0;
    : toppos[x]=-1;
    : for (y=height-1;y>0;y--)
    : {
    : p1 = img->image[x][y][0];
    : p2 = img->image[x][y-1][0];
    :
    : if ((p1>0) && (p2>0))
    : {
    : v++;
    : if (toppos[x]==-1) toppos[x] = y;
    : }
    : }
    :
    : vertical[x] = v;
    : }
    :
    :
    : av_top=0;
    : max_top=0;
    : i=1;
    : for (x=0;xmin_vertical)
    : {
    : av_top += height - toppos[x];
    : i++;
    : if (toppos[x]>max_top) max_top = toppos[x];
    : }
    :
    : av_top /= i;
    : bottom = (av_top * 3) / 4;
    :
    :
    : for (x=0;xmin_vertical) && (max_top - bottom > 0))
    : {
    : ratio = ((float)(toppos[x] - bottom)) / ((float)(max_top - bottom));
    : if ((y>bottom) && (y0.7))
    : for (c=0;c<3;c++) image[x][y][c] = img_raw->image[x][y][c];
    : }
    : }
    : }
    :
    : }
    :
    :
    :
    : //------------------------------------------------------------------------------------------------------------------------
    : // update
    : //------------------------------------------------------------------------------------------------------------------------
    : void classfaces::update(classimage *stereoimage, classimage *rawimage)
    : {
    : if (stereoimage->width>0)
    : {
    : width = stereoimage->width;
    : height = stereoimage->height;
    : if (initialised==false) init();
    :
    : //colourDetect(img);
    : stereoDetect(stereoimage,rawimage);
    : }
    : }
    :
    :
    : #ifndef CLASSFACES_H
    : #define CLASSFACES_H
    :
    : #include "classimage.h"
    :
    : class classfaces : public classimage
    : {
    :
    : private:
    :
    : int *vertical;
    : int *toppos;
    :
    : void init();
    : bool initialised;
    :
    : //detect faces based on skin colour
    : void colourDetect(classimage *img);
    :
    : //detect person-like shapes using stereo
    : void stereoDetect(classimage *img, classimage *img_raw);
    :
    : //function used for detecting skin tones
    : bool isSkinTone(int r,int g,int b);
    :
    : public:
    :
    : void update(classimage *stereoimage, classimage *rawimage);
    :
    : classfaces();
    : ~classfaces();
    : };
    :
    : #endif
    :
    :
    : [/code]
    :
    :
    :
    This is quite simple if you just dont worry about the programming aspect. Just take a look at the code, create a flowchart or psuedocode to extract the correct login for each function, the code the loginc using vb, it is quite very simple. Here's an example

    YOUR CODE:
    //------------------------------------------------------------------------------------------------------------------------
    // update
    //------------------------------------------------------------------------------------------------------------------------
    void classfaces::update(classimage *stereoimage, classimage *rawimage)
    {
    if (stereoimage->width>0)
    {
    width = stereoimage->width;
    height = stereoimage->height;
    if (initialised==false) init();

    //colourDetect(img);
    stereoDetect(stereoimage,rawimage);
    }
    }

    Basically you would need to create a function that needs to 2 classimage objects. You need to compare one of the objects width. If the result is true, you need to assign a new height and width for the object,check if it is initialize, and then call a function to detect the color.

    VB Code would be something like this
    Public Sub UpdateImage (byref stereoimage as classimage, byref rawimage as classimage)

    'compare
    If stereoimage.width>0 then
    width=stereoimage.width
    height=stereoimage.height

    if stereoimage is nothing then
    stereodetect(stereoimage, rawimage)
    End if
    End if

    End Sub

Sign In or Register to comment.