2014-06-27 29 views
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特性中進行縮放? 請幫我

回答

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。,「An extended set of Haar-like features for rapid object detection」,ICIP02,pp.I:900-903,2002。