Log in or register to post comments

Transaction succeeds but resultset is empty

September 26, 2016 - 8:15am #1

Hey all,

I'm having an issue with cloud recognition queries.

First, I noticed that images uploaded from mobile device cameras would always fail no matter how close to the target in the db they were; I presumed this was a formatting issue.

To that end: I have written some JS that will take an image file from the user's camera, create a canvas from it, parse that canvas as a new file in the proper format, and then upload that newly-created file for image recognition.

However, after making this change I find that I always get a "success" response from Vuforia servers no matter what image I use and the results array is always empty (even when uploading from desktop with images that worked previously).

Example response: {"query_id":"cb67cc86260f4acdb82c2a7bbfa68afb","results":[],"result_code":"Success"}

I'm not sure how to proceed as mobile cameras consistently fail but it seems reformatting the image file in JS causes some kind of bug on the Vuforia side.

Any thoughts?

Thanks!

EDIT: Here's the JS code if it's helpful:

function formatFile(file) {

    var

      format        = file.type,

      canvas        = document.createElement("canvas").getContext("2d"),

      image         = new Image();

    image.onload = function () {

      canvas.width  = image.width;

      canvas.height = image.height;

      canvas.drawImage(image, 0, 0);

    };

    image.src = URL.createObjectURL(file);

    var

      dataURL = canvas.canvas.toDataURL(format),

      blob    = atob(dataURL.split(',')[1]),

      arr     = [];

    for ( var i = 0; i < blob.length; i++ ) {

      arr.push(blob.charCodeAt(i));

    }

    var

      b = new Blob([new Uint8Array(arr)], {type: format}),

      f = new File([b], "file", { type: format });

    return f;

  }

 

Log in or register to post comments