Ejemplo n.º 1
0
  protected void processImage(byte[] data, int width, int height) {
    // First, downsample our image and convert it into a grayscale IplImage
    int f = SUBSAMPLING_FACTOR;
    if (grayImage == null || grayImage.width() != width / f || grayImage.height() != height / f) {
      grayImage = IplImage.create(width / f, height / f, IPL_DEPTH_8U, 1);
    }
    int imageWidth = grayImage.width();
    int imageHeight = grayImage.height();
    int dataStride = f * width;
    int imageStride = grayImage.widthStep();
    ByteBuffer imageBuffer = grayImage.getByteBuffer();
    for (int y = 0; y < imageHeight; y++) {
      int dataLine = y * dataStride;
      int imageLine = y * imageStride;
      for (int x = 0; x < imageWidth; x++) {
        imageBuffer.put(imageLine + x, data[dataLine + f * x]);
      }
    }

    cvClearMemStorage(storage);
    faces = cvHaarDetectObjects(grayImage, classifier, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING);
    postInvalidate();
  }