from 0 to combat opencv N (8) - Integral FIG Solution

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

from 0 to combat opencv N (8) - Integral FIG Solution

FIG quadrature and arbitrary region of the pixel and

1, is integral image point (x, y) on the upper left area of ​​the image and, using the integral image can be arbitrary rectangular region of the image,

Using its four point subtraction of the integrated value of the pixel of this area can be obtained and, summing the image features may be required to accelerate the operation speed,

FIG integral is calculated only once, the subsequent query can be used (in conjunction with the addition and subtraction) of the obtained feature value.

2, the function: integral (image, imageIntegral, CV_32F);

And calculating an arbitrary pixel region:

float integra_rect(Mat& image,int x1,int y1,int x2,int y2)

{

float dst_val = image.at<float>(x2,y2)+ image.at<float>(x1, y1) - image.at<float>(x1, y2) - image.at<float>(x2, y1);

return dst_val;

}

3, the test:


void main()

{

Mat src = imread("2.jpg");

Mat image;

cvtColor(src, image, CV_RGB2GRAY); //原图像是三通道,积分图也是三通道

Mat imageIntegral;

integral(image, imageIntegral, CV_32F); //计算积分图

normalize(imageIntegral, imageIntegral, 0, 255, CV_MINMAX); //归一化,方便显示

Mat imageIntegralNorm;

convertScaleAbs(imageIntegral, imageIntegralNorm); //精度转换为8位int整型



imshow("src", image);

imshow("dst", imageIntegralNorm);

cvWaitKey(0);



}

More attention to micro-channel public number: ML_Study

Guess you like

Origin blog.csdn.net/qq_34106574/article/details/93773403