From 42c6f5cc377b27b90aee327e7a4e6ecb0ba66b17 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Fri, 12 Aug 2011 02:26:54 +0900 Subject: [PATCH] uniformed code format --- ext/opencv/curve.cpp | 4 +- ext/opencv/curve.h | 4 +- ext/opencv/cvbox2d.cpp | 2 +- ext/opencv/cvbox2d.h | 4 +- ext/opencv/cvcondensation.cpp | 2 +- ext/opencv/cvhaarclassifiercascade.h | 4 +- ext/opencv/cvmat.cpp | 8 +- ext/opencv/cvmemstorage.cpp | 2 +- ext/opencv/cvpoint2d32f.cpp | 4 +- ext/opencv/cvpoint2d32f.h | 4 +- ext/opencv/cvpoint3d32f.cpp | 6 +- ext/opencv/cvpoint3d32f.h | 6 +- ext/opencv/cvrect.cpp | 2 +- ext/opencv/cvrect.h | 4 +- ext/opencv/cvseq.cpp | 2 +- ext/opencv/cvset.cpp | 2 +- ext/opencv/cvsize.cpp | 2 +- ext/opencv/cvsize.h | 4 +- ext/opencv/cvsize2d32f.cpp | 6 +- ext/opencv/cvsurfparams.cpp | 2 +- ext/opencv/cvsurfpoint.cpp | 2 +- ext/opencv/cvtermcriteria.cpp | 4 +- ext/opencv/cvtermcriteria.h | 2 +- ext/opencv/gui.cpp | 2 +- ext/opencv/iplimage.cpp | 180 ++++++++++++++------------- ext/opencv/mouseevent.h | 4 +- ext/opencv/pointset.cpp | 6 +- ext/opencv/pointset.h | 2 +- ext/opencv/trackbar.h | 7 +- ext/opencv/window.h | 2 +- 30 files changed, 144 insertions(+), 141 deletions(-) diff --git a/ext/opencv/curve.cpp b/ext/opencv/curve.cpp index 8a506a8..0c87c13 100644 --- a/ext/opencv/curve.cpp +++ b/ext/opencv/curve.cpp @@ -7,7 +7,7 @@ Copyright (C) 2005 Masakazu Yonekura ************************************************************/ -#include"curve.h" +#include "curve.h" /* * Document-class: OpenCV::Curve * @@ -27,7 +27,7 @@ rb_module() void define_ruby_module() { - if(module) + if (module) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/curve.h b/ext/opencv/curve.h index ededafa..182ad5a 100644 --- a/ext/opencv/curve.h +++ b/ext/opencv/curve.h @@ -10,9 +10,9 @@ #ifndef RUBY_OPENCV_CVSEQ_CURVE_H #define RUBY_OPENCV_CVSEQ_CURVE_H -#include"opencv.h" +#include "opencv.h" -#define __NAMESPACE_BEGIN_CURVE namespace mCurve{ +#define __NAMESPACE_BEGIN_CURVE namespace mCurve { #define __NAMESPACE_END_CURVE } __NAMESPACE_BEGIN_OPENCV diff --git a/ext/opencv/cvbox2d.cpp b/ext/opencv/cvbox2d.cpp index f90d9d4..e2cd197 100644 --- a/ext/opencv/cvbox2d.cpp +++ b/ext/opencv/cvbox2d.cpp @@ -32,7 +32,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvbox2d.h b/ext/opencv/cvbox2d.h index 36eec51..95a1861 100644 --- a/ext/opencv/cvbox2d.h +++ b/ext/opencv/cvbox2d.h @@ -10,9 +10,9 @@ #ifndef RUBY_OPENCV_CVBOX2D_H #define RUBY_OPENCV_CVBOX2D_H -#include"opencv.h" +#include "opencv.h" -#define __NAMESPACE_BEGIN_CVBOX2D namespace cCvBox2D{ +#define __NAMESPACE_BEGIN_CVBOX2D namespace cCvBox2D { #define __NAMESPACE_END_CVBOX2D } __NAMESPACE_BEGIN_OPENCV diff --git a/ext/opencv/cvcondensation.cpp b/ext/opencv/cvcondensation.cpp index be74c86..e208a75 100644 --- a/ext/opencv/cvcondensation.cpp +++ b/ext/opencv/cvcondensation.cpp @@ -26,7 +26,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvhaarclassifiercascade.h b/ext/opencv/cvhaarclassifiercascade.h index 8551b9e..a167556 100644 --- a/ext/opencv/cvhaarclassifiercascade.h +++ b/ext/opencv/cvhaarclassifiercascade.h @@ -10,10 +10,10 @@ #ifndef RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H #define RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H -#define __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE namespace cCvHaarClassifierCascade{ +#define __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE namespace cCvHaarClassifierCascade { #define __NAMESPACE_END_CVHAARCLASSIFERCASCADE } -#include"opencv.h" +#include "opencv.h" __NAMESPACE_BEGIN_OPENCV __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE diff --git a/ext/opencv/cvmat.cpp b/ext/opencv/cvmat.cpp index a2075a5..bd23067 100644 --- a/ext/opencv/cvmat.cpp +++ b/ext/opencv/cvmat.cpp @@ -14,7 +14,7 @@ * CvMat is basic 2D matrix class in OpenCV. * * C structure is here. - * typedef struct CvMat{ + * typedef struct CvMat { * int type; * int step; * int *refcount; @@ -460,7 +460,7 @@ rb_method_missing(int argc, VALUE *argv, VALUE self) rb_scan_args(argc, argv, "1*", &name, &args); if (RARRAY_LEN(args) != 0) return rb_call_super(argc, argv); - if(rb_reg_match(rb_reg_new(to_str, strlen(to_str), 0), rb_funcall(name, rb_intern("to_s"), 0)) == Qnil) + if (rb_reg_match(rb_reg_new(to_str, strlen(to_str), 0), rb_funcall(name, rb_intern("to_s"), 0)) == Qnil) return rb_call_super(argc, argv); str[0] = rb_str_new2("%s2%s"); str[1] = rb_color_model(self); @@ -1017,7 +1017,7 @@ rb_get_cols(VALUE self, VALUE args) /* * call-seq: - * each_row{|row| ... } -> self + * each_row {|row| ... } -> self * * Calls block once for each row in self, passing that element as a parameter. * @@ -3591,7 +3591,7 @@ rb_good_features_to_track(int argc, VALUE *argv, VALUE self) rb_scan_args(argc, argv, "21", &quality_level, &min_distance, &good_features_to_track_option); good_features_to_track_option = GOOD_FEATURES_TO_TRACK_OPTION(good_features_to_track_option); int np = GF_MAX(good_features_to_track_option); - if(np <= 0) + if (np <= 0) rb_raise(rb_eArgError, "option :max should be positive value."); CvMat *self_ptr = CVMAT(self); diff --git a/ext/opencv/cvmemstorage.cpp b/ext/opencv/cvmemstorage.cpp index f197204..cd3bf0f 100644 --- a/ext/opencv/cvmemstorage.cpp +++ b/ext/opencv/cvmemstorage.cpp @@ -27,7 +27,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvpoint2d32f.cpp b/ext/opencv/cvpoint2d32f.cpp index 19383bb..2d1795a 100644 --- a/ext/opencv/cvpoint2d32f.cpp +++ b/ext/opencv/cvpoint2d32f.cpp @@ -7,7 +7,7 @@ Copyright (C) 2005 Masakazu Yonekura ************************************************************/ -#include"cvpoint2d32f.h" +#include "cvpoint2d32f.h" /* * Document-class: OpenCV::CvPoint2D32f * @@ -34,7 +34,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvpoint2d32f.h b/ext/opencv/cvpoint2d32f.h index ecdd025..020af23 100644 --- a/ext/opencv/cvpoint2d32f.h +++ b/ext/opencv/cvpoint2d32f.h @@ -10,10 +10,10 @@ #ifndef RUBY_OPENCV_CVPOINT2D32F_H #define RUBY_OPENCV_CVPOINT2D32F_H -#define __NAMESPACE_BEGIN_CVPOINT2D32F namespace cCvPoint2D32f{ +#define __NAMESPACE_BEGIN_CVPOINT2D32F namespace cCvPoint2D32f { #define __NAMESPACE_END_CVPOINT2D32F } -#include"opencv.h" +#include "opencv.h" __NAMESPACE_BEGIN_OPENCV __NAMESPACE_BEGIN_CVPOINT2D32F diff --git a/ext/opencv/cvpoint3d32f.cpp b/ext/opencv/cvpoint3d32f.cpp index ca54d48..117fefe 100644 --- a/ext/opencv/cvpoint3d32f.cpp +++ b/ext/opencv/cvpoint3d32f.cpp @@ -7,7 +7,7 @@ Copyright (C) 2005-2008 Masakazu Yonekura ************************************************************/ -#include"cvpoint3d32f.h" +#include "cvpoint3d32f.h" /* * Document-class: OpenCV::CvPoint3D32f * @@ -15,7 +15,7 @@ * X and Y takes the value of the Float. see also CvPoint * * C structure is here, very simple. - * typdef struct CvPoint3D32f{ + * typdef struct CvPoint3D32f { * float x; * float y; * float z; @@ -35,7 +35,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvpoint3d32f.h b/ext/opencv/cvpoint3d32f.h index 6f74edc..f8e47fa 100644 --- a/ext/opencv/cvpoint3d32f.h +++ b/ext/opencv/cvpoint3d32f.h @@ -10,10 +10,10 @@ #ifndef RUBY_OPENCV_CVPOINT3D32F_H #define RUBY_OPENCV_CVPOINT3D32F_H -#define __NAMESPACE_BEGIN_CVPOINT3D32F namespace cCvPoint3D32f{ +#define __NAMESPACE_BEGIN_CVPOINT3D32F namespace cCvPoint3D32f { #define __NAMESPACE_END_CVPOINT3D32F } -#include"opencv.h" +#include "opencv.h" __NAMESPACE_BEGIN_OPENCV __NAMESPACE_BEGIN_CVPOINT3D32F @@ -56,7 +56,7 @@ VALUE_TO_CVPOINT3D32F(VALUE object) NUM2DBL(rb_funcall(object, rb_intern("y"), 0)), NUM2DBL(rb_funcall(object, rb_intern("z"), 0))); } - else{ + else { raise_compatible_typeerror(object, cCvPoint3D32f::rb_class()); } } diff --git a/ext/opencv/cvrect.cpp b/ext/opencv/cvrect.cpp index a0f7e2f..5f8f105 100644 --- a/ext/opencv/cvrect.cpp +++ b/ext/opencv/cvrect.cpp @@ -37,7 +37,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvrect.h b/ext/opencv/cvrect.h index f266cd9..43f4997 100644 --- a/ext/opencv/cvrect.h +++ b/ext/opencv/cvrect.h @@ -10,9 +10,9 @@ #ifndef RUBY_OPENCV_CVRECT_H #define RUBY_OPENCV_CVRECT_H -#include"opencv.h" +#include "opencv.h" -#define __NAMESPACE_BEGIN_CVRECT namespace cCvRect{ +#define __NAMESPACE_BEGIN_CVRECT namespace cCvRect { #define __NAMESPACE_END_CVRECT } __NAMESPACE_BEGIN_OPENCV diff --git a/ext/opencv/cvseq.cpp b/ext/opencv/cvseq.cpp index 914bbc8..e2f20ed 100644 --- a/ext/opencv/cvseq.cpp +++ b/ext/opencv/cvseq.cpp @@ -469,7 +469,7 @@ VALUE rb_shift(VALUE self) { CvSeq *seq = CVSEQ(self); - if(seq->total == 0) + if (seq->total == 0) return Qnil; VALUE object = Qnil; diff --git a/ext/opencv/cvset.cpp b/ext/opencv/cvset.cpp index ea17615..041b826 100644 --- a/ext/opencv/cvset.cpp +++ b/ext/opencv/cvset.cpp @@ -27,7 +27,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvsize.cpp b/ext/opencv/cvsize.cpp index 96565fb..ec775ed 100644 --- a/ext/opencv/cvsize.cpp +++ b/ext/opencv/cvsize.cpp @@ -34,7 +34,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvsize.h b/ext/opencv/cvsize.h index 62bbaf6..fd30027 100644 --- a/ext/opencv/cvsize.h +++ b/ext/opencv/cvsize.h @@ -10,9 +10,9 @@ #ifndef RUBY_OPENCV_CVSIZE_H #define RUBY_OPENCV_CVSIZE_H -#include"opencv.h" +#include "opencv.h" -#define __NAMESPACE_BEGIN_CVSIZE namespace cCvSize{ +#define __NAMESPACE_BEGIN_CVSIZE namespace cCvSize { #define __NAMESPACE_END_CVSIZE } __NAMESPACE_BEGIN_OPENCV diff --git a/ext/opencv/cvsize2d32f.cpp b/ext/opencv/cvsize2d32f.cpp index 87fa531..1e1c70b 100644 --- a/ext/opencv/cvsize2d32f.cpp +++ b/ext/opencv/cvsize2d32f.cpp @@ -15,10 +15,10 @@ * X and Y takes the value of the Float. * * C structure is here, very simple. - * typdef struct CvSize2D32f{ + * typdef struct CvSize2D32f { * float width; * float height; - * }CvSize2D32f; + * } CvSize2D32f; */ __NAMESPACE_BEGIN_OPENCV __NAMESPACE_BEGIN_CVSIZE2D32F @@ -34,7 +34,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvsurfparams.cpp b/ext/opencv/cvsurfparams.cpp index 5aa125b..a493d54 100644 --- a/ext/opencv/cvsurfparams.cpp +++ b/ext/opencv/cvsurfparams.cpp @@ -33,7 +33,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvsurfpoint.cpp b/ext/opencv/cvsurfpoint.cpp index 46c2e7a..84bca7e 100644 --- a/ext/opencv/cvsurfpoint.cpp +++ b/ext/opencv/cvsurfpoint.cpp @@ -38,7 +38,7 @@ rb_class() void define_ruby_class() { - if(rb_klass) + if (rb_klass) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/cvtermcriteria.cpp b/ext/opencv/cvtermcriteria.cpp index e9c08b3..60fa83b 100644 --- a/ext/opencv/cvtermcriteria.cpp +++ b/ext/opencv/cvtermcriteria.cpp @@ -7,7 +7,7 @@ Copyright (C) 2005-2006 Masakazu Yonekura ************************************************************/ -#include"cvtermcriteria.h" +#include "cvtermcriteria.h" /* * Document-class: OpenCV::CvTermCriteria * @@ -150,7 +150,7 @@ VALUE rb_eps(VALUE self) { CvTermCriteria *ptr = CVTERMCRITERIA(self); - if(ptr->type & CV_TERMCRIT_EPS) + if (ptr->type & CV_TERMCRIT_EPS) return rb_float_new(ptr->epsilon); else return Qnil; diff --git a/ext/opencv/cvtermcriteria.h b/ext/opencv/cvtermcriteria.h index 7ff5c2c..0e74755 100644 --- a/ext/opencv/cvtermcriteria.h +++ b/ext/opencv/cvtermcriteria.h @@ -12,7 +12,7 @@ #include "opencv.h" -#define __NAMESPACE_BEGIN_CVTERMCRITERIA namespace cCvTermCriteria{ +#define __NAMESPACE_BEGIN_CVTERMCRITERIA namespace cCvTermCriteria { #define __NAMESPACE_END_CVTERMCRITERIA } __NAMESPACE_BEGIN_OPENCV diff --git a/ext/opencv/gui.cpp b/ext/opencv/gui.cpp index 4c8c5b8..f2240b4 100644 --- a/ext/opencv/gui.cpp +++ b/ext/opencv/gui.cpp @@ -28,7 +28,7 @@ rb_module_GUI() void define_ruby_module() { - if(rb_module) + if (rb_module) return; /* * opencv = rb_define_module("OpenCV"); diff --git a/ext/opencv/iplimage.cpp b/ext/opencv/iplimage.cpp index aa62180..b5d3742 100644 --- a/ext/opencv/iplimage.cpp +++ b/ext/opencv/iplimage.cpp @@ -272,25 +272,29 @@ rb_smoothness(int argc, VALUE *argv, VALUE self) double outLowDensity, outHighDensity; if (TYPE(lowFreqRatio) == T_NIL) { f_lowFreqRatio = 10 / 128.0f; - } else { + } + else { Check_Type(lowFreqRatio, T_FLOAT); f_lowFreqRatio = NUM2DBL(lowFreqRatio); } if (TYPE(blankDensity) == T_NIL) { f_blankDensity = 1.2f; - } else { + } + else { Check_Type(blankDensity, T_FLOAT); f_blankDensity = NUM2DBL(blankDensity); } if (TYPE(messyDensity) == T_NIL) { f_messyDensity = 0.151f; - } else { + } + else { Check_Type(messyDensity, T_FLOAT); f_messyDensity = NUM2DBL(messyDensity); } if (TYPE(highFreqRatio) == T_NIL) { f_highFreqRatio = 5 / 128.0f; - } else { + } + else { Check_Type(highFreqRatio, T_FLOAT); f_highFreqRatio = NUM2DBL(highFreqRatio); } @@ -300,30 +304,31 @@ rb_smoothness(int argc, VALUE *argv, VALUE self) // the image is required to be in depth of 64 if (IPLIMAGE(self)->depth == 64) { - p64DepthImage = NULL; - pFourierImage = create_fourier_image(IPLIMAGE(self)); - } else { - p64DepthImage = rb_cvCreateImage(cvGetSize(IPLIMAGE(self)), IPL_DEPTH_64F, 1); - cvConvertScale(CVARR(self), p64DepthImage, 1.0, 0.0); - pFourierImage = create_fourier_image(p64DepthImage); + p64DepthImage = NULL; + pFourierImage = create_fourier_image(IPLIMAGE(self)); + } + else { + p64DepthImage = rb_cvCreateImage(cvGetSize(IPLIMAGE(self)), IPL_DEPTH_64F, 1); + cvConvertScale(CVARR(self), p64DepthImage, 1.0, 0.0); + pFourierImage = create_fourier_image(p64DepthImage); } - Smoothness result = compute_smoothness(pFourierImage, f_lowFreqRatio, f_blankDensity, f_messyDensity, f_highFreqRatio, outLowDensity, outHighDensity); + Smoothness result = compute_smoothness(pFourierImage, f_lowFreqRatio, f_blankDensity, f_messyDnsity, + f_highFreqRatio, outLowDensity, outHighDensity); cvReleaseImage(&pFourierImage); if (p64DepthImage != NULL) - cvReleaseImage(&p64DepthImage); + cvReleaseImage(&p64DepthImage); - switch(result) - { - case SMOOTH: - return rb_ary_new3(3, ID2SYM(rb_intern("smooth")), rb_float_new(outLowDensity), rb_float_new(outHighDensity)); - case MESSY: - return rb_ary_new3(3, ID2SYM(rb_intern("messy")), rb_float_new(outLowDensity), rb_float_new(outHighDensity)); - case BLANK: - return rb_ary_new3(3, ID2SYM(rb_intern("blank")), rb_float_new(outLowDensity), rb_float_new(outHighDensity)); - default: - return rb_ary_new3(3, NULL, rb_float_new(outLowDensity), rb_float_new(outHighDensity)); + switch(result) { + case SMOOTH: + return rb_ary_new3(3, ID2SYM(rb_intern("smooth")), rb_float_new(outLowDensity), rb_float_new(outHighDensity)); + case MESSY: + return rb_ary_new3(3, ID2SYM(rb_intern("messy")), rb_float_new(outLowDensity), rb_float_new(outHighDensity)); + case BLANK: + return rb_ary_new3(3, ID2SYM(rb_intern("blank")), rb_float_new(outLowDensity), rb_float_new(outHighDensity)); + default: + return rb_ary_new3(3, NULL, rb_float_new(outLowDensity), rb_float_new(outHighDensity)); } } @@ -333,7 +338,9 @@ rb_smoothness(int argc, VALUE *argv, VALUE self) * else -> good; */ Smoothness -compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, const double blankDensity, const double messyDensity, const double highFreqRatio, double &outLowDensity, double &outHighDensity) +compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, const double blankDensity, + const double messyDensity, const double highFreqRatio, double &outLowDensity + double &outHighDensity) { int low, high; IplImage *filteredFourierImage; @@ -341,10 +348,11 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con double sum, den, totalArea; CvScalar scalar; - if(! (pFourierImage->nChannels == 1 && pFourierImage->depth == 64) ) { - cvError( CV_StsUnmatchedSizes, "compute_smoothness", "input image must contain only 1 channel and a depth of 64", __FILE__, __LINE__ ); + if (!(pFourierImage->nChannels == 1 && pFourierImage->depth == 64) ) { + cvError(CV_StsUnmatchedSizes, "compute_smoothness", "input image must contain only 1 channel and a depth of 64", + __FILE__, __LINE__ ); } - + high_pass_range(pFourierImage, lowFreqRatio, low, high ); totalArea = M_PI * (high * high - low * low); @@ -354,12 +362,11 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con cvReleaseImage(&filteredFourierImage); outLowDensity = den = totalIntensity / totalArea; - if(den <= blankDensity) - { + if (den <= blankDensity) { return BLANK; } - low = (int) (high * (1.0 - highFreqRatio)); + low = (int)(high * (1.0 - highFreqRatio)); filteredFourierImage = create_frequency_filtered_image(pFourierImage, low, high); scalar = cvSum(filteredFourierImage); @@ -367,8 +374,7 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con cvReleaseImage(&filteredFourierImage); outHighDensity = den = totalIntensity / totalArea; - if(den >= messyDensity) - { + if (den >= messyDensity) { return MESSY; } @@ -393,37 +399,39 @@ cvShiftDFT(CvArr *src_arr, CvArr *dst_arr ) CvSize dst_size = cvGetSize(dst_arr); int cx, cy; - if(dst_size.width != size.width || - dst_size.height != size.height){ - cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ ); + if (dst_size.width != size.width || + dst_size.height != size.height) { + cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", + __FILE__, __LINE__ ); } - if(src_arr==dst_arr){ - tmp = rb_cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr)); + if (src_arr == dst_arr) { + tmp = rb_cvCreateMat(size.height / 2, size.width / 2, cvGetElemType(src_arr)); } + + cx = size.width / 2; + cy = size.height / 2; // image center - cx = size.width/2; - cy = size.height/2; // image center + q1 = cvGetSubRect(src_arr, &q1stub, cvRect(0,0,cx, cy)); + q2 = cvGetSubRect(src_arr, &q2stub, cvRect(cx,0,cx,cy)); + q3 = cvGetSubRect(src_arr, &q3stub, cvRect(cx,cy,cx,cy)); + q4 = cvGetSubRect(src_arr, &q4stub, cvRect(0,cy,cx,cy)); + d1 = cvGetSubRect(src_arr, &d1stub, cvRect(0,0,cx,cy)); + d2 = cvGetSubRect(src_arr, &d2stub, cvRect(cx,0,cx,cy)); + d3 = cvGetSubRect(src_arr, &d3stub, cvRect(cx,cy,cx,cy)); + d4 = cvGetSubRect(src_arr, &d4stub, cvRect(0,cy,cx,cy)); - q1 = cvGetSubRect( src_arr, &q1stub, cvRect(0,0,cx, cy) ); - q2 = cvGetSubRect( src_arr, &q2stub, cvRect(cx,0,cx,cy) ); - q3 = cvGetSubRect( src_arr, &q3stub, cvRect(cx,cy,cx,cy) ); - q4 = cvGetSubRect( src_arr, &q4stub, cvRect(0,cy,cx,cy) ); - d1 = cvGetSubRect( src_arr, &d1stub, cvRect(0,0,cx,cy) ); - d2 = cvGetSubRect( src_arr, &d2stub, cvRect(cx,0,cx,cy) ); - d3 = cvGetSubRect( src_arr, &d3stub, cvRect(cx,cy,cx,cy) ); - d4 = cvGetSubRect( src_arr, &d4stub, cvRect(0,cy,cx,cy) ); - - if(src_arr!=dst_arr){ - if( !CV_ARE_TYPES_EQ( q1, d1 )){ - cvError( CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ ); + if (src_arr != dst_arr) { + if (!CV_ARE_TYPES_EQ(q1, d1)) { + cvError(CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", + __FILE__, __LINE__ ); } cvCopy(q3, d1, 0); cvCopy(q4, d2, 0); cvCopy(q1, d3, 0); cvCopy(q2, d4, 0); } - else{ + else { cvCopy(q3, tmp, 0); cvCopy(q1, q3, 0); cvCopy(tmp, q1, 0); @@ -432,16 +440,14 @@ cvShiftDFT(CvArr *src_arr, CvArr *dst_arr ) cvCopy(tmp, q2, 0); } - if (tmp != NULL) - { - cvReleaseMat(&tmp); + if (tmp != NULL) { + cvReleaseMat(&tmp); } } IplImage* create_fourier_image(const IplImage *im) { - IplImage *realInput; IplImage *imaginaryInput; IplImage *complexInput; @@ -450,51 +456,50 @@ create_fourier_image(const IplImage *im) IplImage *image_Re; IplImage *image_Im; - realInput = rb_cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1); - imaginaryInput = rb_cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1); - complexInput = rb_cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2); + realInput = rb_cvCreateImage(cvGetSize(im), IPL_DEPTH_64F, 1); + imaginaryInput = rb_cvCreateImage(cvGetSize(im), IPL_DEPTH_64F, 1); + complexInput = rb_cvCreateImage(cvGetSize(im), IPL_DEPTH_64F, 2); cvScale(im, realInput, 1.0, 0.0); cvZero(imaginaryInput); cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput); - dft_M = cvGetOptimalDFTSize( im->height - 1 ); - dft_N = cvGetOptimalDFTSize( im->width - 1 ); + dft_M = cvGetOptimalDFTSize(im->height - 1); + dft_N = cvGetOptimalDFTSize(im->width - 1); - dft_A = rb_cvCreateMat( dft_M, dft_N, CV_64FC2 ); - image_Re = rb_cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1); - image_Im = rb_cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1); + dft_A = rb_cvCreateMat(dft_M, dft_N, CV_64FC2); + image_Re = rb_cvCreateImage(cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1); + image_Im = rb_cvCreateImage(cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1); // copy A to dft_A and pad dft_A with zeros - cvGetSubRect( dft_A, &tmp, cvRect(0,0, im->width, im->height)); - cvCopy( complexInput, &tmp, NULL ); - if( dft_A->cols > im->width ) - { - cvGetSubRect( dft_A, &tmp, cvRect(im->width,0, dft_A->cols - im->width, im->height)); - cvZero( &tmp ); + cvGetSubRect(dft_A, &tmp, cvRect(0,0, im->width, im->height)); + cvCopy(complexInput, &tmp, NULL); + if (dft_A->cols > im->width) { + cvGetSubRect(dft_A, &tmp, cvRect(im->width,0, dft_A->cols - im->width, im->height)); + cvZero(&tmp); } // no need to pad bottom part of dft_A with zeros because of // use nonzero_rows parameter in cvDFT() call below - cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height ); + cvDFT(dft_A, dft_A, CV_DXT_FORWARD, complexInput->height); // Split Fourier in real and imaginary parts - cvSplit( dft_A, image_Re, image_Im, 0, 0 ); + cvSplit(dft_A, image_Re, image_Im, 0, 0); // Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2) - cvPow( image_Re, image_Re, 2.0); - cvPow( image_Im, image_Im, 2.0); - cvAdd( image_Re, image_Im, image_Re, NULL); - cvPow( image_Re, image_Re, 0.5 ); + cvPow(image_Re, image_Re, 2.0); + cvPow(image_Im, image_Im, 2.0); + cvAdd(image_Re, image_Im, image_Re, NULL); + cvPow(image_Re, image_Re, 0.5); // Compute log(1 + Mag) - cvAddS( image_Re, cvScalarAll(1.0), image_Re, NULL ); // 1 + Mag - cvLog( image_Re, image_Re ); // log(1 + Mag) + cvAddS(image_Re, cvScalarAll(1.0), image_Re, NULL); // 1 + Mag + cvLog(image_Re, image_Re); // log(1 + Mag) // Rearrange the quadrants of Fourier image so that the origin is at // the image center - cvShiftDFT( image_Re, image_Re ); + cvShiftDFT(image_Re, image_Re); cvReleaseImage(&realInput); cvReleaseImage(&imaginaryInput); @@ -504,7 +509,6 @@ create_fourier_image(const IplImage *im) cvReleaseMat(&dft_A); return image_Re; - } IplImage* @@ -520,18 +524,18 @@ create_frequency_filtered_image(const IplImage *pImage, int low, int high) box.size.width = high; box.size.height = high; - IplImage *pFilterMask = rb_cvCreateImage( cvGetSize(pImage), IPL_DEPTH_64F, 1 ); - IplImage *pFiltered = rb_cvCreateImage( cvGetSize(pImage), IPL_DEPTH_64F, 1 ); + IplImage *pFilterMask = rb_cvCreateImage(cvGetSize(pImage), IPL_DEPTH_64F, 1); + IplImage *pFiltered = rb_cvCreateImage(cvGetSize(pImage), IPL_DEPTH_64F, 1); cvZero(pFilterMask); cvZero(pFiltered); - if(high > 0) + if (high > 0) cvEllipseBox(pFilterMask, box, cvScalar(255, 255, 255, 255), CV_FILLED, 8, 0); box.size.width = low; box.size.height = low; - if(low > 0) + if (low > 0) cvEllipseBox(pFilterMask, box, cvScalar(0, 0, 0, 0), CV_FILLED, 8, 0); cvAnd(pImage, pFilterMask, pFiltered, NULL); @@ -544,17 +548,15 @@ create_frequency_filtered_image(const IplImage *pImage, int low, int high) void high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &outHigh) { - if(lostPercentage > 1.0f) - { + if (lostPercentage > 1.0f) { lostPercentage = 1; } - else if(lostPercentage < 0.0f ) - { + else if (lostPercentage < 0.0f) { lostPercentage = 0; } - outHigh = (int) MIN( pImage->width, pImage->height ); - outLow = (int) (lostPercentage * outHigh); + outHigh = (int)MIN(pImage->width, pImage->height); + outLow = (int)(lostPercentage * outHigh); } diff --git a/ext/opencv/mouseevent.h b/ext/opencv/mouseevent.h index 7ff539a..55b29a5 100644 --- a/ext/opencv/mouseevent.h +++ b/ext/opencv/mouseevent.h @@ -7,13 +7,13 @@ Copyright (C) 2005-2006 Masakazu Yonekura ************************************************************/ -#define __NAMESPACE_BEGIN_MOUSEEVENT namespace cMouseEvent{ +#define __NAMESPACE_BEGIN_MOUSEEVENT namespace cMouseEvent { #define __NAMESPACE_END_MOUSEEVENT } #ifndef RUBY_OPENCV_GUI_MOUSEEVENT_H #define RUBY_OPENCV_GUI_MOUSEEVENT_H -#include"opencv.h" +#include "opencv.h" __NAMESPACE_BEGIN_OPENCV __NAMESPACE_BEGIN_GUI diff --git a/ext/opencv/pointset.cpp b/ext/opencv/pointset.cpp index 2a1b8e1..22e9d96 100644 --- a/ext/opencv/pointset.cpp +++ b/ext/opencv/pointset.cpp @@ -26,7 +26,7 @@ rb_module() void define_ruby_module() { - if(module) + if (module) return; /* * opencv = rb_define_module("OpenCV"); @@ -50,10 +50,10 @@ VALUE rb_extend_object(VALUE self, VALUE object) { CvSeq *seq = 0; - if(!rb_obj_is_kind_of(object, cCvSeq::rb_class())) + if (!rb_obj_is_kind_of(object, cCvSeq::rb_class())) rb_raise(rb_eTypeError, "object is not %s.\n", rb_class2name(cCvSeq::rb_class())); - if(!CV_IS_SEQ(seq)) + if (!CV_IS_SEQ(seq)) rb_raise(rb_eTypeError, "object is not sequence."); return rb_call_super(1, &object); } diff --git a/ext/opencv/pointset.h b/ext/opencv/pointset.h index 34c361b..2e59180 100644 --- a/ext/opencv/pointset.h +++ b/ext/opencv/pointset.h @@ -13,7 +13,7 @@ #define __NAMESPACE_BEGIN_POINT_SET namespace mPointSet { #define __NAMESPACE_END_POINT_SET } -#include"opencv.h" +#include "opencv.h" __NAMESPACE_BEGIN_OPENCV __NAMESPACE_BEGIN_POINT_SET diff --git a/ext/opencv/trackbar.h b/ext/opencv/trackbar.h index ad3b6c3..bbbb3fb 100644 --- a/ext/opencv/trackbar.h +++ b/ext/opencv/trackbar.h @@ -14,9 +14,9 @@ #ifndef RUBY_OPENCV_GUI_TRACKBAR_H #define RUBY_OPENCV_GUI_TRACKBAR_H -#include"opencv.h" +#include "opencv.h" -#define __NAMESPACE_BEGIN_TRACKBAR namespace cTrackbar{ +#define __NAMESPACE_BEGIN_TRACKBAR namespace cTrackbar { #define __NAMESPACE_END_TRACKBAR } __NAMESPACE_BEGIN_OPENCV @@ -47,7 +47,8 @@ VALUE rb_set_value(VALUE self, VALUE val); __NAMESPACE_END_TRACKBAR -inline Trackbar *TRACKBAR(VALUE object) { +inline Trackbar* +TRACKBAR(VALUE object) { Trackbar *ptr; Data_Get_Struct(object, Trackbar, ptr); return ptr; diff --git a/ext/opencv/window.h b/ext/opencv/window.h index 19be758..d359414 100644 --- a/ext/opencv/window.h +++ b/ext/opencv/window.h @@ -15,7 +15,7 @@ #define RUBY_OPENCV_GUI_WINDOW_H #include "opencv.h" -#define __NAMESPACE_BEGIN_WINDOW namespace cWindow{ +#define __NAMESPACE_BEGIN_WINDOW namespace cWindow { #define __NAMESPACE_END_WINDOW } __NAMESPACE_BEGIN_OPENCV