Trong hàm này mình chưa hiểu hàm LineSegment2D của Emgu CV , bạn nào biết giải thích giùm mình, và cách sử dụng trong OpenCV.Nếu viết lại code c/c++ dùng openCV thì tuyệt. Cảm ơn nhiều
private Image<Gray, Byte> Method_HSV(Image<Hsv, byte> image)
{ LineSegment2D[] Lines = // Points depend on each hue
{ new LineSegment2D ( new Point (32,243), new Point (64,255)),
new LineSegment2D ( new Point (64,16), new Point (32,64)), };
Vmax = 255;
Vmin = 16;
Smax = 64;
Smin = 32;
// Normalise each pixel of the image and return a new image
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
Gray = GreyImg_2[j, i].Intensity;
V = image[j, i].Value; // Checks the Brightness
S = image[j, i].Satuation; // Decides intensity of the colour
H = image[j, i].Hue; // Decides the Colour
int s = (int)S;
int v = (int)V;
if (H > 10 && H < 135) // Check for not RED
{
GreyImg_2[j, i] = Black;
}
else
{// Check horizontal and vertical lines
if (Vmax < V || V < Vmin || S < Smin)
GreyImg_2[j, i] = Black;
else if (S > Smax)
GreyImg_2[j, i] = White;
else
{// use table XI
GreyImg_2[j, i] = White;
for (int n = 0; n < Lines.Length; n++) // number of lines
{
int S1 = Lines[n].P1.X;
int V1 = Lines[n].P1.Y;
int S2 = Lines[n].P2.X;
int V2 = Lines[n].P2.Y;
if ((V2 - V1) > 0)
{
if ((((V2 - V1) * s) + ((S1 - S2) * v) + (V1 * S2 - S1 * V2)) < 0)
GreyImg_2[j, i] = Black;
}
else
{
if ((((V2 - V1) * s) + ((S1 - S2) * v) + (V1 * S2 - S1 * V2)) > 0)
GreyImg_2[j, i] = Black;
}
}
}
}
}
}
return GreyImg_2;
}
private Image<Gray, Byte> Method_HSV(Image<Hsv, byte> image)
{ LineSegment2D[] Lines = // Points depend on each hue
{ new LineSegment2D ( new Point (32,243), new Point (64,255)),
new LineSegment2D ( new Point (64,16), new Point (32,64)), };
Vmax = 255;
Vmin = 16;
Smax = 64;
Smin = 32;
// Normalise each pixel of the image and return a new image
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
Gray = GreyImg_2[j, i].Intensity;
V = image[j, i].Value; // Checks the Brightness
S = image[j, i].Satuation; // Decides intensity of the colour
H = image[j, i].Hue; // Decides the Colour
int s = (int)S;
int v = (int)V;
if (H > 10 && H < 135) // Check for not RED
{
GreyImg_2[j, i] = Black;
}
else
{// Check horizontal and vertical lines
if (Vmax < V || V < Vmin || S < Smin)
GreyImg_2[j, i] = Black;
else if (S > Smax)
GreyImg_2[j, i] = White;
else
{// use table XI
GreyImg_2[j, i] = White;
for (int n = 0; n < Lines.Length; n++) // number of lines
{
int S1 = Lines[n].P1.X;
int V1 = Lines[n].P1.Y;
int S2 = Lines[n].P2.X;
int V2 = Lines[n].P2.Y;
if ((V2 - V1) > 0)
{
if ((((V2 - V1) * s) + ((S1 - S2) * v) + (V1 * S2 - S1 * V2)) < 0)
GreyImg_2[j, i] = Black;
}
else
{
if ((((V2 - V1) * s) + ((S1 - S2) * v) + (V1 * S2 - S1 * V2)) > 0)
GreyImg_2[j, i] = Black;
}
}
}
}
}
}
return GreyImg_2;
}
Comment