Search code examples
opencvcascadejavacvhaar-classifier

opencv cascade.xml format


I've just generated using opencv_traincascade.exe (opencv 2.4.11 (vc10)) cascade.xml file.

Then when I try to use it in javacv 0.8 (and 1.0 too), I get this error:

OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) 
in cvRead, file ..\..\..\..\opencv\modules\core\src\persistence.cpp, line 4991
Exception in thread "main" java.lang.RuntimeException:
 ..\..\..\..\opencv\modules\core\src\persistence.cpp:4991: error: (-2) The node does not represent a user      object (unknown type?) in function cvRead

Windows PATH variable looks to the folder, which consists my opencv_traincascade.exe. So I try to use cacade.xml by library, which made it.

I also have another cascade.xml, which works fine. I found the difference between to cascades:

Working:

<opencv_storage>
    <haarcascade_frontalface_default type_id="opencv-haar-classifier">
        <size>24 24</size>
            <stages>
                 <trees>
                    ...  some tags for one stage
                 </trees>
            </stages>
    </haarcascade_frontalface_default>
</opencv_storage>

Don't working:

<opencv_storage>
   <cascade>
   <stageType>BOOST</stageType>
   <featureType>HAAR</featureType>
   <height>20</height>
   <width>20</width>
   <stageParams>
      <boostType>GAB</boostType>
      <minHitRate>9.9000000953674316e-001</minHitRate>
      <maxFalseAlarm>4.0000000596046448e-001</maxFalseAlarm>
      <weightTrimRate>9.4999999999999996e-001</weightTrimRate>
      <maxDepth>1</maxDepth>
      <maxWeakCount>100</maxWeakCount>
   </stageParams>
   <featureParams>
      <maxCatCount>0</maxCatCount>
      <featSize>1</featSize>
      <mode>ALL</mode>
   </featureParams>
   <stageNum>16</stageNum>
   <stages>
      <!-- stage 0 -->
       <_>
       <maxWeakCount>1</maxWeakCount>
       <stageThreshold>1.</stageThreshold>
       <weakClassifiers>
        <_>
      <internalNodes>
        0 -1 1 -2.3408320546150208e-001</internalNodes>
      <leafValues>
        1. -1.</leafValues></_></weakClassifiers></_>
      <!-- stage 1 -->
      .... //16 stages
      <features>
      .... // a lot of "rect" tags
      </features>
  </cascade>
</opencv_storage>

Everybody can notice, that the structures are different. I guess, this is the reason of the error.

What I'm doing wrong? How can I use my cascade.xml?


Solution

  • Yes, the problem was that I used javacv methods, which use old cascade xml format. Using c++ - everything works. Thank you, berak!