Ask Your Question
0

Error received on cvLoadHaarClassifierCascade() function

asked 2017-04-30 16:28:57 -0500

ertan gravatar image

updated 2017-04-30 16:31:57 -0500

Hello,

Using OpenCV 2.4.13 (64bit) on a Windows 10 system.

When using subject function to load my own trained cascade.xml file, I am getting below error:

OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file C:\builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\core\src\persistence.cpp, line 5008

I couldn't understand what I am doing wrong. I have tried two different format of the cascade.xml (one is old format). Both failing.

My cascade.xml files are as follows (couldn't provide links as my karma points are not sufficient):

original format cascade.xml:

<?xml version="1.0"?>
<opencv_storage>
<cascade>
  <stageType>BOOST</stageType>
  <featureType>HAAR</featureType>
  <height>48</height>
  <width>48</width>
  <stageParams>
    <boostType>GAB</boostType>
    <minHitRate>9.9900001287460327e-001</minHitRate>
    <maxFalseAlarm>5.0000000000000000e-001</maxFalseAlarm>
    <weightTrimRate>9.4999999999999996e-001</weightTrimRate>
    <maxDepth>1</maxDepth>
    <maxWeakCount>100</maxWeakCount></stageParams>
  <featureParams>
    <maxCatCount>0</maxCatCount>
    <featSize>1</featSize>
    <mode>BASIC</mode></featureParams>
  <stageNum>1</stageNum>
  <stages>
    <!-- stage 0 -->
    <_>
      <maxWeakCount>2</maxWeakCount>
      <stageThreshold>0.</stageThreshold>
      <weakClassifiers>
        <_>
          <internalNodes>
            0 -1 1 4.8126034438610077e-002</internalNodes>
          <leafValues>
            -9.9589323997497559e-001 1.</leafValues></_>
        <_>
          <internalNodes>
            0 -1 0 -1.1564785242080688e-001</internalNodes>
          <leafValues>
            1. -1.</leafValues></_></weakClassifiers></_></stages>
  <features>
    <_>
      <rects>
        <_>
          0 8 16 36 -1.</_>
        <_>
          0 8 8 18 2.</_>
        <_>
          8 26 8 18 2.</_></rects>
      <tilted>0</tilted></_>
    <_>
      <rects>
        <_>
          30 27 15 9 -1.</_>
        <_>
          35 27 5 9 3.</_></rects>
      <tilted>0</tilted></_></features></cascade>
</opencv_storage>

old format cascade.xml:

<?xml version="1.0"?>
<opencv_storage>
<cascade>
  <size>
    48 48</size>
  <stages>
    <_>
      <trees>
        <_>
          <_>
            <feature>
              <rects>
                <_>
                  30 27 15 9 -1.</_>
                <_>
                  35 27 5 9 3.</_></rects>
              <tilted>0</tilted></feature>
            <threshold>4.8126034438610077e-002</threshold>
            <left_val>-9.9589322381930179e-001</left_val>
            <right_val>1.</right_val></_></_>
        <_>
          <_>
            <feature>
              <rects>
                <_>
                  0 8 16 36 -1.</_>
                <_>
                  0 8 8 18 2.</_>
                <_>
                  8 26 8 18 2.</_></rects>
              <tilted>0</tilted></feature>
            <threshold>-1.1564785242080688e-001</threshold>
            <left_val>1.</left_val>
            <right_val>-1.</right_val></_></_></trees>
      <stage_threshold>0.</stage_threshold>
      <parent>-1</parent>
      <next>-1</next></_></stages></cascade>
</opencv_storage>

As it may be relevant, you can find my cascade training command line and output is below. Please ignore baseFormatSave parameter. I put it for test purposes:

C:\training>opencv_traincascade -data c:\training\data -vec c:\training\my.vec -bg c:\training\bg.txt -numPos 7 -numNeg 486 -numStages 1 -w 48 -h 48 -minHitRate 0.999 -baseFormatSave
PARAMETERS:
cascadeDirName: c:\training\data
vecFileName: c:\training\my.vec
bgFileName: c:\training\bg.txt
numPos: 7
numNeg: 486
numStages: 1
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 48
sampleHeight: 48
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
Number of unique features given windowSize [48,48] : 2570880

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   7 : 7
NEG count : acceptanceRatio    486 : 1
Precalculation time: 8.279 ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-05-01 00:55:48 -0500

berak gravatar image

opencv's c-api is dead / no more maintained since 2010, you simply must not use it

cvLoadHaarClassifierCascade() cannot read files generated from opencv_traincascade, please use the c++ CascadeClassifier instead.

then, 7 positive images are definitely not enough to do something successful here, try to get like 700....

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-04-30 16:28:57 -0500

Seen: 145 times

Last updated: May 01 '17