Hand center detection
I am detecting the hand, using Defects but i need only the palm without fingers, the center of the palm without fingers. I wrote this piece of code:
int ht, //height left
hb, //height right
wl, //width top
wr; //width botton
bool ok = true;
label1.Text = label1.Text + ",";
for(int i = 10; i < skin.Height - 10; i += 10)
for(int j = 10; j < skin.Width - 10; j+=10)
{
wl = wr = j;
ht = hb = i;
if(skin[i, j].MCvScalar.v0 == 0)
ok = true;
while(ok)
{
wl--;
wr++;
ht--;
hb++;
if( (wl <= 0 || wr >=skin.Height || ht <= 0 || hb >=skin.Width) ||
( skin[j, ht].MCvScalar.v0 != 0 || skin[j, hb].MCvScalar.v0 != 0 ||
skin[wl, j].MCvScalar.v0 != 0 || skin[wr, j].MCvScalar.v0 != 0) )
{
if(maxCircleRadius < (wr - wl) / 2)
{
maxCircleRadius = (wr - wl) / 2;
palmCenter.X = (wr + wl) / 2;
palmCenter.Y = (ht + hb) / 2;
currentFrame.Draw(new CircleF(new PointF(palmCenter.X, palmCenter.Y), 3), new Bgr(200, 125, 75), 2);
label1.Text = maxCircleRadius.ToString();
}
ok = false;
}
}
}
but it takes around 0.5 sec for each image to detect the palm wich is way too much for me. Is there any other solution to detect the palm without fingers?
The performance problem may be the drawing delay. Try removing the Draw() and label.Text calls and re-measure your app. You should also make sure you compile for Release.