mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
uniformed code format
This commit is contained in:
parent
2ac67221f9
commit
42c6f5cc37
30 changed files with 144 additions and 141 deletions
|
@ -272,25 +272,29 @@ rb_smoothness(int argc, VALUE *argv, VALUE self)
|
||||||
double outLowDensity, outHighDensity;
|
double outLowDensity, outHighDensity;
|
||||||
if (TYPE(lowFreqRatio) == T_NIL) {
|
if (TYPE(lowFreqRatio) == T_NIL) {
|
||||||
f_lowFreqRatio = 10 / 128.0f;
|
f_lowFreqRatio = 10 / 128.0f;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Check_Type(lowFreqRatio, T_FLOAT);
|
Check_Type(lowFreqRatio, T_FLOAT);
|
||||||
f_lowFreqRatio = NUM2DBL(lowFreqRatio);
|
f_lowFreqRatio = NUM2DBL(lowFreqRatio);
|
||||||
}
|
}
|
||||||
if (TYPE(blankDensity) == T_NIL) {
|
if (TYPE(blankDensity) == T_NIL) {
|
||||||
f_blankDensity = 1.2f;
|
f_blankDensity = 1.2f;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Check_Type(blankDensity, T_FLOAT);
|
Check_Type(blankDensity, T_FLOAT);
|
||||||
f_blankDensity = NUM2DBL(blankDensity);
|
f_blankDensity = NUM2DBL(blankDensity);
|
||||||
}
|
}
|
||||||
if (TYPE(messyDensity) == T_NIL) {
|
if (TYPE(messyDensity) == T_NIL) {
|
||||||
f_messyDensity = 0.151f;
|
f_messyDensity = 0.151f;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Check_Type(messyDensity, T_FLOAT);
|
Check_Type(messyDensity, T_FLOAT);
|
||||||
f_messyDensity = NUM2DBL(messyDensity);
|
f_messyDensity = NUM2DBL(messyDensity);
|
||||||
}
|
}
|
||||||
if (TYPE(highFreqRatio) == T_NIL) {
|
if (TYPE(highFreqRatio) == T_NIL) {
|
||||||
f_highFreqRatio = 5 / 128.0f;
|
f_highFreqRatio = 5 / 128.0f;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Check_Type(highFreqRatio, T_FLOAT);
|
Check_Type(highFreqRatio, T_FLOAT);
|
||||||
f_highFreqRatio = NUM2DBL(highFreqRatio);
|
f_highFreqRatio = NUM2DBL(highFreqRatio);
|
||||||
}
|
}
|
||||||
|
@ -302,20 +306,21 @@ rb_smoothness(int argc, VALUE *argv, VALUE self)
|
||||||
if (IPLIMAGE(self)->depth == 64) {
|
if (IPLIMAGE(self)->depth == 64) {
|
||||||
p64DepthImage = NULL;
|
p64DepthImage = NULL;
|
||||||
pFourierImage = create_fourier_image(IPLIMAGE(self));
|
pFourierImage = create_fourier_image(IPLIMAGE(self));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
p64DepthImage = rb_cvCreateImage(cvGetSize(IPLIMAGE(self)), IPL_DEPTH_64F, 1);
|
p64DepthImage = rb_cvCreateImage(cvGetSize(IPLIMAGE(self)), IPL_DEPTH_64F, 1);
|
||||||
cvConvertScale(CVARR(self), p64DepthImage, 1.0, 0.0);
|
cvConvertScale(CVARR(self), p64DepthImage, 1.0, 0.0);
|
||||||
pFourierImage = create_fourier_image(p64DepthImage);
|
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);
|
cvReleaseImage(&pFourierImage);
|
||||||
if (p64DepthImage != NULL)
|
if (p64DepthImage != NULL)
|
||||||
cvReleaseImage(&p64DepthImage);
|
cvReleaseImage(&p64DepthImage);
|
||||||
|
|
||||||
switch(result)
|
switch(result) {
|
||||||
{
|
|
||||||
case SMOOTH:
|
case SMOOTH:
|
||||||
return rb_ary_new3(3, ID2SYM(rb_intern("smooth")), rb_float_new(outLowDensity), rb_float_new(outHighDensity));
|
return rb_ary_new3(3, ID2SYM(rb_intern("smooth")), rb_float_new(outLowDensity), rb_float_new(outHighDensity));
|
||||||
case MESSY:
|
case MESSY:
|
||||||
|
@ -333,7 +338,9 @@ rb_smoothness(int argc, VALUE *argv, VALUE self)
|
||||||
* else -> good;
|
* else -> good;
|
||||||
*/
|
*/
|
||||||
Smoothness
|
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;
|
int low, high;
|
||||||
IplImage *filteredFourierImage;
|
IplImage *filteredFourierImage;
|
||||||
|
@ -342,7 +349,8 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con
|
||||||
CvScalar scalar;
|
CvScalar scalar;
|
||||||
|
|
||||||
if (!(pFourierImage->nChannels == 1 && pFourierImage->depth == 64) ) {
|
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__ );
|
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 );
|
high_pass_range(pFourierImage, lowFreqRatio, low, high );
|
||||||
|
@ -354,8 +362,7 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con
|
||||||
cvReleaseImage(&filteredFourierImage);
|
cvReleaseImage(&filteredFourierImage);
|
||||||
outLowDensity = den = totalIntensity / totalArea;
|
outLowDensity = den = totalIntensity / totalArea;
|
||||||
|
|
||||||
if(den <= blankDensity)
|
if (den <= blankDensity) {
|
||||||
{
|
|
||||||
return BLANK;
|
return BLANK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,8 +374,7 @@ compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, con
|
||||||
cvReleaseImage(&filteredFourierImage);
|
cvReleaseImage(&filteredFourierImage);
|
||||||
outHighDensity = den = totalIntensity / totalArea;
|
outHighDensity = den = totalIntensity / totalArea;
|
||||||
|
|
||||||
if(den >= messyDensity)
|
if (den >= messyDensity) {
|
||||||
{
|
|
||||||
return MESSY;
|
return MESSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +401,8 @@ cvShiftDFT(CvArr *src_arr, CvArr *dst_arr )
|
||||||
|
|
||||||
if (dst_size.width != size.width ||
|
if (dst_size.width != size.width ||
|
||||||
dst_size.height != size.height) {
|
dst_size.height != size.height) {
|
||||||
cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ );
|
cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes",
|
||||||
|
__FILE__, __LINE__ );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_arr == dst_arr) {
|
if (src_arr == dst_arr) {
|
||||||
|
@ -416,7 +423,8 @@ cvShiftDFT(CvArr *src_arr, CvArr *dst_arr )
|
||||||
|
|
||||||
if (src_arr != dst_arr) {
|
if (src_arr != dst_arr) {
|
||||||
if (!CV_ARE_TYPES_EQ(q1, d1)) {
|
if (!CV_ARE_TYPES_EQ(q1, d1)) {
|
||||||
cvError( CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ );
|
cvError(CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format",
|
||||||
|
__FILE__, __LINE__ );
|
||||||
}
|
}
|
||||||
cvCopy(q3, d1, 0);
|
cvCopy(q3, d1, 0);
|
||||||
cvCopy(q4, d2, 0);
|
cvCopy(q4, d2, 0);
|
||||||
|
@ -432,8 +440,7 @@ cvShiftDFT(CvArr *src_arr, CvArr *dst_arr )
|
||||||
cvCopy(tmp, q2, 0);
|
cvCopy(tmp, q2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp != NULL)
|
if (tmp != NULL) {
|
||||||
{
|
|
||||||
cvReleaseMat(&tmp);
|
cvReleaseMat(&tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,7 +448,6 @@ cvShiftDFT(CvArr *src_arr, CvArr *dst_arr )
|
||||||
IplImage*
|
IplImage*
|
||||||
create_fourier_image(const IplImage *im)
|
create_fourier_image(const IplImage *im)
|
||||||
{
|
{
|
||||||
|
|
||||||
IplImage *realInput;
|
IplImage *realInput;
|
||||||
IplImage *imaginaryInput;
|
IplImage *imaginaryInput;
|
||||||
IplImage *complexInput;
|
IplImage *complexInput;
|
||||||
|
@ -468,8 +474,7 @@ create_fourier_image(const IplImage *im)
|
||||||
// copy A to dft_A and pad dft_A with zeros
|
// copy A to dft_A and pad dft_A with zeros
|
||||||
cvGetSubRect(dft_A, &tmp, cvRect(0,0, im->width, im->height));
|
cvGetSubRect(dft_A, &tmp, cvRect(0,0, im->width, im->height));
|
||||||
cvCopy(complexInput, &tmp, NULL);
|
cvCopy(complexInput, &tmp, NULL);
|
||||||
if( dft_A->cols > im->width )
|
if (dft_A->cols > im->width) {
|
||||||
{
|
|
||||||
cvGetSubRect(dft_A, &tmp, cvRect(im->width,0, dft_A->cols - im->width, im->height));
|
cvGetSubRect(dft_A, &tmp, cvRect(im->width,0, dft_A->cols - im->width, im->height));
|
||||||
cvZero(&tmp);
|
cvZero(&tmp);
|
||||||
}
|
}
|
||||||
|
@ -504,7 +509,6 @@ create_fourier_image(const IplImage *im)
|
||||||
cvReleaseMat(&dft_A);
|
cvReleaseMat(&dft_A);
|
||||||
|
|
||||||
return image_Re;
|
return image_Re;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IplImage*
|
IplImage*
|
||||||
|
@ -544,12 +548,10 @@ create_frequency_filtered_image(const IplImage *pImage, int low, int high)
|
||||||
void
|
void
|
||||||
high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &outHigh)
|
high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &outHigh)
|
||||||
{
|
{
|
||||||
if(lostPercentage > 1.0f)
|
if (lostPercentage > 1.0f) {
|
||||||
{
|
|
||||||
lostPercentage = 1;
|
lostPercentage = 1;
|
||||||
}
|
}
|
||||||
else if(lostPercentage < 0.0f )
|
else if (lostPercentage < 0.0f) {
|
||||||
{
|
|
||||||
lostPercentage = 0;
|
lostPercentage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ VALUE rb_set_value(VALUE self, VALUE val);
|
||||||
__NAMESPACE_END_TRACKBAR
|
__NAMESPACE_END_TRACKBAR
|
||||||
|
|
||||||
|
|
||||||
inline Trackbar *TRACKBAR(VALUE object) {
|
inline Trackbar*
|
||||||
|
TRACKBAR(VALUE object) {
|
||||||
Trackbar *ptr;
|
Trackbar *ptr;
|
||||||
Data_Get_Struct(object, Trackbar, ptr);
|
Data_Get_Struct(object, Trackbar, ptr);
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue