private Map<RenderingHints.Key, Object> retrieveRenderingHints() {
   if (!renderingHints.isEmpty()
       && (imageProcessing.equals(ImageProcessing.NONE) || verifyNull(imageProcessing))) {
     return renderingHints;
   } else if (verifyNotNull(imageProcessing)
       && !imageProcessing.equals(ImageUtils.ImageProcessing.NONE)) {
     return generateRenderingHintsBasedOnProperties(this.imageProcessing);
   }
   return Collections.emptyMap();
 }
Beispiel #2
0
  public void run() {
    System.out.println("Start MainTask");

    for (int i = 0; i < TaskHolder.getTaskSize(); i++) {
      TaskHolder.getTaskByIndex(i).start();
    }

    BufferedImage[][] smallImages = new BufferedImage[3][2];

    imageProcessor = new ImageProcessing();
    imageProcessor.CreateNewImage(0, 3071, 0, 1535);
    smallImages = imageProcessor.DivideImage(imageProcessor.getFinalImage(), 3, 2);
    for (int i = 0; i < TaskHolder.getTaskSize(); i++) {
      if (i == 1) {
        sendImageRange(i, smallImages[0][1]);
      } else if (i == 3) {
        sendImageRange(i, smallImages[1][1]);
      } else if (i == 5) {
        sendImageRange(i, smallImages[2][1]);
      } else if (i == 0) {
        sendImageRange(i, smallImages[0][0]);
      } else if (i == 2) {
        sendImageRange(i, smallImages[1][0]);
      } else if (i == 4) {
        sendImageRange(i, smallImages[2][0]);
      }
    }

    try {
      System.out.println("Waiting for Tasks!");
      for (int i = 0; i < TaskHolder.getTaskSize(); i++) {
        // System.out.println(String.format("Waiting for Task %d!", i));
        TaskHolder.getTaskByIndex(i).join();
        // System.out.println(String.format("Task %d finished!", i));
      }
    } catch (InterruptedException e) {
      notifyAll();
    }
    System.out.println("The image has: " + objectCounter + " objects.");
    System.out.println("Ending MainTask");
  }
        /** {@inheritDoc} */
        @Override
        public void onPreviewFrame(byte[] data, Camera cam) {
          if (data == null) throw new NullPointerException();
          Camera.Size size = cam.getParameters().getPreviewSize();
          if (size == null) throw new NullPointerException();

          if (!processing.compareAndSet(false, true)) return;

          int width = size.width;
          int height = size.height;

          int imgAvg = ImageProcessing.decodeYUV420SPtoRedAvg(data.clone(), height, width);
          // Log.i(TAG, "imgAvg="+imgAvg);
          if (imgAvg == 0 || imgAvg == 255) {
            processing.set(false);
            return;
          }

          int averageArrayAvg = 0;
          int averageArrayCnt = 0;
          for (int i = 0; i < averageArray.length; i++) {
            if (averageArray[i] > 0) {
              averageArrayAvg += averageArray[i];
              averageArrayCnt++;
            }
          }

          int rollingAverage = (averageArrayCnt > 0) ? (averageArrayAvg / averageArrayCnt) : 0;
          TYPE newType = currentType;
          if (imgAvg < rollingAverage) {
            newType = TYPE.RED;
            if (newType != currentType) {
              beats++;
              // Log.d(TAG, "BEAT!! beats="+beats);
            }
          } else if (imgAvg > rollingAverage) {
            newType = TYPE.GREEN;
          }

          if (averageIndex == averageArraySize) averageIndex = 0;
          averageArray[averageIndex] = imgAvg;
          averageIndex++;

          // Transitioned from one state to another to the same
          if (newType != currentType) {
            currentType = newType;
            image.postInvalidate();
          }

          long endTime = System.currentTimeMillis();
          double totalTimeInSecs = (endTime - startTime) / 1000d;
          if (totalTimeInSecs >= 10) {
            double bps = (beats / totalTimeInSecs);
            int dpm = (int) (bps * 60d);
            if (dpm < 30 || dpm > 180) {
              startTime = System.currentTimeMillis();
              beats = 0;
              processing.set(false);
              return;
            }

            // Log.d(TAG,
            // "totalTimeInSecs="+totalTimeInSecs+" beats="+beats);

            if (beatsIndex == beatsArraySize) beatsIndex = 0;
            beatsArray[beatsIndex] = dpm;
            beatsIndex++;

            int beatsArrayAvg = 0;
            int beatsArrayCnt = 0;
            for (int i = 0; i < beatsArray.length; i++) {
              if (beatsArray[i] > 0) {
                beatsArrayAvg += beatsArray[i];
                beatsArrayCnt++;
              }
            }
            int beatsAvg = (beatsArrayAvg / beatsArrayCnt);
            text.setText(String.valueOf(beatsAvg));
            startTime = System.currentTimeMillis();
            beats = 0;
          }
          processing.set(false);
        }