Operations.h 27 KB

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