after greeting for all
iwant to generate depth map from stereoscope image ,ihave two camera
iput one left and one right
for get left&right image
after that iwant to generate the depth map
iwill using that project for helping blind men as after iget depth iwill generate sound
ihope any one help me
i used two way but the two way not arrived to best result
my code
ihae two grayscale images
this way iget sobel edge to right image the the point that bigger than 149
imake matching best with the left image(point)
put in "newim" bitmap
////////////////////////////////
public void matchpixel()
{
Bitmap p1 = new Bitmap(pictureBox3.Image);
// sumI = 0;
for (j = 0; j < 270; j++)
{
cleardeep();
for (i = 0; i < 270; i++)
{
if (p1.GetPixel(i, j).R >= 149)
{
disparity(i, j);
}
else
{
Color newColor = Color.FromArgb(0, 0, 0);
newim.SetPixel(i,j, newColor);
}
}
}
pictureBox4.Image = newim;
}
private void disparity(int i1, int j1)
{
int S = 0;
int PL = 0;
int X=0;
int Xmatch=0;
int deex=0;
int endlimi = 0;
int limiti = 0;
int o = 0;
int disttvalue = 0;
if ((i1 >= 10) && (i1 <= 269))
{
limiti =Math.Abs( i1 - 10);
endlimi = i1;
}
else if (i1 > 0)
{
limiti = 0;
endlimi = i1;
}
else
{
limiti = 0;
endlimi = 1;
}
min = 9000;
for (o = limiti; o < endlimi; o++)
{
disttvalue = Math.Abs(i1 - o);
PL = Math.Abs(image_s2.GetPixel(i1, j1).R - image_s1.GetPixel(o, j1).R);
if ((PL < min)&&(disttvalue<=10))
{
min = PL;
Xmatch=o;
S = distt;
deex = i1;
}
PL = 0;
disttvalue = 0;
}
min = 9000;
bool C = false;
for (int h = 0; h < 270; h++)
{
if (deep[h] == Xmatch)
{
bool swith=check(h, i1, Xs, j1);
if (swith==true)
{
disp2(h, j1, Xmatch);
deep[i1] = Xs;
setcolor(i1, j1, S);
C = true;
}
if(swith==false)
{
disp2(i1, j1, Xmatch);
C = true;
}
}
}
if (C == false)
{
setcolor(i1, j1, S);
deep[i1] = Xs;
}
}
private void cleardeep()
{
for (int h = 0; h < 270; h++)
{
deep[h] = 0;
}
}
private bool check(int x1, int x2,int Xsimilirity, int Y)
{
int Score1 = image_s2.GetPixel(x1, Y).R - image_s1.GetPixel(Xsimilirity, Y).R;
int Score2 = image_s2.GetPixel(x2, Y).R - image_s1.GetPixel(Xsimilirity, Y).R;
if (Score1 > Score2)
{
return true;
}
else
{
return false;
}
}
private void setcolor(int x, int y, int d)
{
// int d = (y * 12) / (de+1);
if ((d >= 0) && (d <= 1))
{
d = 30;
}
else if ((d > 1) && (d <= 2))
{
d = 70;
}
else if ((d > 2) && (d <= 3))
{
d = 80;
}
else if ((d > 3) && (d <= 4))
{
d = 100;
}
else if ((d > 4) && (d <= 5))
{
d = 110;
}
else if ((d> 5) && (d <= 6))
{
d = 120;
}
else if ((d > 6) && (d <= 7))
{
d = 130;
}
else if ((d > 7) && (d <= 8))
{
d = 140;
}
else if ((d > 8) && (d <= 9))
{
d =255;
}
else if ((d > 9) && (d <= 10))
{
d = 149;
}
if (d > 255)
{
d = 255;
}
if (d <= 0)
{
d = 0;
}
Color newColor = Color.FromArgb(d, d, d);
newim.SetPixel(x,y, newColor);
}
private void disp2(int x,int y,int simi)
{
int limh = 0;
int endlimh = 0;
int o = 0;
int dist = 0;
int deex1 = 0;
int deepscore1 = 0;
int P = 0;
min = 9000;
if ((x>= 10) && (x <= 269))
{
limh = Math.Abs(x - 10);
endlimh= x;
}
else if ((x > 0)&&(x<=9))
{
limh= 0;
endlimh = x;
}
else
{
limh = 0;
endlimh = 1;
}
for (o = limh; o < endlimh; o++)
{
P = Math.Abs(image_s2.GetPixel(x, y).R - image_s1.GetPixel(o, y).R);
if ((P < min) && (o != simi))
{
if (dist <= 10)
{
min = P;
dist = Math.Abs(x - o);
deepscore1 = o;
}
}
P = 0;
}
setcolor(x, y, dist);
deep[x] = deepscore1;
}