コード例 #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();
    }
  }
コード例 #2
0
  @Override
  public IplImage process(IplImage img) {

    /*
    		if(convertFromColor) {
    			imageConversion.convertFromRGB(img, grayImage);
    		} else {
    			imageConversion.convertFromGray(img, grayImage);
    		}
    */

    blur.apply(grayImage, blurImage);
    IplImage bkImage = background.update(blurImage);
    if (bkImage == null) return null;

    ImageDifference.apply(bkImage, blurImage, diffImage);

    thresh.apply(diffImage, threshImage);

    synchronized (blobs) {
      Vector<Blob> allBlobs = new Vector<Blob>(newFrameBlobs.size());
      // probably should come up with some kind of double (or triple buffer) for this rather than
      // re-allocating vectors every frame
      blobs.detectBlobs(threshImage2.getData());
      for (int i = 0; i < regionMap.size(); i++) {
        Vector<Blob> detected = blobs.getDetectedBlobs(i);
        Vector<Blob> newBlobs = new Vector<Blob>(detected.size());
        newBlobs.addAll(detected);
        allBlobs.addAll(detected);
        tracker[i].queueBlobs(newBlobs);
      }
      newFrameBlobs = allBlobs;
    }

    switch (mode) {
      case raw:
        return img;
      case background:
        return bkImage;
      case diff:
        return diffImage;
      case thresh:
      case running:
        return threshImage2;
      default:
        return img;
    }
  }