Пример #1
0
  private void compareImages() {
    for (int row = 0; row < image1.height(); row++) {
      for (int cell = 0; cell < image1.width(); cell++) {

        CvScalar rgbBack = cvGet2D(image1, row, cell);
        double b_back = rgbBack.getVal(0) + 100;
        double g_back = rgbBack.getVal(1) + 100;
        double r_back = rgbBack.getVal(2) + 100;

        CvScalar rgb_Obj = cvGet2D(image2, row, cell);
        double b_obj = rgb_Obj.getVal(0);
        double g_obj = rgb_Obj.getVal(1);
        double r_obj = rgb_Obj.getVal(2);

        double r_diff = r_back + r_obj - 2 * r_obj; // Math.min(r_back, r_obj );
        double g_diff = g_back + g_obj - 2 * r_obj; // Math.min(g_back, g_obj );
        double b_diff = b_back + b_obj - 2 * r_obj; // Math.min(b_back, b_obj );

        CvScalar rgb = CV_RGB(r_diff, g_diff, b_diff);
        cvSet2D(diff, row, cell, rgb);

        double bl_diff = (r_diff + g_diff + b_diff) / 3;

        CvScalar bl_pix = CV_RGB(bl_diff, bl_diff, bl_diff);
        cvSet2D(diff_black, row, cell, bl_pix);
      }
    }
  }
Пример #2
0
  private void process(int x, int y, int lenght) {
    vals = new ArrayList<Map<String, Double>>();
    for (int row = 0; row < height; row++) {
      for (int cell = 0; cell < width; cell++) {
        if (row == y && (cell > x && cell < x + lenght)) {

          CvScalar rgb1 = cvGet2D(image1, row, cell);
          double b_1 = rgb1.getVal(0);
          double g_1 = rgb1.getVal(1);
          double r_1 = rgb1.getVal(2);

          CvScalar rgb2 = cvGet2D(image2, row, cell);
          double b_2 = rgb2.getVal(0);
          double g_2 = rgb2.getVal(1);
          double r_2 = rgb2.getVal(2);

          CvScalar rgb3 = cvGet2D(diff, row, cell);
          double b_3 = rgb3.getVal(0);
          double g_3 = rgb3.getVal(1);
          double r_3 = rgb3.getVal(2);

          Map<String, Double> mp = new HashMap<String, Double>();
          mp.put("b_1", b_1);
          mp.put("g_1", g_1);
          mp.put("r_1", r_1);

          mp.put("b_2", b_2);
          mp.put("g_2", g_2);
          mp.put("r_2", r_2);

          mp.put("diff", Math.abs((b_1 - b_2) + (g_1 - g_2) + (r_1 - r_2)));
          mp.put("b_3", b_3);
          mp.put("g_3", g_3);
          mp.put("r_4", r_3);

          vals.add(mp);

          drawPoint(image1_line, cell, row);
          drawPoint(image2_line, cell, row);
          drawPoint(diff_line, cell, row);
          drawPoint(diff_black, cell, row);
        }
      }
    }
  }