I am trying to compare two different images using resemble.js 
<https://huddle.github.io/Resemble.js/>, but I keep seeing the following 
issues. On the first attempt, I get the following error message: Error: 
undefined is not an object (evaluating 'a.result.rawMisMatchPercentage'). 
One the second attempt, I get a set of results. On occasion, after this the 
set of results appears to be stuck. Furthermore, on a general, the entire 
process seems to be lagging slightly. How do I:

1) Stop the error message appearing on the first iteration.

2) Stop the results getting stuck on subsequent iterations.

3) Optimise the code to improve the general speed of the process.

This is my code:

function findRecommendations(file, products) {
  var responseCount = 0;
  var callback = function(product, base64Img) {
    var uploadedSneaker = base64Img;
    var cachedSneaker = file.data;
    var diff = 
resemble(uploadedSneaker).compareTo(cachedSneaker).onComplete(function(result) 
{ // jshint ignore:line
      product.result = result;
    });
    diff.scaleToSameSize();
    diff.ignoreAntialiasing();
    diff.ignoreColors();
  };
  for(var i = 0; i < products.length; i++) {
    createBase64Property(products[i], callback);
    if(++responseCount === products.length) {
      products.sort(function(a, b) {
        return a.result.rawMisMatchPercentage - b.result.rawMisMatchPercentage;
      });
      return products.slice(0, 3);
    }
  }}
function createBase64Property(product, callback, outputFormat) {
  var img = new Image();
  img.crossOrigin = 'Anonymous';
  img.onload = function() {
    var canvas = document.createElement('CANVAS');
    var ctx = canvas.getContext('2d');
    var dataURL;
    canvas.height = this.height;
    canvas.width = this.width;
    ctx.drawImage(this, 0, 0);
    dataURL = canvas.toDataURL(outputFormat);
    callback(product, dataURL);
  };
  img.src = product.imageUrl;
  if (img.complete || img.complete === undefined) {
    img.src = 
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
    img.src = product.imageUrl;
  }}

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to