1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| int CImageProcessing::HSV_Thresholding(IplImage* src_HSV, IplImage*
dst_gray)
{
int x,y;
char* MyImageData = m_pImage_gray->imageData ;
int MyStep = m_pImage_gray->widthStep ;
char* MyHSVImageData = src_HSV->imageData ;
int MyHSVStep = src_HSV->widthStep ;
for (y=269;y>=0;--y)
for (x=width-1;x>=0;--x)
{
Hue = ((uchar*)(MyHSVImageData + MyHSVStep*y))[x*3];
Saturation = ((uchar*)(MyHSVImageData + MyHSVStep*y))[x*3+1];
Value = ((uchar*)(MyHSVImageData + MyHSVStep*y))[x*3+2];
if ( ((Hue>H_Threshold_large) && (Hue<180-H_Threshold_large))
|| (Saturation<S_Threshold_large)
|| (Value<V_Threshold_large) )
{
((uchar*)(MyImageData + MyStep*y))[x] = 0 ;
}
else if ( ((Hue>H_Threshold) && (Hue<180-H_Threshold))
|| (Saturation<S_Threshold)
|| (Value<V_Threshold) )
{
((uchar*)(MyImageData + MyStep*y))[x] = 125 ;
}
else
{
((uchar*)(MyImageData + MyStep*y))[x] = 255 ;
}
}
return 0;
} |
Partager