You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.2 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright � 2000-2017. All Rights Reserved.
  4. // Version 2.0 9/14/2017
  5. // Last modification: 9/14/2017
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: basicImage.h
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of basicImage.h
  13. //----------------------------------------------------------------------------
  14. //
  15. #ifndef __CORTEX_BASIC_IMAGE_HEADER__
  16. #define __CORTEX_BASIC_IMAGE_HEADER__
  17. #ifndef STB_IMAGE_IMPLEMENTATION
  18. #define STB_IMAGE_IMPLEMENTATION
  19. #endif // !STB_IMAGE_IMPLEMENTATION
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <float.h>
  23. #include <string.h>
  24. #include <stdint.h>
  25. #include <math.h>
  26. #include <opencv2/opencv.hpp>
  27. #include "basicUtils.h"
  28. //#include "../qmath/qmath.h"
  29. typedef struct S_BOX{
  30. float x, y, w, h;
  31. } cortexBOX;
  32. typedef std::vector<cortexBOX> arrayBOX;
  33. typedef struct S_ARGS{
  34. uint32_t w;
  35. uint32_t h;
  36. float scale;
  37. float rad;
  38. float dx;
  39. float dy;
  40. float aspect;
  41. } cortexARGS;
  42. class cortexImage;
  43. typedef std::vector<cortexImage*> cortexImageList;
  44. class cortexImage{
  45. private:
  46. void rgb_to_hsv(void);
  47. void hsv_to_rgb(void);
  48. void yuv_to_rgb(void);
  49. void rgb_to_yuv(void);
  50. void rgb_to_bgr(void);
  51. void rotateCW(uint32_t times);
  52. void ghost(cortexImage *source, uint32_t dx, uint32_t dy);
  53. void transpose(void);
  54. void constrain(void);
  55. void normalize(void);
  56. void threshold(float thresh);
  57. void saturate(float sat);
  58. void exposure(float sat);
  59. void distort(float hue, float sat, float val);
  60. void binarize(void);
  61. void normalize2(void);
  62. void hue(float hue);
  63. float bilinear_interpolate(float x, float y, uint32_t c);
  64. void scale_channel(uint32_t c, float v);
  65. void translate_channel(uint32_t cc, float v);
  66. void saturateExposure(float sat, float exposure);
  67. void blendAsFront(cortexImage *back, float alpha);
  68. void blendAsBack(cortexImage *fore, float alpha);
  69. void grayscale_3C(void);
  70. void resizeMin(uint32_t min);
  71. void resizeMax(uint32_t max);
  72. void letterbox(uint32_t ww, uint32_t hh);
  73. void composite3d(char *f1, char *f2, char *out, int delta);
  74. public:
  75. /*Defaults*/
  76. cortexImage();
  77. ~cortexImage();
  78. /*Special*/
  79. cortexImage(IplImage* src);//image ipl_to_image(IplImage* src);
  80. cortexImage(cv::Mat* src);
  81. cortexImage( const cortexImage &CC );
  82. cortexImage( const cortexImage *CC );
  83. //cortexImage( cortexImage &CC );
  84. //cortexImage( cortexImage *CC );
  85. /* */
  86. uint16_t w;
  87. uint16_t h;
  88. uint16_t c;
  89. uint16_t step;
  90. float * data;
  91. size_t size;
  92. /*Methods*/
  93. bool fillFromMat( cv::Mat* src );
  94. bool fillFromVoid( uint32_t width, uint32_t height, uint32_t c){ return true; };
  95. bool fillFromStream( CvCapture *cap);
  96. bool fillFromIplImage( IplImage* src);//void ipl_into_image(IplImage* src, image im);
  97. bool fillFromFile( char* path, uint32_t x, uint32_t y, uint32_t channels = 3);
  98. bool toIpl( IplImage* dst);//void image_into_ipl(image im, IplImage* dst);
  99. void grayscale( void);
  100. void randomDistort( float hue, float saturation, float exposure);
  101. //void flush_stream_buffer(CvCapture *cap, int n);
  102. //void show_image_cv( image p, const char *name, IplImage *disp);
  103. float getColor( uint32_t c, uint32_t x, uint32_t max);
  104. void drawBoxEX( uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, float r, float g, float b);
  105. void drawBoxWEX( uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint32_t w, float r, float g, float b);
  106. void drawBox( cortexBOX *bbox, uint32_t w, float r, float g, float b);
  107. void drawLabel( uint32_t r, uint32_t c, cortexImage *label, const float *rgb);
  108. void writeLabel( uint32_t r, uint32_t c, cortexImage **characters, char *string, float *rgb);
  109. void distance( cortexImage *b);
  110. void fill( float s);
  111. void translate( float s);
  112. void scale( float s);
  113. void rotateCrop( float rad, float s, uint32_t w, uint32_t h, float dx, float dy, float aspect);
  114. void centerCrop( uint32_t ww, uint32_t hh);
  115. void crop( uint32_t x, uint32_t y, uint32_t w, uint32_t h);
  116. void border( uint32_t border);
  117. void randomCrop( uint32_t w, uint32_t h);
  118. void randomAugment( float angle, float aspect, uint32_t low, uint32_t high, uint32_t w, uint32_t h);
  119. cortexARGS randomAugmentArgs( float angle, float aspect, uint32_t low, uint32_t high, uint32_t w, uint32_t h);
  120. void letterboxInto( cortexImage *boxed);
  121. void resize( uint32_t w, uint32_t h);
  122. void rotate( float rad);
  123. void embed( cortexImage *source, uint32_t dx, uint32_t dy);
  124. bool composite( cortexImage *source, uint32_t dx, uint32_t dy);
  125. void place( uint32_t w, uint32_t h, uint32_t dx, uint32_t dy, cortexImage *canvas);
  126. void flip( void);
  127. bool collapseLayers( uint32_t border);
  128. void collapseImagesHorz(cortexImageList *imgList);
  129. void collapseImagesVert(cortexImageList *imgList);
  130. //bool showNormalized( const char *name );
  131. //void show_images( image *ims, int n, char *window);
  132. bool showLayers( char *name);
  133. bool showCollapsed( char *name);
  134. void print( void);
  135. void makeEmpty( uint32_t w, uint32_t h, uint32_t c);
  136. void makeWithData( uint32_t ww, uint32_t hh, uint32_t cc);
  137. void copyInto( cortexImage *dest);
  138. float getPixel( uint32_t x, uint32_t y, uint32_t c);
  139. float getPixelEX( uint32_t x, uint32_t y, uint32_t c);
  140. void setPixel( uint32_t x, uint32_t y, uint32_t c, float val);
  141. void addPixel( uint32_t x, uint32_t y, uint32_t c, float val);
  142. float bilinearInterpolate(float x, float y, uint32_t c);
  143. //cortexLayer *getlayer( int l);
  144. void toMat( cv::Mat &dst);
  145. void toMat( cv::Mat *dst);
  146. cv::Mat *toMat( void);
  147. void saveJPG( const char *name, int Quality = 80 );
  148. void saveBMP( const char *name);
  149. void savePNG( const char *name);
  150. void freeData( void);
  151. void fillRandom( void);
  152. void setData( uint32_t w, uint32_t h, uint32_t c, float *data);
  153. cortexImage *getLayer( uint32_t l);
  154. };
  155. int best3dShiftR(cortexImage *a, cortexImage *b, int min, int max);
  156. int best3dShift(cortexImage *a, cortexImage *b, int min, int max);
  157. void composite3d(char *f1, char *f2, char *out, int delta);
  158. #endif