0

这是我的代码

import java.awt.image.BufferedImage;

public class HaarFeature {
    public static void GetFeature(BufferedImage image){
        int width  = image.getWidth();
        int height = image.getHeight();
        //int feature_width=1*scale_width;
        //int feature_height=1*scale_height;
        int[][] iI = IntegralImage.convIntegralImage(image);
        int white=0;
        int black=0;
        int feature=0;
        for(int i=0;i<height;i++){
            for(int j=0;j<width;j++){
                if(i<(height-1) && j<(width-3)){
                    if(i==0 && j==0){
                        black=iI[i][j+3];
                        white=iI[i+1][j+3]-iI[i][j+3];
                        feature=black-white;
                        System.out.print(feature+" ");
                    }
                    else if(i==0){
                        black=iI[i][j+3]-iI[i][j-1];
                        white=iI[i+1][j+3]+iI[i][j-1]-iI[i][j+3]-iI[i+1][j-1];
                        feature=black-white;
                        System.out.print(feature+" ");
                    }
                    else if(j==0){
                        black=iI[i][j+3]-iI[i-1][j+3];
                        white=iI[i+1][j+3]-iI[i][j+3];
                        feature=black-white;
                        System.out.print(feature+" ");
                    }
                    else{
                        black=iI[i][j+3]+iI[i-1][j-1]-iI[i][j-1]-iI[i-1][j+3];
                        white=iI[i+1][j+3]+iI[i][j-1]-iI[i][j+3]-iI[i+1][j-1];
                        feature=black-white;
                        System.out.print(feature+" ");
                    }
                }
            }
            System.out.println();
        }

    }
}

这段代码只生成一个 2px x 4px 的矩形特征。据我所知,haar 特征中有很多矩形特征。如何编写代码以扩展 haar 功能?请帮我

4

1 回答 1

0

我可以帮助你,但我用 C++ 编程,检查 mi 代码以生成 haar 功能:

int sizeX = feature[i][0];
int sizeY = feature[i][1];
// Each position:
for (int x = 0; x <= frameSize-sizeX; x++) {
    for (int y = 0; y <= frameSize-sizeY; y++) {
        // Each size fitting within the frameSize:
        for (int width = sizeX; width <= frameSize-x; width+=sizeX) {
            for (int height = sizeY; height <= frameSize-y; height+=sizeY) {
                count++;

                     }

                }
           }

    }

此代码给出了 Lienhart, R. 和 Maydt, J. 的文章中显示的正确数量的特征,“用于快速对象检测的 Haar 类特征的扩展集”,ICIP02,第 I:900–903,2002。

于 2014-10-20T22:12:10.063 回答