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
176 lines
6.2 KiB
//----------------------------------------------------------------------------
|
|
// Dr.Frucht Systems Ltd.
|
|
// Copyright © 2000-2017. All Rights Reserved.
|
|
// Version 2.0 9/14/2017
|
|
// Last modification: 9/14/2017
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: basicImage.h
|
|
// AUTHOR: gagua
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Header file of basicImage.h
|
|
//----------------------------------------------------------------------------
|
|
//
|
|
#ifndef __CORTEX_BASIC_IMAGE_HEADER__
|
|
#define __CORTEX_BASIC_IMAGE_HEADER__
|
|
|
|
#ifndef STB_IMAGE_IMPLEMENTATION
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
#endif // !STB_IMAGE_IMPLEMENTATION
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <float.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <math.h>
|
|
#include <opencv2/opencv.hpp>
|
|
#include "basicUtils.h"
|
|
//#include "../qmath/qmath.h"
|
|
|
|
typedef struct S_BOX{
|
|
float x, y, w, h;
|
|
} cortexBOX;
|
|
|
|
typedef std::vector<cortexBOX> arrayBOX;
|
|
|
|
typedef struct S_ARGS{
|
|
uint32_t w;
|
|
uint32_t h;
|
|
float scale;
|
|
float rad;
|
|
float dx;
|
|
float dy;
|
|
float aspect;
|
|
} cortexARGS;
|
|
|
|
class cortexImage;
|
|
|
|
typedef std::vector<cortexImage*> cortexImageList;
|
|
|
|
class cortexImage{
|
|
private:
|
|
void rgb_to_hsv(void);
|
|
void hsv_to_rgb(void);
|
|
void yuv_to_rgb(void);
|
|
void rgb_to_yuv(void);
|
|
void rgb_to_bgr(void);
|
|
void rotateCW(uint32_t times);
|
|
void ghost(cortexImage *source, uint32_t dx, uint32_t dy);
|
|
void transpose(void);
|
|
void constrain(void);
|
|
void normalize(void);
|
|
void threshold(float thresh);
|
|
void saturate(float sat);
|
|
void exposure(float sat);
|
|
void distort(float hue, float sat, float val);
|
|
void binarize(void);
|
|
void normalize2(void);
|
|
void hue(float hue);
|
|
float bilinear_interpolate(float x, float y, uint32_t c);
|
|
void scale_channel(uint32_t c, float v);
|
|
void translate_channel(uint32_t cc, float v);
|
|
void saturateExposure(float sat, float exposure);
|
|
|
|
void blendAsFront(cortexImage *back, float alpha);
|
|
void blendAsBack(cortexImage *fore, float alpha);
|
|
|
|
void grayscale_3C(void);
|
|
void resizeMin(uint32_t min);
|
|
void resizeMax(uint32_t max);
|
|
void letterbox(uint32_t ww, uint32_t hh);
|
|
void composite3d(char *f1, char *f2, char *out, int delta);
|
|
public:
|
|
/*Defaults*/
|
|
cortexImage();
|
|
~cortexImage();
|
|
|
|
/*Special*/
|
|
cortexImage(IplImage* src);//image ipl_to_image(IplImage* src);
|
|
cortexImage(cv::Mat* src);
|
|
|
|
cortexImage( const cortexImage &CC );
|
|
cortexImage( const cortexImage *CC );
|
|
|
|
//cortexImage( cortexImage &CC );
|
|
//cortexImage( cortexImage *CC );
|
|
|
|
/* */
|
|
uint16_t w;
|
|
uint16_t h;
|
|
uint16_t c;
|
|
uint16_t step;
|
|
float * data;
|
|
size_t size;
|
|
/*Methods*/
|
|
bool fillFromMat( cv::Mat* src );
|
|
bool fillFromVoid( uint32_t width, uint32_t height, uint32_t c){ return true; };
|
|
bool fillFromStream( CvCapture *cap);
|
|
bool fillFromIplImage( IplImage* src);//void ipl_into_image(IplImage* src, image im);
|
|
bool fillFromFile( char* path, uint32_t x, uint32_t y, uint32_t channels = 3);
|
|
bool toIpl( IplImage* dst);//void image_into_ipl(image im, IplImage* dst);
|
|
void grayscale( void);
|
|
void randomDistort( float hue, float saturation, float exposure);
|
|
//void flush_stream_buffer(CvCapture *cap, int n);
|
|
//void show_image_cv( image p, const char *name, IplImage *disp);
|
|
float getColor( uint32_t c, uint32_t x, uint32_t max);
|
|
void drawBoxEX( uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, float r, float g, float b);
|
|
void drawBoxWEX( uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint32_t w, float r, float g, float b);
|
|
void drawBox( cortexBOX *bbox, uint32_t w, float r, float g, float b);
|
|
void drawLabel( uint32_t r, uint32_t c, cortexImage *label, const float *rgb);
|
|
void writeLabel( uint32_t r, uint32_t c, cortexImage **characters, char *string, float *rgb);
|
|
void distance( cortexImage *b);
|
|
void fill( float s);
|
|
void translate( float s);
|
|
void scale( float s);
|
|
void rotateCrop( float rad, float s, uint32_t w, uint32_t h, float dx, float dy, float aspect);
|
|
|
|
void centerCrop( uint32_t ww, uint32_t hh);
|
|
void crop( uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
|
void border( uint32_t border);
|
|
void randomCrop( uint32_t w, uint32_t h);
|
|
void randomAugment( float angle, float aspect, uint32_t low, uint32_t high, uint32_t w, uint32_t h);
|
|
cortexARGS randomAugmentArgs( float angle, float aspect, uint32_t low, uint32_t high, uint32_t w, uint32_t h);
|
|
void letterboxInto( cortexImage *boxed);
|
|
void resize( uint32_t w, uint32_t h);
|
|
void rotate( float rad);
|
|
void embed( cortexImage *source, uint32_t dx, uint32_t dy);
|
|
bool composite( cortexImage *source, uint32_t dx, uint32_t dy);
|
|
void place( uint32_t w, uint32_t h, uint32_t dx, uint32_t dy, cortexImage *canvas);
|
|
void flip( void);
|
|
bool collapseLayers( uint32_t border);
|
|
void collapseImagesHorz(cortexImageList *imgList);
|
|
void collapseImagesVert(cortexImageList *imgList);
|
|
//bool showNormalized( const char *name );
|
|
//void show_images( image *ims, int n, char *window);
|
|
bool showLayers( char *name);
|
|
bool showCollapsed( char *name);
|
|
void print( void);
|
|
void makeEmpty( uint32_t w, uint32_t h, uint32_t c);
|
|
void makeWithData( uint32_t ww, uint32_t hh, uint32_t cc);
|
|
void copyInto( cortexImage *dest);
|
|
float getPixel( uint32_t x, uint32_t y, uint32_t c);
|
|
float getPixelEX( uint32_t x, uint32_t y, uint32_t c);
|
|
void setPixel( uint32_t x, uint32_t y, uint32_t c, float val);
|
|
void addPixel( uint32_t x, uint32_t y, uint32_t c, float val);
|
|
float bilinearInterpolate(float x, float y, uint32_t c);
|
|
//cortexLayer *getlayer( int l);
|
|
void toMat( cv::Mat &dst);
|
|
void toMat( cv::Mat *dst);
|
|
cv::Mat *toMat( void);
|
|
void saveJPG( const char *name, int Quality = 80 );
|
|
void saveBMP( const char *name);
|
|
void savePNG( const char *name);
|
|
void freeData( void);
|
|
void fillRandom( void);
|
|
void setData( uint32_t w, uint32_t h, uint32_t c, float *data);
|
|
cortexImage *getLayer( uint32_t l);
|
|
};
|
|
|
|
int best3dShiftR(cortexImage *a, cortexImage *b, int min, int max);
|
|
int best3dShift(cortexImage *a, cortexImage *b, int min, int max);
|
|
void composite3d(char *f1, char *f2, char *out, int delta);
|
|
#endif
|
|
|
|
|