Coder Social home page Coder Social logo

Comments (7)

mrnugget avatar mrnugget commented on August 16, 2024

I'd be interested in that too. I also tried HAAR.js, but as @ludovicpages said: the output is different. And HAAR.js does not work with newer XML cascade files (generated by opencv_traincascade, instead of the deprecated opencv_haartraining).

from js-objectdetect.

robertonr avatar robertonr commented on August 16, 2024

I have what you need, check the following python code:

import xml.etree.ElementTree as ET
import sys


name = sys.argv[1]
tilted = False
size = "0,0"
tree = ET.parse('%s.xml' % name)
sys.stdout.write('var %s = {complexClassifiers:[' % name)
root = tree.getroot()
for n in root:
    size = n.find('size').text.replace(' ', ',')
    stages = n.find('stages')
    ccs = ''
    for s in stages:
        sys.stdout.write('%s{simpleClassifiers:[' % (ccs))
        trees = s.find('trees')
        scs = ''
        for t2 in trees:
            sys.stdout.write('%s{features:[' % scs)
            scs = ','
            for t in t2:
                feature = t.find('feature')
                scf = ''
                for r in feature.find('rects'):
                    sys.stdout.write('%s[%s]' % (scf, r.text.replace(' ', ',')))
                    scf = ','
                tilted = tilted | (feature.find('tilted').text == '1')
                threshold = t.find('threshold').text
                right_val = t.find('right_val').text
                left_val = t.find('left_val').text
                sys.stdout.write('],threshold:%s,right_val:%s,left_val:%s}' % (threshold, right_val, left_val))
        sys.stdout.write(']}')
        ccs = ','
sys.stdout.write('],size:[%s],tilted:%s};\n' % (size, 'true' if tilted else 'false'))
sys.stdout.flush()

from js-objectdetect.

mrnugget avatar mrnugget commented on August 16, 2024

Thanks a lot for this @robertonr!

from js-objectdetect.

mrnugget avatar mrnugget commented on August 16, 2024

Does anyone have an idea if it's possible to convert the newer classifier formats, produced by opencv_traincascade as opposed to opencv_haartraining, to JavaScript and get it to work with this library?

from js-objectdetect.

mtschirs avatar mtschirs commented on August 16, 2024

@robertonr: Thanks for sharing your code!
@mrnugget: This library only handles stump-based cascaded. As long as opencv_traincascade can be configured to produce those, they should be compatible (probably with minor adaptions).

from js-objectdetect.

mtschirs avatar mtschirs commented on August 16, 2024

Here is a custom script to convert the new OpenCV xml format haarcascades produced by opencv_traincascade: https://gist.github.com/mtschirs/df8d8dc5ff56cc7187b1

from js-objectdetect.

HoracioEspinosa avatar HoracioEspinosa commented on August 16, 2024

how i can convert my haarcascade in opencv 2.4 version with a similar python code? :( thanks

from js-objectdetect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.