Operations.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. /**
  2. * @file Operation.h
  3. * @brief abstract class for any kind of feature extraction from images
  4. * @author Björn Fröhlich
  5. * @date 24.04.2012
  6. */
  7. #include "core/image/MultiChannelImageT.h"
  8. #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
  9. namespace OBJREC {
  10. class Operation;
  11. /**
  12. * @brief methods for value access
  13. **/
  14. enum ValueTypes
  15. {
  16. RAWFEAT,
  17. CONTEXT,
  18. SPARSE,
  19. NBVALUETYPES
  20. };
  21. /**
  22. * @brief feature extraction methods
  23. **/
  24. enum OperationTypes {
  25. MINUS,
  26. MINUSABS,
  27. ADDITION,
  28. ONLY1,
  29. INTEGRAL,
  30. INTEGRALCENT,
  31. BIINTEGRALCENT,
  32. HAARHORIZ,
  33. HAARVERT,
  34. HAARDIAG,
  35. HAAR3HORIZ,
  36. HAAR3VERT,
  37. RELATIVEXPOSITION,
  38. RELATIVEYPOSITION,
  39. GLOBALFEATS,
  40. EQUALITY,
  41. NBOPERATIONS
  42. };
  43. /**
  44. * @brief node class for context tree
  45. **/
  46. class TreeNode
  47. {
  48. public:
  49. /** left child node */
  50. int left;
  51. /** right child node */
  52. int right;
  53. /** position of feat for decision */
  54. Operation *feat;
  55. /** decision stamp */
  56. double decision;
  57. /** is the node a leaf or not */
  58. bool isleaf;
  59. /** distribution in current node */
  60. std::vector<double> dist;
  61. /** depth of the node in the tree */
  62. int depth;
  63. /** how many pixels are in this node */
  64. int featcounter;
  65. /** unique number */
  66. int nodeNumber;
  67. /** simple constructor */
  68. TreeNode() : left ( -1 ), right ( -1 ), feat ( NULL ), decision ( -1.0 ), isleaf ( false ) {}
  69. /** standard constructor */
  70. TreeNode ( int _left, int _right, Operation *_feat, double _decision ) : left ( _left ), right ( _right ), feat ( _feat ), decision ( _decision ), isleaf ( false ) {}
  71. };
  72. /**
  73. * @brief holds all necessary information for feature extraction
  74. **/
  75. struct Features {
  76. /** simple features like RGB values */
  77. NICE::MultiChannelImageT<double> *feats;
  78. /** current leaf position for each pixel and each tree */
  79. NICE::MultiChannelImageT<unsigned short int> *cfeats;
  80. /** amount of trees */
  81. int cTree;
  82. /** tree nodes */
  83. std::vector<TreeNode> *tree;
  84. };
  85. /**
  86. * @brief abstract values access class
  87. **/
  88. class ValueAccess
  89. {
  90. public:
  91. /**
  92. * @brief extract value on specific position x,y and channel;
  93. *
  94. * @param feats see struct Features
  95. * @param x position of feature
  96. * @param y position of feature
  97. * @param channel position of feature
  98. * @return double value
  99. **/
  100. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel ) = 0;
  101. /**
  102. * @brief print some infos about feature type
  103. *
  104. * @return string feature type
  105. **/
  106. virtual std::string writeInfos() = 0;
  107. /**
  108. * @brief get feature type
  109. *
  110. * @return feature type
  111. **/
  112. virtual ValueTypes getType() = 0;
  113. };
  114. /**
  115. * @brief simple MultiChannelImageT access
  116. **/
  117. class MCImageAccess: public ValueAccess
  118. {
  119. public:
  120. /**
  121. * @brief extract value on specific position x,y and channel;
  122. *
  123. * @param feats see struct Features
  124. * @param x position of feature
  125. * @param y position of feature
  126. * @param channel position of feature
  127. * @return double value
  128. **/
  129. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
  130. {
  131. return feats.feats->get ( x, y, channel );
  132. }
  133. /**
  134. * @brief print some infos about feature type
  135. *
  136. * @return string feature type
  137. **/
  138. virtual std::string writeInfos()
  139. {
  140. return "raw";
  141. }
  142. /**
  143. * @brief get feature type
  144. *
  145. * @return feature type
  146. **/
  147. virtual ValueTypes getType()
  148. {
  149. return RAWFEAT;
  150. }
  151. };
  152. class ClassificationResultAccess: public ValueAccess
  153. {
  154. public:
  155. /**
  156. * @brief extract value on specific position x,y and channel;
  157. *
  158. * @param feats see struct Features
  159. * @param x position of feature
  160. * @param y position of feature
  161. * @param channel position of feature
  162. * @return double value
  163. **/
  164. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
  165. {
  166. return ( *feats.tree ) [feats.cfeats->get ( x,y,feats.cTree ) ].dist[channel];
  167. }
  168. /**
  169. * @brief print some infos about feature type
  170. *
  171. * @return string feature type
  172. **/
  173. virtual std::string writeInfos()
  174. {
  175. return "context";
  176. }
  177. /**
  178. * @brief get feature type
  179. *
  180. * @return feature type
  181. **/
  182. virtual ValueTypes getType()
  183. {
  184. return CONTEXT;
  185. }
  186. };
  187. #if 0
  188. /**
  189. * @brief not finished yet, do we really need sparse feature representation or ClassificationResultAccess sufficient
  190. **/
  191. class SparseImageAccess: public ValueAccess
  192. {
  193. private:
  194. double scale;
  195. public:
  196. /**
  197. * @brief extract value on specific position x,y and channel;
  198. *
  199. * @param feats see struct Features
  200. * @param x position of feature
  201. * @param y position of feature
  202. * @param channel position of feature
  203. * @return double value
  204. **/
  205. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
  206. {
  207. //MultiChannelImageT<SparseVectorInt> textonMap;
  208. //TODO: implement access
  209. return -1.0;
  210. }
  211. /**
  212. * @brief print some infos about feature type
  213. *
  214. * @return string feature type
  215. **/
  216. virtual std::string writeInfos()
  217. {
  218. return "context";
  219. }
  220. /**
  221. * @brief get feature type
  222. *
  223. * @return feature type
  224. **/
  225. virtual ValueTypes getType()
  226. {
  227. return CONTEXT;
  228. }
  229. };
  230. #endif
  231. /**
  232. * @brief abstract operation class
  233. **/
  234. class Operation
  235. {
  236. protected:
  237. /** two different points (e.g. for an rectangle or two positions), channels and size */
  238. int x1, y1, x2, y2, channel1, channel2, maxtypes;
  239. /** type of feature */
  240. int featType;
  241. ValueAccess *values;
  242. bool context;
  243. public:
  244. /** simple constructor */
  245. Operation();
  246. /**
  247. * @brief set all parameters
  248. * @param _x1 position 1
  249. * @param _y1 position 1
  250. * @param _x2 position 2
  251. * @param _y2 position 2
  252. * @param _channel1 channel 1
  253. * @param _channel2 channel 2
  254. * @param _values value extraction method
  255. * @return void nothing
  256. **/
  257. virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
  258. /**
  259. * @brief set whether it is a context feature or not
  260. * @param _context context boolean
  261. * @return void nothing
  262. **/
  263. void setContext ( bool _context );
  264. /**
  265. * @brief return context information (set by setContext(bool)
  266. *
  267. * @return bool whether context is used or not
  268. **/
  269. bool getContext();
  270. /**
  271. * @brief set type of feature
  272. * @param _featType type of feature
  273. * @return void nothing
  274. **/
  275. void setFeatType ( int _featType );
  276. /**
  277. * @brief return context information (set by setContext(bool)
  278. *
  279. * @return int get feature type
  280. **/
  281. int getFeatType();
  282. /**
  283. * @brief abstract interface for feature computation
  284. * @param feats features
  285. * @param cfeats number of tree node for each pixel
  286. * @param tree current tree
  287. * @param x current x position
  288. * @param y current y position
  289. * @return double distance
  290. **/
  291. virtual double getVal ( const Features &feats, const int &x, const int &y ) = 0;
  292. /**
  293. * @brief virtual clone operation instead of copy constructor (copy constructor does not work)
  294. **/
  295. virtual Operation* clone() = 0;
  296. /**
  297. * @brief print some infos about operation extraction type
  298. * @return string feature type
  299. **/
  300. virtual std::string writeInfos();
  301. /**
  302. * @brief exctract current image boarders
  303. * @param feats image information
  304. * @param xsize width
  305. * @param ysize height
  306. * @return void
  307. **/
  308. inline void getXY ( const Features &feats, int &xsize, int &ysize );
  309. /**
  310. * @brief return operation type (for store and restor)
  311. * @return OperationTypes
  312. **/
  313. virtual OperationTypes getOps() = 0;
  314. /**
  315. * @brief store all information for current operation in stream
  316. * @param os out stream
  317. * @return void
  318. **/
  319. virtual void store ( std::ostream & os );
  320. /**
  321. * @brief restore all information for current operation from stream
  322. * @param is in stream
  323. * @return void
  324. **/
  325. virtual void restore ( std::istream & is );
  326. };
  327. /**
  328. * @brief simple equality check ?(A==B)
  329. **/
  330. class Equality: public Operation
  331. {
  332. public:
  333. /**
  334. * @brief interface for feature computation
  335. * @param feats features
  336. * @param cfeats number of tree node for each pixel
  337. * @param tree current tree
  338. * @param x current x position
  339. * @param y current y position
  340. * @return double distance
  341. **/
  342. virtual double getVal ( const Features &feats, const int &x, const int &y );
  343. /**
  344. * @brief clone operation instead of copy constructor (copy constructor does not work)
  345. **/
  346. virtual Operation* clone()
  347. {
  348. return new Equality();
  349. }
  350. /**
  351. * @brief print some infos about operation extraction type
  352. * @return string feature type
  353. **/
  354. virtual std::string writeInfos()
  355. {
  356. std::string out = "Equality";
  357. if ( values != NULL )
  358. out += values->writeInfos();
  359. return out + Operation::writeInfos();
  360. }
  361. /**
  362. * @brief return operation type (for store and restor)
  363. * @return OperationTypes
  364. **/
  365. virtual OperationTypes getOps()
  366. {
  367. return EQUALITY;
  368. }
  369. };
  370. /**
  371. * @brief simple difference operation A-B
  372. **/
  373. class Minus: public Operation
  374. {
  375. public:
  376. /**
  377. * @brief interface for feature computation
  378. * @param feats features
  379. * @param cfeats number of tree node for each pixel
  380. * @param tree current tree
  381. * @param x current x position
  382. * @param y current y position
  383. * @return double distance
  384. **/
  385. virtual double getVal ( const Features &feats, const int &x, const int &y );
  386. /**
  387. * @brief clone operation instead of copy constructor (copy constructor does not work)
  388. **/
  389. virtual Operation* clone()
  390. {
  391. return new Minus();
  392. }
  393. /**
  394. * @brief print some infos about operation extraction type
  395. * @return string feature type
  396. **/
  397. virtual std::string writeInfos()
  398. {
  399. std::string out = "Minus";
  400. if ( values != NULL )
  401. out += values->writeInfos();
  402. return out + Operation::writeInfos();
  403. }
  404. /**
  405. * @brief return operation type (for store and restor)
  406. * @return OperationTypes
  407. **/
  408. virtual OperationTypes getOps()
  409. {
  410. return MINUS;
  411. }
  412. };
  413. /**
  414. * @brief simple absolute difference operation |A-B|
  415. **/
  416. class MinusAbs: public Operation
  417. {
  418. public:
  419. /**
  420. * @brief interface for feature computation
  421. * @param feats features
  422. * @param cfeats number of tree node for each pixel
  423. * @param tree current tree
  424. * @param x current x position
  425. * @param y current y position
  426. * @return double distance
  427. **/
  428. virtual double getVal ( const Features &feats, const int &x, const int &y );
  429. /**
  430. * @brief clone operation instead of copy constructor (copy constructor does not work)
  431. **/
  432. virtual Operation* clone()
  433. {
  434. return new MinusAbs();
  435. };
  436. /**
  437. * @brief print some infos about operation extraction type
  438. * @return string feature type
  439. **/
  440. virtual std::string writeInfos()
  441. {
  442. std::string out = "MinusAbs";
  443. if ( values != NULL )
  444. out += values->writeInfos();
  445. return out;
  446. }
  447. /**
  448. * @brief return operation type (for store and restor)
  449. * @return OperationTypes
  450. **/
  451. virtual OperationTypes getOps()
  452. {
  453. return MINUSABS;
  454. }
  455. };
  456. /**
  457. * @brief simple addition operation A+B
  458. **/
  459. class Addition: public Operation
  460. {
  461. public:
  462. /**
  463. * @brief interface for feature computation
  464. * @param feats features
  465. * @param cfeats number of tree node for each pixel
  466. * @param tree current tree
  467. * @param x current x position
  468. * @param y current y position
  469. * @return double distance
  470. **/
  471. virtual double getVal ( const Features &feats, const int &x, const int &y );
  472. /**
  473. * @brief clone operation instead of copy constructor (copy constructor does not work)
  474. **/
  475. virtual Operation* clone()
  476. {
  477. return new Addition();
  478. }
  479. /**
  480. * @brief print some infos about operation extraction type
  481. * @return string feature type
  482. **/
  483. virtual std::string writeInfos()
  484. {
  485. std::string out = "Addition";
  486. if ( values != NULL )
  487. out += values->writeInfos();
  488. return out + Operation::writeInfos();
  489. }
  490. /**
  491. * @brief return operation type (for store and restor)
  492. * @return OperationTypes
  493. **/
  494. virtual OperationTypes getOps()
  495. {
  496. return ADDITION;
  497. }
  498. };
  499. /**
  500. * @brief simple single element access operation
  501. **/
  502. class Only1: public Operation
  503. {
  504. public:
  505. /**
  506. * @brief interface for feature computation
  507. * @param feats features
  508. * @param cfeats number of tree node for each pixel
  509. * @param tree current tree
  510. * @param x current x position
  511. * @param y current y position
  512. * @return double distance
  513. **/
  514. virtual double getVal ( const Features &feats, const int &x, const int &y );
  515. /**
  516. * @brief clone operation instead of copy constructor (copy constructor does not work)
  517. **/
  518. virtual Operation* clone()
  519. {
  520. return new Only1();
  521. }
  522. /**
  523. * @brief print some infos about operation extraction type
  524. * @return string feature type
  525. **/
  526. virtual std::string writeInfos()
  527. {
  528. std::string out = "Only1";
  529. if ( values != NULL )
  530. out += values->writeInfos();
  531. return out + Operation::writeInfos();
  532. }
  533. /**
  534. * @brief return operation type (for store and restor)
  535. * @return OperationTypes
  536. **/
  537. virtual OperationTypes getOps()
  538. {
  539. return ONLY1;
  540. }
  541. };
  542. /**
  543. * @brief get current relative x position
  544. **/
  545. class RelativeXPosition: public Operation
  546. {
  547. public:
  548. /**
  549. * @brief interface for feature computation
  550. * @param feats features
  551. * @param cfeats number of tree node for each pixel
  552. * @param tree current tree
  553. * @param x current x position
  554. * @param y current y position
  555. * @return double distance
  556. **/
  557. virtual double getVal ( const Features &feats, const int &x, const int &y );
  558. /**
  559. * @brief clone operation instead of copy constructor (copy constructor does not work)
  560. **/
  561. virtual Operation* clone()
  562. {
  563. return new RelativeXPosition();
  564. }
  565. /**
  566. * @brief print some infos about operation extraction type
  567. * @return string feature type
  568. **/
  569. virtual std::string writeInfos()
  570. {
  571. return "RelativeXPosition" + Operation::writeInfos();
  572. }
  573. /**
  574. * @brief return operation type (for store and restor)
  575. * @return OperationTypes
  576. **/
  577. virtual OperationTypes getOps()
  578. {
  579. return RELATIVEXPOSITION;
  580. }
  581. };
  582. /**
  583. * @brief get current relative y position
  584. **/
  585. class RelativeYPosition: public Operation
  586. {
  587. public:
  588. /**
  589. * @brief interface for feature computation
  590. * @param feats features
  591. * @param cfeats number of tree node for each pixel
  592. * @param tree current tree
  593. * @param x current x position
  594. * @param y current y position
  595. * @return double distance
  596. **/
  597. virtual double getVal ( const Features &feats, const int &x, const int &y );
  598. /**
  599. * @brief clone operation instead of copy constructor (copy constructor does not work)
  600. **/
  601. virtual Operation* clone()
  602. {
  603. return new RelativeYPosition();
  604. }
  605. /**
  606. * @brief print some infos about operation extraction type
  607. * @return string feature type
  608. **/
  609. virtual std::string writeInfos()
  610. {
  611. return "RelativeYPosition" + Operation::writeInfos();
  612. }
  613. /**
  614. * @brief return operation type (for store and restor)
  615. * @return OperationTypes
  616. **/
  617. virtual OperationTypes getOps()
  618. {
  619. return RELATIVEYPOSITION;
  620. }
  621. };
  622. /**
  623. * @brief uses mean in a window given by (x1,y1) (x2,y2)
  624. **/
  625. class IntegralOps: public Operation
  626. {
  627. public:
  628. /**
  629. * @brief set all parameters
  630. * @param _x1 position 1
  631. * @param _y1 position 1
  632. * @param _x2 position 2
  633. * @param _y2 position 2
  634. * @param _channel1 channel 1
  635. * @param _channel2 channel 2
  636. * @param _values value extraction method
  637. * @return void nothing
  638. **/
  639. virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
  640. /**
  641. * @brief interface for feature computation
  642. * @param feats features
  643. * @param cfeats number of tree node for each pixel
  644. * @param tree current tree
  645. * @param x current x position
  646. * @param y current y position
  647. * @return double distance
  648. **/
  649. virtual double getVal ( const Features &feats, const int &x, const int &y );
  650. /**
  651. * @brief clone operation instead of copy constructor (copy constructor does not work)
  652. **/
  653. virtual Operation* clone()
  654. {
  655. return new IntegralOps();
  656. }
  657. /**
  658. * @brief print some infos about operation extraction type
  659. * @return string feature type
  660. **/
  661. virtual std::string writeInfos()
  662. {
  663. return "IntegralOps" + Operation::writeInfos();
  664. }
  665. /**
  666. * @brief return operation type (for store and restor)
  667. * @return OperationTypes
  668. **/
  669. virtual OperationTypes getOps()
  670. {
  671. return INTEGRAL;
  672. }
  673. };
  674. /**
  675. * @brief like a global bag of words to model the current appearance of classes in an image without local context
  676. **/
  677. class GlobalFeats: public IntegralOps
  678. {
  679. public:
  680. /**
  681. * @brief interface for feature computation
  682. * @param feats features
  683. * @param cfeats number of tree node for each pixel
  684. * @param tree current tree
  685. * @param x current x position
  686. * @param y current y position
  687. * @return double distance
  688. **/
  689. virtual double getVal ( const Features &feats, const int &x, const int &y );
  690. /**
  691. * @brief clone operation instead of copy constructor (copy constructor does not work)
  692. **/
  693. virtual Operation* clone()
  694. {
  695. return new GlobalFeats();
  696. }
  697. /**
  698. * @brief print some infos about operation extraction type
  699. * @return string feature type
  700. **/
  701. virtual std::string writeInfos()
  702. {
  703. return "GlobalFeats" + Operation::writeInfos();
  704. }
  705. /**
  706. * @brief return operation type (for store and restor)
  707. * @return OperationTypes
  708. **/
  709. virtual OperationTypes getOps()
  710. {
  711. return GLOBALFEATS;
  712. }
  713. };
  714. /**
  715. * @brief uses mean of Integral image given by x1, y1 with current pixel as center
  716. **/
  717. class IntegralCenteredOps: public IntegralOps
  718. {
  719. public:
  720. /**
  721. * @brief set all parameters
  722. * @param _x1 position 1
  723. * @param _y1 position 1
  724. * @param _x2 position 2
  725. * @param _y2 position 2
  726. * @param _channel1 channel 1
  727. * @param _channel2 channel 2
  728. * @param _values value extraction method
  729. * @return void nothing
  730. **/
  731. virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
  732. /**
  733. * @brief interface for feature computation
  734. * @param feats features
  735. * @param cfeats number of tree node for each pixel
  736. * @param tree current tree
  737. * @param x current x position
  738. * @param y current y position
  739. * @return double distance
  740. **/
  741. virtual double getVal ( const Features &feats, const int &x, const int &y );
  742. /**
  743. * @brief clone operation instead of copy constructor (copy constructor does not work)
  744. **/
  745. virtual Operation* clone()
  746. {
  747. return new IntegralCenteredOps();
  748. }
  749. /**
  750. * @brief print some infos about operation extraction type
  751. * @return string feature type
  752. **/
  753. virtual std::string writeInfos()
  754. {
  755. return "IntegralCenteredOps" + Operation::writeInfos();
  756. }
  757. /**
  758. * @brief return operation type (for store and restor)
  759. * @return OperationTypes
  760. **/
  761. virtual OperationTypes getOps()
  762. {
  763. return INTEGRALCENT;
  764. }
  765. };
  766. /**
  767. * @brief uses different of mean of Integral image given by two windows, where (x1,y1) is the width and height of window1 and (x2,y2) of window 2
  768. **/
  769. class BiIntegralCenteredOps: public IntegralCenteredOps
  770. {
  771. public:
  772. /**
  773. * @brief set all parameters
  774. * @param _x1 position 1
  775. * @param _y1 position 1
  776. * @param _x2 position 2
  777. * @param _y2 position 2
  778. * @param _channel1 channel 1
  779. * @param _channel2 channel 2
  780. * @param _values value extraction method
  781. * @return void nothing
  782. **/
  783. virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
  784. /**
  785. * @brief interface for feature computation
  786. * @param feats features
  787. * @param cfeats number of tree node for each pixel
  788. * @param tree current tree
  789. * @param x current x position
  790. * @param y current y position
  791. * @return double distance
  792. **/
  793. virtual double getVal ( const Features &feats, const int &x, const int &y );
  794. /**
  795. * @brief clone operation instead of copy constructor (copy constructor does not work)
  796. **/
  797. virtual Operation* clone()
  798. {
  799. return new BiIntegralCenteredOps();
  800. }
  801. /**
  802. * @brief print some infos about operation extraction type
  803. * @return string feature type
  804. **/
  805. virtual std::string writeInfos()
  806. {
  807. return "BiIntegralCenteredOps" + Operation::writeInfos();
  808. }
  809. /**
  810. * @brief return operation type (for store and restor)
  811. * @return OperationTypes
  812. **/
  813. virtual OperationTypes getOps()
  814. {
  815. return BIINTEGRALCENT;
  816. }
  817. };
  818. /**
  819. * @brief horizontal Haar features
  820. * ++
  821. * --
  822. **/
  823. class HaarHorizontal: public IntegralCenteredOps
  824. {
  825. public:
  826. /**
  827. * @brief interface for feature computation
  828. * @param feats features
  829. * @param cfeats number of tree node for each pixel
  830. * @param tree current tree
  831. * @param x current x position
  832. * @param y current y position
  833. * @return double distance
  834. **/
  835. virtual double getVal ( const Features &feats, const int &x, const int &y );
  836. /**
  837. * @brief clone operation instead of copy constructor (copy constructor does not work)
  838. **/
  839. virtual Operation* clone()
  840. {
  841. return new HaarHorizontal();
  842. }
  843. /**
  844. * @brief print some infos about operation extraction type
  845. * @return string feature type
  846. **/
  847. virtual std::string writeInfos()
  848. {
  849. return "HaarHorizontal" + Operation::writeInfos();
  850. }
  851. /**
  852. * @brief return operation type (for store and restor)
  853. * @return OperationTypes
  854. **/
  855. virtual OperationTypes getOps()
  856. {
  857. return HAARHORIZ;
  858. }
  859. };
  860. /**
  861. * @brief vertical Haar features
  862. * +-
  863. * +-
  864. **/
  865. class HaarVertical: public IntegralCenteredOps
  866. {
  867. public:
  868. /**
  869. * @brief interface for feature computation
  870. * @param feats features
  871. * @param cfeats number of tree node for each pixel
  872. * @param tree current tree
  873. * @param x current x position
  874. * @param y current y position
  875. * @return double distance
  876. **/
  877. virtual double getVal ( const Features &feats, const int &x, const int &y );
  878. /**
  879. * @brief clone operation instead of copy constructor (copy constructor does not work)
  880. **/
  881. virtual Operation* clone()
  882. {
  883. return new HaarVertical();
  884. }
  885. /**
  886. * @brief print some infos about operation extraction type
  887. * @return string feature type
  888. **/
  889. virtual std::string writeInfos()
  890. {
  891. return "HaarVertical" + Operation::writeInfos();
  892. }
  893. /**
  894. * @brief return operation type (for store and restor)
  895. * @return OperationTypes
  896. **/
  897. virtual OperationTypes getOps()
  898. {
  899. return HAARVERT;
  900. }
  901. };
  902. /**
  903. * @brief diagonal Haar features
  904. * +-
  905. * -+
  906. **/
  907. class HaarDiag: public IntegralCenteredOps
  908. {
  909. public:
  910. /**
  911. * @brief interface for feature computation
  912. * @param feats features
  913. * @param cfeats number of tree node for each pixel
  914. * @param tree current tree
  915. * @param x current x position
  916. * @param y current y position
  917. * @return double distance
  918. **/
  919. virtual double getVal ( const Features &feats, const int &x, const int &y );
  920. /**
  921. * @brief clone operation instead of copy constructor (copy constructor does not work)
  922. **/
  923. virtual Operation* clone()
  924. {
  925. return new HaarDiag();
  926. }
  927. /**
  928. * @brief print some infos about operation extraction type
  929. * @return string feature type
  930. **/
  931. virtual std::string writeInfos()
  932. {
  933. return "HaarDiag" + Operation::writeInfos();
  934. }
  935. /**
  936. * @brief return operation type (for store and restor)
  937. * @return OperationTypes
  938. **/
  939. virtual OperationTypes getOps()
  940. {
  941. return HAARDIAG;
  942. }
  943. };
  944. /**
  945. * @brief horizontal Haar features
  946. * +++
  947. * ---
  948. * +++
  949. */
  950. class Haar3Horiz: public BiIntegralCenteredOps
  951. {
  952. public:
  953. /**
  954. * @brief interface for feature computation
  955. * @param feats features
  956. * @param cfeats number of tree node for each pixel
  957. * @param tree current tree
  958. * @param x current x position
  959. * @param y current y position
  960. * @return double distance
  961. **/
  962. virtual double getVal ( const Features &feats, const int &x, const int &y );
  963. /**
  964. * @brief clone operation instead of copy constructor (copy constructor does not work)
  965. **/
  966. virtual Operation* clone()
  967. {
  968. return new Haar3Horiz();
  969. }
  970. /**
  971. * @brief print some infos about operation extraction type
  972. * @return string feature type
  973. **/
  974. virtual std::string writeInfos()
  975. {
  976. return "Haar3Horiz" + Operation::writeInfos();
  977. }
  978. /**
  979. * @brief return operation type (for store and restor)
  980. * @return OperationTypes
  981. **/
  982. virtual OperationTypes getOps()
  983. {
  984. return HAAR3HORIZ;
  985. }
  986. };
  987. /**
  988. * @brief vertical Haar features
  989. * +-+
  990. * +-+
  991. * +-+
  992. */
  993. class Haar3Vert: public BiIntegralCenteredOps
  994. {
  995. public:
  996. /**
  997. * @brief interface for feature computation
  998. * @param feats features
  999. * @param cfeats number of tree node for each pixel
  1000. * @param tree current tree
  1001. * @param x current x position
  1002. * @param y current y position
  1003. * @return double distance
  1004. **/
  1005. virtual double getVal ( const Features &feats, const int &x, const int &y );
  1006. /**
  1007. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1008. **/
  1009. virtual Operation* clone()
  1010. {
  1011. return new Haar3Vert();
  1012. }
  1013. /**
  1014. * @brief print some infos about operation extraction type
  1015. * @return string feature type
  1016. **/
  1017. virtual std::string writeInfos()
  1018. {
  1019. return "Haar3Vert" + Operation::writeInfos();
  1020. }
  1021. /**
  1022. * @brief return operation type (for store and restor)
  1023. * @return OperationTypes
  1024. **/
  1025. virtual OperationTypes getOps()
  1026. {
  1027. return HAAR3VERT;
  1028. }
  1029. };
  1030. } //end namespace