C形式の関数・構造体がOpenCV2.1からどれだけ変わったかをまとめておき、ラッパー開発の指針にしようと思います。例によって多分どこか抜けています。また、C++の方はまとめる気はありません。
公式の変更点はこちら。実際のところこちらに全て載っています。文章ではなくソースコード的にまとめただけです。
opencv2/core/core_c.h (旧cxcore.h)
diffを取ってみましたがほぼ変化はありません。CvFontのみ、Qt対応のためか若干変わっています。
CvFont
/* Font structure */ typedef struct CvFont { const char* nameFont; //Qt:nameFont CvScalar color; //Qt:ColorFont -> cvScalar(blue_component, green_component, red\_component[, alpha_component]) int font_face; //Qt: bool italic /* =CV_FONT_* */ const int* ascii; /* font data and metrics */ const int* greek; const int* cyrillic; float hscale, vscale; float shear; /* slope coefficient: 0 - normal, >0 - italic */ int thickness; //Qt: weight /* letters thickness */ float dx; /* horizontal interval between letters */ int line_type; //Qt: PointSize } CvFont;
opencv2/imgproc/imgproc_c.h (旧cv.h)
cv.h の半分ぐらいを引き継ぐのが imgproc_c.h です。カメラキャリブレーション関係や特徴点抽出などの関数が出て行ってしまいました。また、2.1までは引数に与える定数も一緒に定義されていましたが、2.2では opencv2/imgproc/types_c.h に移り、さらに#defineではなくenumにより定義されています。
cvCvtColor
処理モード定数がかなり増えています。ChangeLogによると処理の中身も色々と変わったそうです。
/* Constants for color conversion */ enum { /* 中略 */ CV_BayerBG2BGR_VNG =62, CV_BayerGB2BGR_VNG =63, CV_BayerRG2BGR_VNG =64, CV_BayerGR2BGR_VNG =65, CV_BayerBG2RGB_VNG =CV_BayerRG2BGR_VNG, CV_BayerGB2RGB_VNG =CV_BayerGR2BGR_VNG, CV_BayerRG2RGB_VNG =CV_BayerBG2BGR_VNG, CV_BayerGR2RGB_VNG =CV_BayerGB2BGR_VNG, CV_BGR2HSV_FULL = 66, CV_RGB2HSV_FULL = 67, CV_BGR2HLS_FULL = 68, CV_RGB2HLS_FULL = 69, CV_HSV2BGR_FULL = 70, CV_HSV2RGB_FULL = 71, CV_HLS2BGR_FULL = 72, CV_HLS2RGB_FULL = 73, CV_LBGR2Lab = 74, CV_LRGB2Lab = 75, CV_LBGR2Luv = 76, CV_LRGB2Luv = 77, CV_Lab2LBGR = 78, CV_Lab2LRGB = 79, CV_Luv2LBGR = 80, CV_Luv2LRGB = 81, CV_BGR2YUV = 82, CV_RGB2YUV = 83, CV_YUV2BGR = 84, CV_YUV2RGB = 85, CV_COLORCVT_MAX =100 };
cvResize
Lanczos法による処理のための定数が増えています。これは実は2.1でもC++ Interfaceの方の定数を借りてくれば使用できました。
enum { /* 中略 */ CV_INTER_LANCZOS4 =4 };
opencv2/calib3d/calib3d.hpp
カメラキャリブレーションや姿勢推定などの関数が集まっています。拡張子が.hppですが、C形式の関数も前半に含まれています。なおこちらでは定数は従来通り#defineにより定義されています。
cvCalibrateCamera2
The new rational distortion modelが追加されたそうで、そのための新しいモードの定数です。
#define CV_CALIB_FIX_K4 2048 #define CV_CALIB_FIX_K5 4096 #define CV_CALIB_FIX_K6 8192 #define CV_CALIB_RATIONAL_MODEL 16384
opencv2/features2d/features2d.hpp
SURFとかMSERなどが入っているところです。とくに増えたものはCでは見当たらず。
opencv2/objdetect/objdetect.hpp
物体検出機があるところです。LatentSVM オブジェクト検出器が追加されています。
LatentSVM
//////////////// Object Detection using Latent SVM ////////////// // DataType: STRUCT position // Structure describes the position of the filter in the feature pyramid typedef struct { unsigned int x; unsigned int y; unsigned int l; } CvLSVMFilterPosition; // DataType: STRUCT filterObject // Description of the filter, which corresponds to the part of the object typedef struct{ CvLSVMFilterPosition V; float fineFunction[4]; unsigned int sizeX; unsigned int sizeY; unsigned int p; unsigned int xp; float *H; } CvLSVMFilterObject; // data type: STRUCT CvLatentSvmDetector // structure contains internal representation of trained Latent SVM detector typedef struct CvLatentSvmDetector { int num_filters; int num_components; int* num_part_filters; CvLSVMFilterObject** filters; float* b; float score_threshold; } CvLatentSvmDetector; // data type: STRUCT CvObjectDetection // structure contains the bounding box and confidence level for detected object typedef struct CvObjectDetection { CvRect rect; float score; } CvObjectDetection; /* // load trained detector from a file */ CVAPI(CvLatentSvmDetector*) cvLoadLatentSvmDetector(const char* filename); /* // release memory allocated for CvLatentSvmDetector structure */ CVAPI(void) cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector); /* // find rectangular regions in the given image that are likely // to contain objects and corresponding confidence levels */ CVAPI(CvSeq*) cvLatentSvmDetectObjects(IplImage* image, CvLatentSvmDetector* detector, CvMemStorage* storage, float overlap_threshold CV_DEFAULT(0.5f));
opencv2/video/background_segm.hpp
見慣れないものが多いですが、cvaux.hから引っ越してきたものばかりです。とくに増えたものは見当たらず。
opencv2/video/tracking.hpp
ここも増えたものは見つけられず。
opencv2/ml/ml.hpp
機械学習関係です。これはかなり前からあったのでC++ですが取り上げます。新しくGradient boosting trees モデルが追加されたようです。
絶望的にコメントが無いMLにありながら、新規追加だけあって関数やその引数の説明がたくさんコメントに書かれています。長いのでここでは省きます。
CvGBTreesParams
struct CV_EXPORTS_W_MAP CvGBTreesParams : public CvDTreeParams { CV_PROP_RW int weak_count; CV_PROP_RW int loss_function_type; CV_PROP_RW float subsample_portion; CV_PROP_RW float shrinkage; CvGBTreesParams(); CvGBTreesParams( int loss_function_type, int weak_count, float shrinkage, float subsample_portion, int max_depth, bool use_surrogates ); };
CvGBTrees
class CV_EXPORTS_W CvGBTrees : public CvStatModel { public: enum {SQUARED_LOSS=0, ABSOLUTE_LOSS, HUBER_LOSS=3, DEVIANCE_LOSS}; CV_WRAP CvGBTrees(); CvGBTrees( const CvMat* trainData, int tflag, const CvMat* responses, const CvMat* varIdx=0, const CvMat* sampleIdx=0, const CvMat* varType=0, const CvMat* missingDataMask=0, CvGBTreesParams params=CvGBTreesParams() ); virtual ~CvGBTrees(); virtual bool train( const CvMat* trainData, int tflag, const CvMat* responses, const CvMat* varIdx=0, const CvMat* sampleIdx=0, const CvMat* varType=0, const CvMat* missingDataMask=0, CvGBTreesParams params=CvGBTreesParams(), bool update=false ); virtual bool train( CvMLData* data, CvGBTreesParams params=CvGBTreesParams(), bool update=false ); virtual float predict( const CvMat* sample, const CvMat* missing=0, CvMat* weakResponses=0, CvSlice slice = CV_WHOLE_SEQ, int k=-1 ) const; CV_WRAP virtual void clear(); virtual float calc_error( CvMLData* _data, int type, std::vector<float> *resp = 0 ); virtual void write( CvFileStorage* fs, const char* name ) const; virtual void read( CvFileStorage* fs, CvFileNode* node ); // new-style C++ interface CV_WRAP CvGBTrees( const cv::Mat& trainData, int tflag, const cv::Mat& responses, const cv::Mat& varIdx=cv::Mat(), const cv::Mat& sampleIdx=cv::Mat(), const cv::Mat& varType=cv::Mat(), const cv::Mat& missingDataMask=cv::Mat(), CvGBTreesParams params=CvGBTreesParams() ); CV_WRAP virtual bool train( const cv::Mat& trainData, int tflag, const cv::Mat& responses, const cv::Mat& varIdx=cv::Mat(), const cv::Mat& sampleIdx=cv::Mat(), const cv::Mat& varType=cv::Mat(), const cv::Mat& missingDataMask=cv::Mat(), CvGBTreesParams params=CvGBTreesParams(), bool update=false ); CV_WRAP virtual float predict( const cv::Mat& sample, const cv::Mat& missing=cv::Mat(), const cv::Range& slice = cv::Range::all(), int k=-1 ) const; protected: virtual void find_gradient( const int k = 0); virtual void change_values(CvDTree* tree, const int k = 0); virtual float find_optimal_value( const CvMat* _Idx ); virtual void do_subsample(); void leaves_get( CvDTreeNode** leaves, int& count, CvDTreeNode* node ); CvDTreeNode** GetLeaves( const CvDTree* dtree, int& len ); virtual bool problem_type() const; virtual void write_params( CvFileStorage* fs ) const; virtual void read_params( CvFileStorage* fs, CvFileNode* fnode ); CvDTreeTrainData* data; CvGBTreesParams params; CvSeq** weak; CvMat* orig_response; CvMat* sum_response; CvMat* sum_response_tmp; CvMat* weak_eval; CvMat* sample_idx; CvMat* subsample_train; CvMat* subsample_test; CvMat* missing; CvMat* class_labels; cv::RNG* rng; int class_count; float delta; float base_value; };
opencv2/highgui/highgui_c.h
OpenCV 2.2の目玉の一つはQtによるGUIの追加だと思われます。その関係の関数がたくさん増えました。
Qt
//YV //-----------New for Qt /* For font */ enum { CV_FONT_LIGHT = 25,//QFont::Light, CV_FONT_NORMAL = 50,//QFont::Normal, CV_FONT_DEMIBOLD = 63,//QFont::DemiBold, CV_FONT_BOLD = 75,//QFont::Bold, CV_FONT_BLACK = 87 //QFont::Black }; enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal, CV_STYLE_ITALIC = 1,//QFont::StyleItalic, CV_STYLE_OBLIQUE = 2 //QFont::StyleOblique }; /* ---------*/ //for color cvScalar(blue_component, green_component, red\_component[, alpha_component]) //and alpha= 0 <-> 0xFF (not transparent <-> transparent) CVAPI(CvFont) cvFontQt(const char* nameFont, int pointSize CV_DEFAULT(-1), CvScalar color CV_DEFAULT(cvScalarAll(0)), int weight CV_DEFAULT(CV_FONT_NORMAL), int style CV_DEFAULT(CV_STYLE_NORMAL), int spacing CV_DEFAULT(0)); CVAPI(void) cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont *arg2); CVAPI(void) cvDisplayOverlay(const char* name, const char* text, int delayms); CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms); typedef void (CV_CDECL *CvOpenGLCallback)(void* userdata); CVAPI(void) cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata CV_DEFAULT(NULL), double angle CV_DEFAULT(-1), double zmin CV_DEFAULT(-1), double zmax CV_DEFAULT(-1)); CVAPI(void) cvSaveWindowParameters(const char* name); CVAPI(void) cvLoadWindowParameters(const char* name); CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); CVAPI(void) cvStopLoop(); typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata); enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1, CV_RADIOBOX = 2}; CVAPI(int) cvCreateButton( const char* button_name CV_DEFAULT(NULL),CvButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL) , int button_type CV_DEFAULT(CV_PUSH_BUTTON), int initial_button_state CV_DEFAULT(0)); //---------------------- // --------- YV --------- enum { //These 3 flags are used by cvSet/GetWindowProperty CV_WND_PROP_FULLSCREEN = 0,//to change/get window's fullscreen property CV_WND_PROP_AUTOSIZE = 1,//to change/get window's autosize property CV_WND_PROP_ASPECTRATIO= 2,//to change/get window's aspectratio property // //These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty CV_WINDOW_NORMAL = 0x00000000,//the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size CV_WINDOW_AUTOSIZE = 0x00000001,//the user cannot resize the window, the size is constrainted by the image displayed // //Those flags are only for Qt CV_GUI_EXPANDED = 0x00000000,//status bar and tool bar CV_GUI_NORMAL = 0x00000010,//old fashious way // //These 3 flags are used by cvNamedWindow and cvSet/GetWindowProperty CV_WINDOW_FULLSCREEN = 1,//change the window to fullscreen CV_WINDOW_FREERATIO = 0x00000100,//the image expends as much as it can (no ratio constraint) CV_WINDOW_KEEPRATIO = 0x00000000//the ration image is respected. };