Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target not detected #2

Closed
mkaouri opened this issue Feb 13, 2017 · 2 comments
Closed

Target not detected #2

mkaouri opened this issue Feb 13, 2017 · 2 comments

Comments

@mkaouri
Copy link

mkaouri commented Feb 13, 2017

Hi, everything is looking fine on Android, camera and opencv library are loaded, except detecting a target image. I tried to change targets and used png & jpg but no luck. Also image data is loaded to app but the image features detection is not working. Below is the javascript code.
Appreciate your help.

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
    
var imgDetectionPlugin = window.plugins.ImageDetectionPlugin || new ImageDetectionPlugin();

imgDetectionPlugin.startProcessing(true, function(success){console.log(success);}, function(error){console.log(error);});

imgDetectionPlugin.isDetecting(function(success){
  console.log(success);
  var resp = JSON.parse(success);
  console.log(resp.index, "image detected - ", indexes[resp.index]);
}, function(error){console.log(error);});

function setAllPatterns(patterns) {
  imgDetectionPlugin.setPatterns(patterns, function(success){console.log(success);}, function(error){console.log(error);});
}

var loadAllImg = 0;
var patternsHolder = [];
var indexes = {};
var limit = 1;

function ToDataURL (self) {
  var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');
  var dataURL;
  canvas.height = self.height;
  canvas.width = self.width;
  ctx.drawImage(self, 0, 0);
  dataURL = canvas.toDataURL("image/jpeg", 0.8);
  //console.log(dataURL);
  patternsHolder.push(dataURL);
  indexes[loadAllImg] = self.src.substr(self.src.lastIndexOf("/") + 1);
  loadAllImg += 1;
  console.log("!!!", loadAllImg, indexes);
  if(loadAllImg == limit){
    console.log("patterns set", patternsHolder);
    setAllPatterns(patternsHolder);
  }
  canvas = null;
}

var img = new Image();
img.crossOrigin = "Anonymous";
img.onload = function(){
  ToDataURL(this)
};
img.src = "img/koclogo.png";

imgDetectionPlugin.setDetectionTimeout(2, function(success){console.log(success);}, function(error){console.log(error);});
    }
};

app.initialize();
@mkaouri
Copy link
Author

mkaouri commented Feb 13, 2017

Finally, it works with other images. It seems that images should have good quality of features.

@a31859
Copy link
Contributor

a31859 commented Feb 13, 2017

Sorry for the late response @mkaouri, glad you managed to get it to work
Yes the plugin is using openCV feature matching to do the detection of similar images so the more rich in features the image is, the more likely it is for it to find a match

@a31859 a31859 closed this as completed Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants