/OpenCV-2.4.2/modules/objdetect/src/lsvmparser.cpp

# · C++ · 813 lines · 719 code · 50 blank · 44 comment · 243 complexity · b94aff6f3b2ccf2b3e856e1ca71c1d9d MD5 · raw file

  1. #include "precomp.hpp"
  2. #include <stdio.h>
  3. #include "string.h"
  4. #include "_lsvmparser.h"
  5. #include "_lsvm_error.h"
  6. namespace
  7. {
  8. int isMODEL (char *str){
  9. char stag [] = "<Model>";
  10. char etag [] = "</Model>";
  11. if(strcmp(stag, str) == 0)return MODEL;
  12. if(strcmp(etag, str) == 0)return EMODEL;
  13. return 0;
  14. }
  15. int isP (char *str){
  16. char stag [] = "<P>";
  17. char etag [] = "</P>";
  18. if(strcmp(stag, str) == 0)return P;
  19. if(strcmp(etag, str) == 0)return EP;
  20. return 0;
  21. }
  22. int isSCORE (char *str){
  23. char stag [] = "<ScoreThreshold>";
  24. char etag [] = "</ScoreThreshold>";
  25. if(strcmp(stag, str) == 0)return SCORE;
  26. if(strcmp(etag, str) == 0)return ESCORE;
  27. return 0;
  28. }
  29. int isCOMP (char *str){
  30. char stag [] = "<Component>";
  31. char etag [] = "</Component>";
  32. if(strcmp(stag, str) == 0)return COMP;
  33. if(strcmp(etag, str) == 0)return ECOMP;
  34. return 0;
  35. }
  36. int isRFILTER (char *str){
  37. char stag [] = "<RootFilter>";
  38. char etag [] = "</RootFilter>";
  39. if(strcmp(stag, str) == 0)return RFILTER;
  40. if(strcmp(etag, str) == 0)return ERFILTER;
  41. return 0;
  42. }
  43. int isPFILTERs (char *str){
  44. char stag [] = "<PartFilters>";
  45. char etag [] = "</PartFilters>";
  46. if(strcmp(stag, str) == 0)return PFILTERs;
  47. if(strcmp(etag, str) == 0)return EPFILTERs;
  48. return 0;
  49. }
  50. int isPFILTER (char *str){
  51. char stag [] = "<PartFilter>";
  52. char etag [] = "</PartFilter>";
  53. if(strcmp(stag, str) == 0)return PFILTER;
  54. if(strcmp(etag, str) == 0)return EPFILTER;
  55. return 0;
  56. }
  57. int isSIZEX (char *str){
  58. char stag [] = "<sizeX>";
  59. char etag [] = "</sizeX>";
  60. if(strcmp(stag, str) == 0)return SIZEX;
  61. if(strcmp(etag, str) == 0)return ESIZEX;
  62. return 0;
  63. }
  64. int isSIZEY (char *str){
  65. char stag [] = "<sizeY>";
  66. char etag [] = "</sizeY>";
  67. if(strcmp(stag, str) == 0)return SIZEY;
  68. if(strcmp(etag, str) == 0)return ESIZEY;
  69. return 0;
  70. }
  71. int isWEIGHTS (char *str){
  72. char stag [] = "<Weights>";
  73. char etag [] = "</Weights>";
  74. if(strcmp(stag, str) == 0)return WEIGHTS;
  75. if(strcmp(etag, str) == 0)return EWEIGHTS;
  76. return 0;
  77. }
  78. int isV (char *str){
  79. char stag [] = "<V>";
  80. char etag [] = "</V>";
  81. if(strcmp(stag, str) == 0)return TAGV;
  82. if(strcmp(etag, str) == 0)return ETAGV;
  83. return 0;
  84. }
  85. int isVx (char *str){
  86. char stag [] = "<Vx>";
  87. char etag [] = "</Vx>";
  88. if(strcmp(stag, str) == 0)return Vx;
  89. if(strcmp(etag, str) == 0)return EVx;
  90. return 0;
  91. }
  92. int isVy (char *str){
  93. char stag [] = "<Vy>";
  94. char etag [] = "</Vy>";
  95. if(strcmp(stag, str) == 0)return Vy;
  96. if(strcmp(etag, str) == 0)return EVy;
  97. return 0;
  98. }
  99. int isD (char *str){
  100. char stag [] = "<Penalty>";
  101. char etag [] = "</Penalty>";
  102. if(strcmp(stag, str) == 0)return TAGD;
  103. if(strcmp(etag, str) == 0)return ETAGD;
  104. return 0;
  105. }
  106. int isDx (char *str){
  107. char stag [] = "<dx>";
  108. char etag [] = "</dx>";
  109. if(strcmp(stag, str) == 0)return Dx;
  110. if(strcmp(etag, str) == 0)return EDx;
  111. return 0;
  112. }
  113. int isDy (char *str){
  114. char stag [] = "<dy>";
  115. char etag [] = "</dy>";
  116. if(strcmp(stag, str) == 0)return Dy;
  117. if(strcmp(etag, str) == 0)return EDy;
  118. return 0;
  119. }
  120. int isDxx (char *str){
  121. char stag [] = "<dxx>";
  122. char etag [] = "</dxx>";
  123. if(strcmp(stag, str) == 0)return Dxx;
  124. if(strcmp(etag, str) == 0)return EDxx;
  125. return 0;
  126. }
  127. int isDyy (char *str){
  128. char stag [] = "<dyy>";
  129. char etag [] = "</dyy>";
  130. if(strcmp(stag, str) == 0)return Dyy;
  131. if(strcmp(etag, str) == 0)return EDyy;
  132. return 0;
  133. }
  134. int isB (char *str){
  135. char stag [] = "<LinearTerm>";
  136. char etag [] = "</LinearTerm>";
  137. if(strcmp(stag, str) == 0)return BTAG;
  138. if(strcmp(etag, str) == 0)return EBTAG;
  139. return 0;
  140. }
  141. int getTeg(char *str){
  142. int sum = 0;
  143. sum = isMODEL (str)+
  144. isP (str)+
  145. isSCORE (str)+
  146. isCOMP (str)+
  147. isRFILTER (str)+
  148. isPFILTERs (str)+
  149. isPFILTER (str)+
  150. isSIZEX (str)+
  151. isSIZEY (str)+
  152. isWEIGHTS (str)+
  153. isV (str)+
  154. isVx (str)+
  155. isVy (str)+
  156. isD (str)+
  157. isDx (str)+
  158. isDy (str)+
  159. isDxx (str)+
  160. isDyy (str)+
  161. isB (str);
  162. return sum;
  163. }
  164. void addFilter(CvLSVMFilterObject *** model, int *last, int *max){
  165. CvLSVMFilterObject ** nmodel;
  166. int i;
  167. (*last) ++;
  168. if((*last) >= (*max)){
  169. (*max) += 10;
  170. nmodel = (CvLSVMFilterObject **)malloc(sizeof(CvLSVMFilterObject *) * (*max));
  171. for(i = 0; i < *last; i++){
  172. nmodel[i] = (* model)[i];
  173. }
  174. free(* model);
  175. (*model) = nmodel;
  176. }
  177. (*model) [(*last)] = (CvLSVMFilterObject *)malloc(sizeof(CvLSVMFilterObject));
  178. }
  179. void parserRFilter (FILE * xmlf, int p, CvLSVMFilterObject * model, float *b){
  180. int st = 0;
  181. int sizeX=0, sizeY=0;
  182. int tag;
  183. int tagVal;
  184. char ch;
  185. int i,j,ii;
  186. char buf[1024];
  187. char tagBuf[1024];
  188. double *data;
  189. //printf("<RootFilter>\n");
  190. model->V.x = 0;
  191. model->V.y = 0;
  192. model->V.l = 0;
  193. model->fineFunction[0] = 0.0;
  194. model->fineFunction[1] = 0.0;
  195. model->fineFunction[2] = 0.0;
  196. model->fineFunction[3] = 0.0;
  197. i = 0;
  198. j = 0;
  199. st = 0;
  200. tag = 0;
  201. while(!feof(xmlf)){
  202. ch = (char)fgetc( xmlf );
  203. if(ch == '<'){
  204. tag = 1;
  205. j = 1;
  206. tagBuf[j - 1] = ch;
  207. }else {
  208. if(ch == '>'){
  209. tagBuf[j ] = ch;
  210. tagBuf[j + 1] = '\0';
  211. tagVal = getTeg(tagBuf);
  212. if(tagVal == ERFILTER){
  213. //printf("</RootFilter>\n");
  214. return;
  215. }
  216. if(tagVal == SIZEX){
  217. st = 1;
  218. i = 0;
  219. }
  220. if(tagVal == ESIZEX){
  221. st = 0;
  222. buf[i] = '\0';
  223. sizeX = atoi(buf);
  224. model->sizeX = sizeX;
  225. //printf("<sizeX>%d</sizeX>\n", sizeX);
  226. }
  227. if(tagVal == SIZEY){
  228. st = 1;
  229. i = 0;
  230. }
  231. if(tagVal == ESIZEY){
  232. st = 0;
  233. buf[i] = '\0';
  234. sizeY = atoi(buf);
  235. model->sizeY = sizeY;
  236. //printf("<sizeY>%d</sizeY>\n", sizeY);
  237. }
  238. if(tagVal == WEIGHTS){
  239. data = (double *)malloc( sizeof(double) * p * sizeX * sizeY);
  240. size_t elements_read = fread(data, sizeof(double), p * sizeX * sizeY, xmlf);
  241. CV_Assert(elements_read == (size_t)(p * sizeX * sizeY));
  242. model->H = (float *)malloc(sizeof(float)* p * sizeX * sizeY);
  243. for(ii = 0; ii < p * sizeX * sizeY; ii++){
  244. model->H[ii] = (float)data[ii];
  245. }
  246. free(data);
  247. }
  248. if(tagVal == EWEIGHTS){
  249. //printf("WEIGHTS OK\n");
  250. }
  251. if(tagVal == BTAG){
  252. st = 1;
  253. i = 0;
  254. }
  255. if(tagVal == EBTAG){
  256. st = 0;
  257. buf[i] = '\0';
  258. *b =(float) atof(buf);
  259. //printf("<B>%f</B>\n", *b);
  260. }
  261. tag = 0;
  262. i = 0;
  263. }else{
  264. if((tag == 0)&& (st == 1)){
  265. buf[i] = ch; i++;
  266. }else{
  267. tagBuf[j] = ch; j++;
  268. }
  269. }
  270. }
  271. }
  272. }
  273. void parserV (FILE * xmlf, int /*p*/, CvLSVMFilterObject * model){
  274. int st = 0;
  275. int tag;
  276. int tagVal;
  277. char ch;
  278. int i,j;
  279. char buf[1024];
  280. char tagBuf[1024];
  281. //printf(" <V>\n");
  282. i = 0;
  283. j = 0;
  284. st = 0;
  285. tag = 0;
  286. while(!feof(xmlf)){
  287. ch = (char)fgetc( xmlf );
  288. if(ch == '<'){
  289. tag = 1;
  290. j = 1;
  291. tagBuf[j - 1] = ch;
  292. }else {
  293. if(ch == '>'){
  294. tagBuf[j ] = ch;
  295. tagBuf[j + 1] = '\0';
  296. tagVal = getTeg(tagBuf);
  297. if(tagVal == ETAGV){
  298. //printf(" </V>\n");
  299. return;
  300. }
  301. if(tagVal == Vx){
  302. st = 1;
  303. i = 0;
  304. }
  305. if(tagVal == EVx){
  306. st = 0;
  307. buf[i] = '\0';
  308. model->V.x = atoi(buf);
  309. //printf(" <Vx>%d</Vx>\n", model->V.x);
  310. }
  311. if(tagVal == Vy){
  312. st = 1;
  313. i = 0;
  314. }
  315. if(tagVal == EVy){
  316. st = 0;
  317. buf[i] = '\0';
  318. model->V.y = atoi(buf);
  319. //printf(" <Vy>%d</Vy>\n", model->V.y);
  320. }
  321. tag = 0;
  322. i = 0;
  323. }else{
  324. if((tag == 0)&& (st == 1)){
  325. buf[i] = ch; i++;
  326. }else{
  327. tagBuf[j] = ch; j++;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. void parserD (FILE * xmlf, int /*p*/, CvLSVMFilterObject * model){
  334. int st = 0;
  335. int tag;
  336. int tagVal;
  337. char ch;
  338. int i,j;
  339. char buf[1024];
  340. char tagBuf[1024];
  341. //printf(" <D>\n");
  342. i = 0;
  343. j = 0;
  344. st = 0;
  345. tag = 0;
  346. while(!feof(xmlf)){
  347. ch = (char)fgetc( xmlf );
  348. if(ch == '<'){
  349. tag = 1;
  350. j = 1;
  351. tagBuf[j - 1] = ch;
  352. }else {
  353. if(ch == '>'){
  354. tagBuf[j ] = ch;
  355. tagBuf[j + 1] = '\0';
  356. tagVal = getTeg(tagBuf);
  357. if(tagVal == ETAGD){
  358. //printf(" </D>\n");
  359. return;
  360. }
  361. if(tagVal == Dx){
  362. st = 1;
  363. i = 0;
  364. }
  365. if(tagVal == EDx){
  366. st = 0;
  367. buf[i] = '\0';
  368. model->fineFunction[0] = (float)atof(buf);
  369. //printf(" <Dx>%f</Dx>\n", model->fineFunction[0]);
  370. }
  371. if(tagVal == Dy){
  372. st = 1;
  373. i = 0;
  374. }
  375. if(tagVal == EDy){
  376. st = 0;
  377. buf[i] = '\0';
  378. model->fineFunction[1] = (float)atof(buf);
  379. //printf(" <Dy>%f</Dy>\n", model->fineFunction[1]);
  380. }
  381. if(tagVal == Dxx){
  382. st = 1;
  383. i = 0;
  384. }
  385. if(tagVal == EDxx){
  386. st = 0;
  387. buf[i] = '\0';
  388. model->fineFunction[2] = (float)atof(buf);
  389. //printf(" <Dxx>%f</Dxx>\n", model->fineFunction[2]);
  390. }
  391. if(tagVal == Dyy){
  392. st = 1;
  393. i = 0;
  394. }
  395. if(tagVal == EDyy){
  396. st = 0;
  397. buf[i] = '\0';
  398. model->fineFunction[3] = (float)atof(buf);
  399. //printf(" <Dyy>%f</Dyy>\n", model->fineFunction[3]);
  400. }
  401. tag = 0;
  402. i = 0;
  403. }else{
  404. if((tag == 0)&& (st == 1)){
  405. buf[i] = ch; i++;
  406. }else{
  407. tagBuf[j] = ch; j++;
  408. }
  409. }
  410. }
  411. }
  412. }
  413. void parserPFilter (FILE * xmlf, int p, int /*N_path*/, CvLSVMFilterObject * model){
  414. int st = 0;
  415. int sizeX=0, sizeY=0;
  416. int tag;
  417. int tagVal;
  418. char ch;
  419. int i,j, ii;
  420. char buf[1024];
  421. char tagBuf[1024];
  422. double *data;
  423. //printf("<PathFilter> (%d)\n", N_path);
  424. model->V.x = 0;
  425. model->V.y = 0;
  426. model->V.l = 0;
  427. model->fineFunction[0] = 0.0f;
  428. model->fineFunction[1] = 0.0f;
  429. model->fineFunction[2] = 0.0f;
  430. model->fineFunction[3] = 0.0f;
  431. i = 0;
  432. j = 0;
  433. st = 0;
  434. tag = 0;
  435. while(!feof(xmlf)){
  436. ch = (char)fgetc( xmlf );
  437. if(ch == '<'){
  438. tag = 1;
  439. j = 1;
  440. tagBuf[j - 1] = ch;
  441. }else {
  442. if(ch == '>'){
  443. tagBuf[j ] = ch;
  444. tagBuf[j + 1] = '\0';
  445. tagVal = getTeg(tagBuf);
  446. if(tagVal == EPFILTER){
  447. //printf("</PathFilter>\n");
  448. return;
  449. }
  450. if(tagVal == TAGV){
  451. parserV(xmlf, p, model);
  452. }
  453. if(tagVal == TAGD){
  454. parserD(xmlf, p, model);
  455. }
  456. if(tagVal == SIZEX){
  457. st = 1;
  458. i = 0;
  459. }
  460. if(tagVal == ESIZEX){
  461. st = 0;
  462. buf[i] = '\0';
  463. sizeX = atoi(buf);
  464. model->sizeX = sizeX;
  465. //printf("<sizeX>%d</sizeX>\n", sizeX);
  466. }
  467. if(tagVal == SIZEY){
  468. st = 1;
  469. i = 0;
  470. }
  471. if(tagVal == ESIZEY){
  472. st = 0;
  473. buf[i] = '\0';
  474. sizeY = atoi(buf);
  475. model->sizeY = sizeY;
  476. //printf("<sizeY>%d</sizeY>\n", sizeY);
  477. }
  478. if(tagVal == WEIGHTS){
  479. data = (double *)malloc( sizeof(double) * p * sizeX * sizeY);
  480. size_t elements_read = fread(data, sizeof(double), p * sizeX * sizeY, xmlf);
  481. CV_Assert(elements_read == (size_t)(p * sizeX * sizeY));
  482. model->H = (float *)malloc(sizeof(float)* p * sizeX * sizeY);
  483. for(ii = 0; ii < p * sizeX * sizeY; ii++){
  484. model->H[ii] = (float)data[ii];
  485. }
  486. free(data);
  487. }
  488. if(tagVal == EWEIGHTS){
  489. //printf("WEIGHTS OK\n");
  490. }
  491. tag = 0;
  492. i = 0;
  493. }else{
  494. if((tag == 0)&& (st == 1)){
  495. buf[i] = ch; i++;
  496. }else{
  497. tagBuf[j] = ch; j++;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. void parserPFilterS (FILE * xmlf, int p, CvLSVMFilterObject *** model, int *last, int *max){
  504. int st = 0;
  505. int N_path = 0;
  506. int tag;
  507. int tagVal;
  508. char ch;
  509. int /*i,*/j;
  510. //char buf[1024];
  511. char tagBuf[1024];
  512. //printf("<PartFilters>\n");
  513. //i = 0;
  514. j = 0;
  515. st = 0;
  516. tag = 0;
  517. while(!feof(xmlf)){
  518. ch = (char)fgetc( xmlf );
  519. if(ch == '<'){
  520. tag = 1;
  521. j = 1;
  522. tagBuf[j - 1] = ch;
  523. }else {
  524. if(ch == '>'){
  525. tagBuf[j ] = ch;
  526. tagBuf[j + 1] = '\0';
  527. tagVal = getTeg(tagBuf);
  528. if(tagVal == EPFILTERs){
  529. //printf("</PartFilters>\n");
  530. return;
  531. }
  532. if(tagVal == PFILTER){
  533. addFilter(model, last, max);
  534. parserPFilter (xmlf, p, N_path, (*model)[*last]);
  535. N_path++;
  536. }
  537. tag = 0;
  538. //i = 0;
  539. }else{
  540. if((tag == 0)&& (st == 1)){
  541. //buf[i] = ch; i++;
  542. }else{
  543. tagBuf[j] = ch; j++;
  544. }
  545. }
  546. }
  547. }
  548. }
  549. void parserComp (FILE * xmlf, int p, int *N_comp, CvLSVMFilterObject *** model, float *b, int *last, int *max){
  550. int st = 0;
  551. int tag;
  552. int tagVal;
  553. char ch;
  554. int /*i,*/j;
  555. //char buf[1024];
  556. char tagBuf[1024];
  557. //printf("<Component> %d\n", *N_comp);
  558. //i = 0;
  559. j = 0;
  560. st = 0;
  561. tag = 0;
  562. while(!feof(xmlf)){
  563. ch = (char)fgetc( xmlf );
  564. if(ch == '<'){
  565. tag = 1;
  566. j = 1;
  567. tagBuf[j - 1] = ch;
  568. }else {
  569. if(ch == '>'){
  570. tagBuf[j ] = ch;
  571. tagBuf[j + 1] = '\0';
  572. tagVal = getTeg(tagBuf);
  573. if(tagVal == ECOMP){
  574. (*N_comp) ++;
  575. return;
  576. }
  577. if(tagVal == RFILTER){
  578. addFilter(model, last, max);
  579. parserRFilter (xmlf, p, (*model)[*last],b);
  580. }
  581. if(tagVal == PFILTERs){
  582. parserPFilterS (xmlf, p, model, last, max);
  583. }
  584. tag = 0;
  585. //i = 0;
  586. }else{
  587. if((tag == 0)&& (st == 1)){
  588. //buf[i] = ch; i++;
  589. }else{
  590. tagBuf[j] = ch; j++;
  591. }
  592. }
  593. }
  594. }
  595. }
  596. void parserModel(FILE * xmlf, CvLSVMFilterObject *** model, int *last, int *max, int **comp, float **b, int *count, float * score){
  597. int p = 0;
  598. int N_comp = 0;
  599. int * cmp;
  600. float *bb;
  601. int st = 0;
  602. int tag;
  603. int tagVal;
  604. char ch;
  605. int i,j, ii = 0;
  606. char buf[1024];
  607. char tagBuf[1024];
  608. //printf("<Model>\n");
  609. i = 0;
  610. j = 0;
  611. st = 0;
  612. tag = 0;
  613. while(!feof(xmlf)){
  614. ch = (char)fgetc( xmlf );
  615. if(ch == '<'){
  616. tag = 1;
  617. j = 1;
  618. tagBuf[j - 1] = ch;
  619. }else {
  620. if(ch == '>'){
  621. tagBuf[j ] = ch;
  622. tagBuf[j + 1] = '\0';
  623. tagVal = getTeg(tagBuf);
  624. if(tagVal == EMODEL){
  625. //printf("</Model>\n");
  626. for(ii = 0; ii <= *last; ii++){
  627. (*model)[ii]->numFeatures = p;
  628. }
  629. * count = N_comp;
  630. return;
  631. }
  632. if(tagVal == COMP){
  633. if(N_comp == 0){
  634. cmp = (int *)malloc(sizeof(int));
  635. bb = (float *)malloc(sizeof(float));
  636. * comp = cmp;
  637. * b = bb;
  638. * count = N_comp + 1;
  639. } else {
  640. cmp = (int *)malloc(sizeof(int) * (N_comp + 1));
  641. bb = (float *)malloc(sizeof(float) * (N_comp + 1));
  642. for(ii = 0; ii < N_comp; ii++){
  643. cmp[ii] = (* comp)[ii];
  644. bb [ii] = (* b )[ii];
  645. }
  646. free(* comp);
  647. free(* b );
  648. * comp = cmp;
  649. * b = bb;
  650. * count = N_comp + 1;
  651. }
  652. parserComp(xmlf, p, &N_comp, model, &((*b)[N_comp]), last, max);
  653. cmp[N_comp - 1] = *last;
  654. }
  655. if(tagVal == P){
  656. st = 1;
  657. i = 0;
  658. }
  659. if(tagVal == EP){
  660. st = 0;
  661. buf[i] = '\0';
  662. p = atoi(buf);
  663. //printf("<P>%d</P>\n", p);
  664. }
  665. if(tagVal == SCORE){
  666. st = 1;
  667. i = 0;
  668. }
  669. if(tagVal == ESCORE){
  670. st = 0;
  671. buf[i] = '\0';
  672. *score = (float)atof(buf);
  673. //printf("<ScoreThreshold>%f</ScoreThreshold>\n", score);
  674. }
  675. tag = 0;
  676. i = 0;
  677. }else{
  678. if((tag == 0)&& (st == 1)){
  679. buf[i] = ch; i++;
  680. }else{
  681. tagBuf[j] = ch; j++;
  682. }
  683. }
  684. }
  685. }
  686. }
  687. }//namespace
  688. int LSVMparser(const char * filename, CvLSVMFilterObject *** model, int *last, int *max, int **comp, float **b, int *count, float * score){
  689. //int st = 0;
  690. int tag;
  691. char ch;
  692. int /*i,*/j;
  693. FILE *xmlf;
  694. //char buf[1024];
  695. char tagBuf[1024];
  696. (*max) = 10;
  697. (*last) = -1;
  698. (*model) = (CvLSVMFilterObject ** )malloc((sizeof(CvLSVMFilterObject * )) * (*max));
  699. //printf("parse : %s\n", filename);
  700. xmlf = fopen(filename, "rb");
  701. if(xmlf == NULL)
  702. return LSVM_PARSER_FILE_NOT_FOUND;
  703. //i = 0;
  704. j = 0;
  705. //st = 0;
  706. tag = 0;
  707. while(!feof(xmlf)){
  708. ch = (char)fgetc( xmlf );
  709. if(ch == '<'){
  710. tag = 1;
  711. j = 1;
  712. tagBuf[j - 1] = ch;
  713. }else {
  714. if(ch == '>'){
  715. tag = 0;
  716. //i = 0;
  717. tagBuf[j ] = ch;
  718. tagBuf[j + 1] = '\0';
  719. if(getTeg(tagBuf) == MODEL){
  720. parserModel(xmlf, model, last, max, comp, b, count, score);
  721. }
  722. }else{
  723. if(tag == 0){
  724. //buf[i] = ch; i++;
  725. }else{
  726. tagBuf[j] = ch; j++;
  727. }
  728. }
  729. }
  730. }
  731. fclose(xmlf);
  732. return LATENT_SVM_OK;
  733. }
  734. int loadModel(
  735. const char *modelPath,
  736. CvLSVMFilterObject ***filters,
  737. int *kFilters,
  738. int *kComponents,
  739. int **kPartFilters,
  740. float **b,
  741. float *scoreThreshold){
  742. int last;
  743. int max;
  744. int *comp;
  745. int count;
  746. int i;
  747. int err;
  748. float score;
  749. //printf("start_parse\n\n");
  750. err = LSVMparser(modelPath, filters, &last, &max, &comp, b, &count, &score);
  751. if(err != LATENT_SVM_OK){
  752. return err;
  753. }
  754. (*kFilters) = last + 1;
  755. (*kComponents) = count;
  756. (*scoreThreshold) = (float) score;
  757. (*kPartFilters) = (int *)malloc(sizeof(int) * count);
  758. for(i = 1; i < count;i++){
  759. (*kPartFilters)[i] = (comp[i] - comp[i - 1]) - 1;
  760. }
  761. (*kPartFilters)[0] = comp[0];
  762. return 0;
  763. }