Ask Your Question

Revision history [back]

js cascadeclassifier load always empty

I am trying to load the pretrained models. I am using Vue and the XML is in the public directory

public/models/haarcascades/*

I can load it using axios.get() I then can create a new File() using the data from the get

But no matter what I do, I can not get the classifier not be empty. What is the search path used by classifier? is it local file access or network? If local file then I could use my new File()

    let classifier = new cv2.CascadeClassifier();

    // load pre-trained classifiers
    let b = classifier.load('/models/haarcascades/haarcascade_frontalface_default.xml');
    console.log('NNLOAD', b, classifier.empty())
    let faces = new cv2.RectVector();
    //console.log(faces)
      //InterpolationFlags
    try {
      classifier.detectMultiScale(gray, faces, 1.1, 3, 0)
      console.log('FACE',faces, faces.size(), faces.get(0))
    }
    catch(err) {
      console.log('FERR',err);
    }

```

js cascadeclassifier load always empty

I am trying to load the pretrained models. I am using Vue and the XML is in the public directory

public/models/haarcascades/*

I can load it using axios.get() I then can create a new File() using the data from the get

But no matter what I do, I can not get the classifier not be empty. What is the search path used by classifier? is it local file access or network? If local file then I could use my new File()

    let classifier = new cv2.CascadeClassifier();

    // load pre-trained classifiers
    let b = classifier.load('/models/haarcascades/haarcascade_frontalface_default.xml');
    console.log('NNLOAD', b, classifier.empty())
    let faces = new cv2.RectVector();
    //console.log(faces)
      //InterpolationFlags
    try {
      classifier.detectMultiScale(gray, faces, 1.1, 3, 0)
      console.log('FACE',faces, faces.size(), faces.get(0))
    }
    catch(err) {
      console.log('FERR',err);
    }

`````` To test each path I did the following. I know that I need the correct path. That is my question., is there a default path? Where does opencv js look for the files?

  let b = classifier.load('/public/models/haarcascades/haarcascade_frontalface_default.xml')
  console.log('CLASS', process.env.BASE_URL, b, classifier.empty())
  b = classifier.load('/models/haarcascades/haarcascade_frontalface_default.xml')
  console.log('CLASS', process.env.BASE_URL, b, classifier.empty())
  b = classifier.load('models/haarcascades/haarcascade_frontalface_default.xml')
  console.log('CLASS', process.env.BASE_URL, b, classifier.empty())
  b = classifier.load('../../public/models/haarcascades/haarcascade_frontalface_default.xml')
  console.log('CLASS', process.env.BASE_URL, b, classifier.empty())
  b = classifier.load('public/models/haarcascades/haarcascade_frontalface_default.xml')
  console.log('CLASS', process.env.BASE_URL, b, classifier.empty())
  b = classifier.load('haarcascade_frontalface_default.xml')
  console.log('CLASS', process.env.BASE_URL, b, classifier.empty())

They all returned false and .empty() true.