Ejemplo n.º 1
0
  public BlobTracker(int srcWidth, int srcHeight) {
    super(srcWidth, srcHeight);

    blur = new Blur();

    String mapFileName = ElProps.THE_PROPS.getProperty("regionMap", "regionMap.png");
    regionMap = new RegionMap(mapFileName);

    //			grayImage = new BufferedImage(w,h,BufferedImage.TYPE_USHORT_GRAY);
    grayImage = IplImage.create(w, h, IPL_DEPTH_8U, 1);
    //		scaledImage = new BufferedImage(w,h,BufferedImage.TYPE_USHORT_GRAY);

    diffImage = IplImage.create(w, h, IPL_DEPTH_8U, 1);
    blurImage = IplImage.create(w, h, IPL_DEPTH_8U, 1);
    threshImage = IplImage.create(w, h, IPL_DEPTH_8U, 1);

    background = new BackgroundImage(.001, 15);

    blobs = new Blobs(srcWidth, srcHeight, regionMap);
    tracker = new Tracker[regionMap.size()];
    for (int i = 0; i < regionMap.size(); i++) {
      tracker[i] = new Tracker(ElProps.THE_PROPS, regionMap.getRegion(i));
      tracker[i].start();
    }
  }
Ejemplo n.º 2
0
  /**
   * Receives frame and uses face recognition algorithms to set coordinates of faces
   *
   * @param originalImage
   * @return list of integer arrays, with coordinates and size of faces
   */
  public static List<Integer[]> detect(IplImage originalImage) {

    List<Integer[]> facesList = new ArrayList<Integer[]>();

    IplImage grayImage =
        IplImage.create(originalImage.width(), originalImage.height(), IPL_DEPTH_8U, 1);

    cvCvtColor(originalImage, grayImage, CV_BGR2GRAY);

    CvMemStorage storage = CvMemStorage.create();
    opencv_objdetect.CvHaarClassifierCascade cascade =
        new opencv_objdetect.CvHaarClassifierCascade(cvLoad(CASCADE_FILE));

    CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, 1.1, 1, 0);

    Integer[] coordinates = null;
    for (int i = 0; i < faces.total(); i++) {
      CvRect r = new CvRect(cvGetSeqElem(faces, i));
      coordinates = new Integer[4];
      coordinates[0] = r.x();
      coordinates[1] = r.y();
      coordinates[2] = r.height();
      coordinates[3] = r.width();
      facesList.add(coordinates);
    }
    return facesList;
  }
    @Override
    public void run() {
      try {
        int sw = (int) (w * scale);
        int sh = (int) (h * scale);
        xoffset = (width - sw) / 2;
        yoffset = (height - sh) / 2;
        if (bitmap == null) {
          bitmap = Bitmap.createBitmap(sw, sh, Bitmap.Config.ARGB_8888);
        }
        if (rgbaImage == null) {
          rgbaImage = IplImage.create(sw, sh, IPL_DEPTH_8U, 4);
        }
        if (resizedImage == null) {
          resizedImage = IplImage.create(sw, sh, IPL_DEPTH_8U, 3);
        }

        for (int i = 0; i < 16; i++) {
          int currentFps = fpsCounter.getFPS();
          // System.out.println(currentFps+"/"+fps);
          if (currentFps > 10) {
            Thread.sleep(0, 999999);
            continue;
          }

          if (currentFps < 1) {
            rendering = false;
            return;
          }

          break;
        }

        cvResize(image, resizedImage);
        cvCvtColor(resizedImage, rgbaImage, CV_BGR2RGBA);
        bitmap.copyPixelsFromBuffer(rgbaImage.getByteBuffer());

        draw();

        fpsCounter.addFrameTime();
      } catch (Exception e) {
        Log.e(LOG_TAG, "onImage error " + e.getMessage());
      }

      rendering = false;
    }
Ejemplo n.º 4
0
  public void generatePGMFromPic(String srcPath, String file, String destPath) throws Exception {

    String srcFilePath = srcPath + "/" + file;
    System.out.println("Loading image from " + srcFilePath);
    IplImage origImg = cvLoadImage(srcFilePath);

    // convert to grayscale
    IplImage grayImg = IplImage.create(origImg.width(), origImg.height(), IPL_DEPTH_8U, 1);
    cvCvtColor(origImg, grayImg, CV_BGR2GRAY);

    // scale the grayscale (to speed up face detection)
    IplImage smallImg =
        IplImage.create(grayImg.width() / SCALE, grayImg.height() / SCALE, IPL_DEPTH_8U, 1);
    cvResize(grayImg, smallImg, CV_INTER_LINEAR);

    // equalize the small grayscale
    IplImage equImg = IplImage.create(smallImg.width(), smallImg.height(), IPL_DEPTH_8U, 1);
    cvEqualizeHist(smallImg, equImg);

    CvMemStorage storage = CvMemStorage.create();

    CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad(CASCADE_FILE));
    System.out.println("Detecting faces...");
    CvSeq faces = cvHaarDetectObjects(equImg, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING);
    cvClearMemStorage(storage);
    int total = faces.total();
    System.out.println("Found " + total + " face(s)");
    for (int i = 0; i < total; i++) {
      CvRect r = new CvRect(cvGetSeqElem(faces, i));
      cvSetImageROI(
          origImg, cvRect(r.x() * SCALE, r.y() * SCALE, r.width() * SCALE, r.height() * SCALE));
      IplImage origface = cvCreateImage(cvSize(r.width() * SCALE, r.height() * SCALE), 8, 3);

      IplImage smallface = cvCreateImage(cvSize(120, 120), 8, 3);
      cvCopy(origImg, origface);
      cvResize(origface, smallface, CV_INTER_LINEAR);
      cvSaveImage(destPath + "/" + file + i + ".pgm", smallface);
      cvResetImageROI(origImg);
    }
  }
Ejemplo n.º 5
0
  /**
   * Creates a new image by using img as the color image
   *
   * @param img an 8U1C or 8U3C image (8bit unsigned and 1 or 3 channels)
   */
  public Image(IplImage img) {
    if (img.nChannels() != 1) {
      // color image
      this.color = img;
      this.gray = IplImage.create(color.cvSize(), IPL_DEPTH_8U, 1);
      cvCvtColor(color, gray, CV_BGR2GRAY);
    } else {
      // grayscale image
      this.color = img;
      this.gray = color;
    }

    this.img = gray.clone();
    this.temp = gray.clone();
  }
Ejemplo n.º 6
0
  public IplImage asTotalImage() {
    if (totalImg == null) {
      int sum = hist[0];
      for (int i = 1; i < hist.length; i++) {
        sum += hist[i];
      }

      int height = 512;
      totalImg = IplImage.create(cvSize(hist.length, height), 8, 1);

      cvSetZero(totalImg);
      for (int x = 0; x < hist.length; x++) {
        int val = (int) Math.round(hist[x] * (height / (double) sum));
        cvDrawLine(totalImg, cvPoint(x, height), cvPoint(x, height - val), CvScalar.WHITE, 1, 1, 0);
      }
    }
    return totalImg;
  }
Ejemplo n.º 7
0
  public IplImage asImage() {
    if (img == null) {
      int max = hist[0];
      for (int i = 1; i < hist.length; i++) {
        max = max >= hist[i] ? max : hist[i];
      }

      int height = 100;
      img = IplImage.create(cvSize(hist.length, height), 8, 1);

      cvSetZero(img);
      for (int x = 0; x < hist.length; x++) {
        int val = (int) Math.round(hist[x] * (height / (double) max));
        cvDrawLine(img, cvPoint(x, height), cvPoint(x, height - val), CvScalar.WHITE, 1, 1, 0);
      }
    }
    return img;
  }
Ejemplo n.º 8
0
 public static IplImage createLeafMask(Block root, Dimension imageSize) {
   IplImage mask = IplImage.create(cvSize(imageSize.width, imageSize.height), 8, 1);
   cvSet(mask, CvScalar.BLACK);
   paintLeafMaskRecursively(mask, root);
   return mask;
 }