Operations.h 27 KB

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