Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Results are always the same #5

Open
DWboutin opened this issue Nov 2, 2017 · 2 comments
Open

Results are always the same #5

DWboutin opened this issue Nov 2, 2017 · 2 comments

Comments

@DWboutin
Copy link

DWboutin commented Nov 2, 2017

I'm creating an application to compare one image to multiples images in a folder. I'm creating this application with Electron and React.

I pass 2 Buffers. As you can see, the Buffers are the same at the first entry, but it gives the same results.
capture d ecran 2017-11-02 a 11 26 40

There's how I use rembrandt:

        let mainImg = fs.readFileSync('/Users/mboutin2/Desktop/12798992_10207498962925066_4475804348577634517_n.jpg');

        data.forEach((file) => {
          smb2Client.readFile('Mike\\' + file, function(err, data){
            if(err) {
              console.log("Error (readdir):\n", err);
              console.log("data", data);
            } else {
              //console.log("File ->", file);

              const rembrandt = new Rembrandt({
                // `imageA` and `imageB` can be either Strings (file path on node.js,
                // public url on Browsers) or Buffers
                imageA: mainImg,
                imageB: data,

                // Needs to be one of Rembrandt.THRESHOLD_PERCENT or Rembrandt.THRESHOLD_PIXELS
                thresholdType: Rembrandt.THRESHOLD_PERCENT,

                // The maximum threshold (0...1 for THRESHOLD_PERCENT, pixel count for THRESHOLD_PIXELS
                maxThreshold: 1,

                // Maximum color delta (0...255):
                maxDelta: 20,

                // Maximum surrounding pixel offset
                maxOffset: 0,

                renderComposition: false, // Should Rembrandt render a composition image?
              });

              rembrandt.compare()
                .then(function (result) {
                  console.log('\n\n\n');
                  console.log(data);
                  console.log(mainImg);
                  console.log('Passed:', result.passed)
                  console.log('Pixel Difference:', result.differences, 'Percentage Difference', result.percentageDifference, '%')
                  console.log('Composition image buffer:', result.compositionImage)

                  // Note that `compositionImage` is an Image when Rembrandt.js is run in the browser environment
                })
                .catch((e) => {
                  console.error(e)
                })
            }
          });
        });

Is there something I do wrong?

@saturday1
Copy link

saturday1 commented Jan 24, 2018

Did you get this to work? I do only get that they are not the same image, but they are. Here is my test: http://cdn.axiell.com/~dev/gota/image-test/html-template.html

I use this code:

<html>
<head>
	<title></title>
</head>
<body>
  <img src="01.jpg" class="image1">
  <img src="02.jpg" class="image2">
  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="rembrandt.min.js"></script>
  <script>
    const rembrandt = new Rembrandt({
      // `imageA` and `imageB` can be either Strings (file path on node.js,
      // public url on Browsers) or Buffers
      imageA: $('.image1').attr('src'),
      imageB: $('.image2').attr('src'),

      thresholdType: Rembrandt.THRESHOLD_PERCENT,

      // The maximum threshold (0...1 for THRESHOLD_PERCENT, pixel count for THRESHOLD_PIXELS
      maxThreshold: 0,

      // Maximum color delta (0...255):
      maxDelta: 0,

      // Maximum surrounding pixel offset
      maxOffset: 0,

    })

    // Run the comparison
    rembrandt.compare()
      .then(function (result) {

        if(result.passed){
          alert('Yes');
        } else {
          alert('No');
        }
  })
  </script>
</body>
</html>

@saturday1
Copy link

I seems to have solved this part. I made maxDelta: 20 and it started to set "passed" to correct value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants