Operations.h 25 KB

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