diff --git a/.gitignore b/.gitignore index e783439d..cfeba504 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.project examples/data *.o *.so @@ -11,3 +12,5 @@ GSYMS GTAGS OpenCV-2.2.0 ruby-1.9.2-p136 +ext/opencv/test.txt +pkg/ diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..5a3b733d --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source :gemcutter + +gem "hoe" +gem "hoe-gemspec" +gem "rspec" \ No newline at end of file diff --git a/Manifest.txt b/Manifest.txt index b7477d89..dcb8b810 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -1,7 +1,7 @@ History.txt -Manifest.txt -README.txt License.txt +Manifest.txt +README.rdoc Rakefile examples/convexhull.rb examples/face_detect.rb @@ -11,99 +11,99 @@ examples/inpaint.rb examples/paint.rb examples/snake.rb examples/stuff.jpg -ext/curve.cpp -ext/curve.h -ext/cvavgcomp.cpp -ext/cvavgcomp.h -ext/cvbox2d.cpp -ext/cvbox2d.h -ext/cvcapture.cpp -ext/cvcapture.h -ext/cvchain.cpp -ext/cvchain.h -ext/cvchaincode.cpp -ext/cvchaincode.h -ext/cvcircle32f.cpp -ext/cvcircle32f.h -ext/cvcondensation.cpp -ext/cvcondensation.h -ext/cvconnectedcomp.cpp -ext/cvconnectedcomp.h -ext/cvcontour.cpp -ext/cvcontour.h -ext/cvcontourtree.cpp -ext/cvcontourtree.h -ext/cvconvexitydefect.cpp -ext/cvconvexitydefect.h -ext/cverror.cpp -ext/cverror.h -ext/cvfont.cpp -ext/cvfont.h -ext/cvhaarclassifiercascade.cpp -ext/cvhaarclassifiercascade.h -ext/cvhistogram.cpp -ext/cvhistogram.h -ext/cvindex.cpp -ext/cvindex.h -ext/cvline.cpp -ext/cvline.h -ext/cvmat.cpp -ext/cvmat.h -ext/cvmatnd.cpp -ext/cvmatnd.h -ext/cvmemstorage.cpp -ext/cvmemstorage.h -ext/cvmoments.cpp -ext/cvmoments.h -ext/cvpoint.cpp -ext/cvpoint.h -ext/cvpoint2d32f.cpp -ext/cvpoint2d32f.h -ext/cvpoint3d32f.cpp -ext/cvpoint3d32f.h -ext/cvrect.cpp -ext/cvrect.h -ext/cvscalar.cpp -ext/cvscalar.h -ext/cvseq.cpp -ext/cvseq.h -ext/cvset.cpp -ext/cvset.h -ext/cvsize.cpp -ext/cvsize.h -ext/cvsize2d32f.cpp -ext/cvsize2d32f.h -ext/cvslice.cpp -ext/cvslice.h -ext/cvsparsemat.cpp -ext/cvsparsemat.h -ext/cvtermcriteria.cpp -ext/cvtermcriteria.h -ext/cvtwopoints.cpp -ext/cvtwopoints.h -ext/cvvector.cpp -ext/cvvector.h -ext/cvvideowriter.cpp -ext/cvvideowriter.h -ext/extconf.rb -ext/gui.cpp -ext/gui.h -ext/iplconvkernel.cpp -ext/iplconvkernel.h -ext/iplimage.cpp -ext/iplimage.h -ext/mouseevent.cpp -ext/mouseevent.h -ext/opencv.cpp -ext/opencv.h -ext/point3dset.cpp -ext/point3dset.h -ext/pointset.cpp -ext/pointset.h -ext/trackbar.cpp -ext/trackbar.h -ext/window.cpp -ext/window.h +ext/opencv/curve.cpp +ext/opencv/curve.h +ext/opencv/cvavgcomp.cpp +ext/opencv/cvavgcomp.h +ext/opencv/cvbox2d.cpp +ext/opencv/cvbox2d.h +ext/opencv/cvcapture.cpp +ext/opencv/cvcapture.h +ext/opencv/cvchain.cpp +ext/opencv/cvchain.h +ext/opencv/cvchaincode.cpp +ext/opencv/cvchaincode.h +ext/opencv/cvcircle32f.cpp +ext/opencv/cvcircle32f.h +ext/opencv/cvcondensation.cpp +ext/opencv/cvcondensation.h +ext/opencv/cvconnectedcomp.cpp +ext/opencv/cvconnectedcomp.h +ext/opencv/cvcontour.cpp +ext/opencv/cvcontour.h +ext/opencv/cvcontourtree.cpp +ext/opencv/cvcontourtree.h +ext/opencv/cvconvexitydefect.cpp +ext/opencv/cvconvexitydefect.h +ext/opencv/cverror.cpp +ext/opencv/cverror.h +ext/opencv/cvfont.cpp +ext/opencv/cvfont.h +ext/opencv/cvhaarclassifiercascade.cpp +ext/opencv/cvhaarclassifiercascade.h +ext/opencv/cvhistogram.cpp +ext/opencv/cvhistogram.h +ext/opencv/cvhumoments.cpp +ext/opencv/cvhumoments.h +ext/opencv/cvindex.cpp +ext/opencv/cvindex.h +ext/opencv/cvline.cpp +ext/opencv/cvline.h +ext/opencv/cvmat.cpp +ext/opencv/cvmat.h +ext/opencv/cvmatnd.cpp +ext/opencv/cvmatnd.h +ext/opencv/cvmemstorage.cpp +ext/opencv/cvmemstorage.h +ext/opencv/cvmoments.cpp +ext/opencv/cvmoments.h +ext/opencv/cvpoint.cpp +ext/opencv/cvpoint.h +ext/opencv/cvpoint2d32f.cpp +ext/opencv/cvpoint2d32f.h +ext/opencv/cvpoint3d32f.cpp +ext/opencv/cvpoint3d32f.h +ext/opencv/cvrect.cpp +ext/opencv/cvrect.h +ext/opencv/cvscalar.cpp +ext/opencv/cvscalar.h +ext/opencv/cvseq.cpp +ext/opencv/cvseq.h +ext/opencv/cvset.cpp +ext/opencv/cvset.h +ext/opencv/cvsize.cpp +ext/opencv/cvsize.h +ext/opencv/cvsize2d32f.cpp +ext/opencv/cvsize2d32f.h +ext/opencv/cvslice.cpp +ext/opencv/cvslice.h +ext/opencv/cvsparsemat.cpp +ext/opencv/cvsparsemat.h +ext/opencv/cvtermcriteria.cpp +ext/opencv/cvtermcriteria.h +ext/opencv/cvtwopoints.cpp +ext/opencv/cvtwopoints.h +ext/opencv/cvvideowriter.cpp +ext/opencv/cvvideowriter.h +ext/opencv/extconf.rb +ext/opencv/gui.cpp +ext/opencv/gui.h +ext/opencv/iplconvkernel.cpp +ext/opencv/iplconvkernel.h +ext/opencv/iplimage.cpp +ext/opencv/iplimage.h +ext/opencv/mouseevent.cpp +ext/opencv/mouseevent.h +ext/opencv/opencv.cpp +ext/opencv/opencv.h +ext/opencv/point3dset.cpp +ext/opencv/point3dset.h +ext/opencv/pointset.cpp +ext/opencv/pointset.h +ext/opencv/trackbar.cpp +ext/opencv/trackbar.h +ext/opencv/window.cpp +ext/opencv/window.h images/CvMat_sobel.png images/CvMat_sub_rect.png images/CvSeq_relationmap.png @@ -113,3 +113,52 @@ lib/version.rb setup/setup.cygwin.rb setup/setup.mingw.rb setup/setup.mswin32.rb +test/helper.rb +test/runner.rb +test/samples/airplane.jpg +test/samples/baboon.jpg +test/samples/baboon200.jpg +test/samples/baboon200_rotated.jpg +test/samples/cat.jpg +test/samples/contours.jpg +test/samples/fruits.jpg +test/samples/inpaint-mask.bmp +test/samples/lena-256x256.jpg +test/samples/lena-32x32.jpg +test/samples/lena-eyes.jpg +test/samples/lena-inpaint.jpg +test/samples/lena.jpg +test/samples/lines.jpg +test/samples/one_way_train_0000.jpg +test/samples/one_way_train_0001.jpg +test/samples/str-cv-rotated.jpg +test/samples/str-cv.jpg +test/samples/str-ov.jpg +test/samples/stuff.jpg +test/test_cvbox2d.rb +test/test_cvchain.rb +test/test_cvcircle32f.rb +test/test_cvconnectedcomp.rb +test/test_cvcontour.rb +test/test_cvfont.rb +test/test_cvhumoments.rb +test/test_cvline.rb +test/test_cvmat.rb +test/test_cvmat_drawing.rb +test/test_cvmat_dxt.rb +test/test_cvmat_imageprocessing.rb +test/test_cvmoments.rb +test/test_cvpoint.rb +test/test_cvpoint2d32f.rb +test/test_cvpoint3d32f.rb +test/test_cvrect.rb +test/test_cvscalar.rb +test/test_cvseq.rb +test/test_cvsize.rb +test/test_cvsize2d32f.rb +test/test_cvtermcriteria.rb +test/test_cvtwopoints.rb +test/test_iplconvkernel.rb +test/test_iplimage.rb +test/test_opencv.rb +test/test_preliminary.rb diff --git a/README.rdoc b/README.rdoc index 83d8baf8..5d1010de 100644 --- a/README.rdoc +++ b/README.rdoc @@ -36,9 +36,12 @@ You can install by cloning this repository: Then inside the ruby-opencv folder run: - ruby ext/extconf.rb - make - sudo make install + rake install_gem + +You can also add ruby-opencv in your Gemfile: + + echo -e "\n"'gem "opencv", :git => "https://github.com/pcting/ruby-opencv"' >> Gemfile + bundle install # or bundle update == SYNOPSIS: diff --git a/Rakefile b/Rakefile index f90e03a1..137ad7f5 100644 --- a/Rakefile +++ b/Rakefile @@ -2,33 +2,49 @@ require 'rubygems' require 'hoe' + +require 'rake/extensiontask' require './lib/version' -Hoe.new('opencv', OpenCV::VERSION) do |p| - p.author = ['Masakazu Yonekura'] +Hoe.plugin :gemspec + +hoespec = Hoe.spec 'opencv' do |p| + p.version = OpenCV::VERSION p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n") p.description = < %w{ext/extconf.rb} + :extensions => %w{ext/opencv/extconf.rb} } p.summary = 'OpenCV wrapper for Ruby.' - # p.test_globs = 'spec/**/*_spec.rb' - p.clean_globs |= ['*.o'] - + p.test_globs = ['test/test_*.rb'] + p.clean_globs << 'lib/*.so' << 'tmp' + p.url = 'http://blueruby.mydns.jp/opencv' - - p.extra_deps << ['hoe'] + + p.extra_dev_deps << ['rake-compiler', '>= 0'] << ['hoe-gemspec'] << ['rspec'] + + Rake::ExtensionTask.new('opencv', spec) do |ext| + ext.lib_dir = File.join('lib', 'opencv') + end + end +hoespec.spec.files.delete('.gemtest') +hoespec.spec.files.delete('ruby-opencv.gemspec') +hoespec.spec.files.delete('opencv.gemspec') +hoespec.spec.cert_chain = [] +hoespec.spec.signing_key = nil + +Rake::Task[:test].prerequisites << :compile + # vim: syntax=Ruby diff --git a/ext/iplimage.cpp b/ext/iplimage.cpp deleted file mode 100644 index a4a5c2e4..00000000 --- a/ext/iplimage.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/************************************************************ - - iplimage.cpp - - - $Author: lsxi $ - - Copyright (C) 2005-2006 Masakazu Yonekura - -************************************************************/ -#include "iplimage.h" -/* - * Document-class: OpenCV::IplImage - * - * IPL(Intel Image Processing Library) Image class. - * - * IplImage is subclass of CvMat. IplImage support ROI(region of interest) and COI(color of interest). - * Most of CvMat method support ROI, and some of CvMat method support COI. - * - * =What is ROI? - * region of interest. - * - * =What is COI? - * color of interest. - */ -__NAMESPACE_BEGIN_OPENCV -__NAMESPACE_BEGIN_IPLIMAGE - -VALUE rb_klass; - -VALUE -rb_class() -{ - return rb_klass; -} - -void -define_ruby_class() -{ - if (rb_klass) - return; - /* - * opencv = rb_define_module("OpenCV"); - * cvmat = rb_define_class_under(opencv, "CvMat", rb_cObject); - * - * note: this comment is used by rdoc. - */ - VALUE opencv = rb_module_opencv(); - VALUE cvmat = cCvMat::rb_class(); - rb_klass = rb_define_class_under(opencv, "IplImage", cvmat); - rb_define_alloc_func(rb_klass, rb_allocate); - rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load_image), -1); - rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1); - rb_define_method(rb_klass, "get_roi", RUBY_METHOD_FUNC(rb_get_roi), 0); - rb_define_alias(rb_klass, "roi", "get_roi"); - rb_define_method(rb_klass, "set_roi", RUBY_METHOD_FUNC(rb_set_roi), 1); - rb_define_alias(rb_klass, "roi=", "set_roi"); - rb_define_method(rb_klass, "reset_roi", RUBY_METHOD_FUNC(rb_reset_roi), 0); - rb_define_method(rb_klass, "get_coi", RUBY_METHOD_FUNC(rb_get_coi), 0); - rb_define_alias(rb_klass, "coi", "get_coi"); - rb_define_method(rb_klass, "set_coi", RUBY_METHOD_FUNC(rb_set_coi), 1); - rb_define_alias(rb_klass, "coi=", "set_coi"); - rb_define_method(rb_klass, "reset_coi", RUBY_METHOD_FUNC(rb_reset_coi), 0); -} - -VALUE -rb_allocate(VALUE klass) -{ - return OPENCV_OBJECT(rb_klass, 0); -} - -/* - * call-seq: - * new(width, height[, depth = CV_8U][, channel = 3]) - * - * Create width * height image. Each element-value set 0. - * - * Each element possigle range is set by depth. Default is unsigned 8bit. - * - * Number of channel is set by channel. channel should be 1..4. - * - * note: width = col, height = row, on CvMat. It is noted not to make a mistake - * because the order of argument is differenct to CvMat. - */ -VALUE -rb_initialize(int argc, VALUE *argv, VALUE self) -{ - VALUE width, height, depth, channel; - rb_scan_args(argc, argv, "22", &width, &height, &depth, &channel); - int _depth = argc < 3 ? CV_8U : FIX2INT(depth); - int _channel = argc < 4 ? 3 : FIX2INT(channel); - DATA_PTR(self) = cvCreateImage(cvSize(FIX2INT(width), FIX2INT(height)), cvIplDepth(_depth), _channel); - return self; -} - -/* - * call-seq: - * IplImage::load(filename[,iscolor = CV_LOAD_IMAGE_COLOR]) - * - * Load an image from file. - * iscolor = CV_LOAD_IMAGE_COLOR, the loaded image is forced to be a 3-channel color image - * iscolor = CV_LOAD_IMAGE_GRAYSCALE, the loaded image is forced to be grayscale - * iscolor = CV_LOAD_IMAGE_UNCHANGED, the loaded image will be loaded as is. - * Currently the following file format are supported. - * * Windows bitmaps - BMP,DIB - * * JPEG files - JPEG,JPG,JPE - * * Portable Network Graphics - PNG - * * Portable image format - PBM,PGM,PPM - * * Sun rasters - SR,RAS - * * TIFF files - TIFF,TIF - */ -VALUE -rb_load_image(int argc, VALUE *argv, VALUE self) -{ - VALUE filename, iscolor; - rb_scan_args(argc, argv, "11", &filename, &iscolor); - Check_Type(filename, T_STRING); - - int _iscolor; - if (TYPE(iscolor) == T_NIL) { - _iscolor = CV_LOAD_IMAGE_COLOR; - } - else { - Check_Type(iscolor, T_FIXNUM); - _iscolor = FIX2INT(iscolor); - } - - IplImage *image; - if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) { - rb_raise(rb_eStandardError, "file does not exist or invalid format image."); - } - return OPENCV_OBJECT(rb_klass, image); -} - -/* - * Get ROI as CvRect. - */ -VALUE -rb_get_roi(VALUE self) -{ - return cCvRect::new_object(cvGetImageROI(IPLIMAGE(self))); -} - -/* - * call-seq: - * set_roi(rect) - * set_roi(rect){|image| ...} - * - * Set ROI. rect should be CvRect or compatible object. - * Return self. - */ -VALUE -rb_set_roi(VALUE self, VALUE roi) -{ - VALUE block = rb_block_given_p() ? rb_block_proc() : 0; - if (block) { - CvRect prev_roi = cvGetImageROI(IPLIMAGE(self)); - cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi)); - rb_yield_values(1, self); - cvSetImageROI(IPLIMAGE(self), prev_roi); - } else { - cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi)); - } - return self; -} - - -/* - * Reset ROI setting. Same as IplImage#roi = nil. Return self. - */ -VALUE -rb_reset_roi(VALUE self) -{ - cvResetImageROI(IPLIMAGE(self)); - return self; -} - -/* - * Return COI as Fixnum. - */ -VALUE -rb_get_coi(VALUE self) -{ - return INT2FIX(cvGetImageCOI(IPLIMAGE(self))); -} - -/* - * call-seq: - * set_coi(coi) - * set_coi(coi){|image| ...} - * - * Set COI. coi should be Fixnum. - * Return self. - */ -VALUE -rb_set_coi(VALUE self, VALUE coi) -{ - VALUE block = rb_block_given_p() ? rb_block_proc() : 0; - if (block) { - int prev_coi = cvGetImageCOI(IPLIMAGE(self)); - cvSetImageCOI(IPLIMAGE(self), FIX2INT(coi)); - rb_yield_values(1, self); - cvSetImageCOI(IPLIMAGE(self), prev_coi); - } else { - cvSetImageCOI(IPLIMAGE(self), FIX2INT(coi)); - } - return self; -} - -/* - * Reset COI setting. Same as IplImage#coi = 0. Return self. - */ -VALUE -rb_reset_coi(VALUE self) -{ - cvSetImageCOI(IPLIMAGE(self), 0); - return self; -} - - -VALUE -new_object(int width, int height, int type) -{ - return OPENCV_OBJECT(rb_klass, cvCreateImage(cvSize(width, height), cvIplDepth(type), CV_MAT_CN(type))); -} - -VALUE -new_object(CvSize size, int type) -{ - return OPENCV_OBJECT(rb_klass, cvCreateImage(size, cvIplDepth(type), CV_MAT_CN(type))); -} - -__NAMESPACE_END_IPLIMAGE -__NAMESPACE_END_OPENCV diff --git a/ext/curve.cpp b/ext/opencv/curve.cpp similarity index 100% rename from ext/curve.cpp rename to ext/opencv/curve.cpp diff --git a/ext/curve.h b/ext/opencv/curve.h similarity index 100% rename from ext/curve.h rename to ext/opencv/curve.h diff --git a/ext/cvavgcomp.cpp b/ext/opencv/cvavgcomp.cpp similarity index 100% rename from ext/cvavgcomp.cpp rename to ext/opencv/cvavgcomp.cpp diff --git a/ext/cvavgcomp.h b/ext/opencv/cvavgcomp.h similarity index 100% rename from ext/cvavgcomp.h rename to ext/opencv/cvavgcomp.h diff --git a/ext/cvbox2d.cpp b/ext/opencv/cvbox2d.cpp similarity index 100% rename from ext/cvbox2d.cpp rename to ext/opencv/cvbox2d.cpp diff --git a/ext/cvbox2d.h b/ext/opencv/cvbox2d.h similarity index 100% rename from ext/cvbox2d.h rename to ext/opencv/cvbox2d.h diff --git a/ext/cvcapture.cpp b/ext/opencv/cvcapture.cpp similarity index 100% rename from ext/cvcapture.cpp rename to ext/opencv/cvcapture.cpp diff --git a/ext/cvcapture.h b/ext/opencv/cvcapture.h similarity index 100% rename from ext/cvcapture.h rename to ext/opencv/cvcapture.h diff --git a/ext/cvchain.cpp b/ext/opencv/cvchain.cpp similarity index 100% rename from ext/cvchain.cpp rename to ext/opencv/cvchain.cpp diff --git a/ext/cvchain.h b/ext/opencv/cvchain.h similarity index 100% rename from ext/cvchain.h rename to ext/opencv/cvchain.h diff --git a/ext/cvchaincode.cpp b/ext/opencv/cvchaincode.cpp similarity index 100% rename from ext/cvchaincode.cpp rename to ext/opencv/cvchaincode.cpp diff --git a/ext/cvchaincode.h b/ext/opencv/cvchaincode.h similarity index 100% rename from ext/cvchaincode.h rename to ext/opencv/cvchaincode.h diff --git a/ext/cvcircle32f.cpp b/ext/opencv/cvcircle32f.cpp similarity index 100% rename from ext/cvcircle32f.cpp rename to ext/opencv/cvcircle32f.cpp diff --git a/ext/cvcircle32f.h b/ext/opencv/cvcircle32f.h similarity index 100% rename from ext/cvcircle32f.h rename to ext/opencv/cvcircle32f.h diff --git a/ext/cvcondensation.cpp b/ext/opencv/cvcondensation.cpp similarity index 100% rename from ext/cvcondensation.cpp rename to ext/opencv/cvcondensation.cpp diff --git a/ext/cvcondensation.h b/ext/opencv/cvcondensation.h similarity index 100% rename from ext/cvcondensation.h rename to ext/opencv/cvcondensation.h diff --git a/ext/cvconnectedcomp.cpp b/ext/opencv/cvconnectedcomp.cpp similarity index 100% rename from ext/cvconnectedcomp.cpp rename to ext/opencv/cvconnectedcomp.cpp diff --git a/ext/cvconnectedcomp.h b/ext/opencv/cvconnectedcomp.h similarity index 100% rename from ext/cvconnectedcomp.h rename to ext/opencv/cvconnectedcomp.h diff --git a/ext/cvcontour.cpp b/ext/opencv/cvcontour.cpp similarity index 100% rename from ext/cvcontour.cpp rename to ext/opencv/cvcontour.cpp diff --git a/ext/cvcontour.h b/ext/opencv/cvcontour.h similarity index 100% rename from ext/cvcontour.h rename to ext/opencv/cvcontour.h diff --git a/ext/cvcontourtree.cpp b/ext/opencv/cvcontourtree.cpp similarity index 100% rename from ext/cvcontourtree.cpp rename to ext/opencv/cvcontourtree.cpp diff --git a/ext/cvcontourtree.h b/ext/opencv/cvcontourtree.h similarity index 100% rename from ext/cvcontourtree.h rename to ext/opencv/cvcontourtree.h diff --git a/ext/cvconvexitydefect.cpp b/ext/opencv/cvconvexitydefect.cpp similarity index 100% rename from ext/cvconvexitydefect.cpp rename to ext/opencv/cvconvexitydefect.cpp diff --git a/ext/cvconvexitydefect.h b/ext/opencv/cvconvexitydefect.h similarity index 100% rename from ext/cvconvexitydefect.h rename to ext/opencv/cvconvexitydefect.h diff --git a/ext/cverror.cpp b/ext/opencv/cverror.cpp similarity index 100% rename from ext/cverror.cpp rename to ext/opencv/cverror.cpp diff --git a/ext/cverror.h b/ext/opencv/cverror.h similarity index 100% rename from ext/cverror.h rename to ext/opencv/cverror.h diff --git a/ext/cvfont.cpp b/ext/opencv/cvfont.cpp similarity index 100% rename from ext/cvfont.cpp rename to ext/opencv/cvfont.cpp diff --git a/ext/cvfont.h b/ext/opencv/cvfont.h similarity index 100% rename from ext/cvfont.h rename to ext/opencv/cvfont.h diff --git a/ext/cvhaarclassifiercascade.cpp b/ext/opencv/cvhaarclassifiercascade.cpp similarity index 100% rename from ext/cvhaarclassifiercascade.cpp rename to ext/opencv/cvhaarclassifiercascade.cpp diff --git a/ext/cvhaarclassifiercascade.h b/ext/opencv/cvhaarclassifiercascade.h similarity index 100% rename from ext/cvhaarclassifiercascade.h rename to ext/opencv/cvhaarclassifiercascade.h diff --git a/ext/cvhistogram.cpp b/ext/opencv/cvhistogram.cpp similarity index 100% rename from ext/cvhistogram.cpp rename to ext/opencv/cvhistogram.cpp diff --git a/ext/cvhistogram.h b/ext/opencv/cvhistogram.h similarity index 100% rename from ext/cvhistogram.h rename to ext/opencv/cvhistogram.h diff --git a/ext/cvhumoments.cpp b/ext/opencv/cvhumoments.cpp similarity index 100% rename from ext/cvhumoments.cpp rename to ext/opencv/cvhumoments.cpp diff --git a/ext/cvhumoments.h b/ext/opencv/cvhumoments.h similarity index 100% rename from ext/cvhumoments.h rename to ext/opencv/cvhumoments.h diff --git a/ext/cvindex.cpp b/ext/opencv/cvindex.cpp similarity index 100% rename from ext/cvindex.cpp rename to ext/opencv/cvindex.cpp diff --git a/ext/cvindex.h b/ext/opencv/cvindex.h similarity index 100% rename from ext/cvindex.h rename to ext/opencv/cvindex.h diff --git a/ext/cvline.cpp b/ext/opencv/cvline.cpp similarity index 100% rename from ext/cvline.cpp rename to ext/opencv/cvline.cpp diff --git a/ext/cvline.h b/ext/opencv/cvline.h similarity index 100% rename from ext/cvline.h rename to ext/opencv/cvline.h diff --git a/ext/cvmat.cpp b/ext/opencv/cvmat.cpp similarity index 99% rename from ext/cvmat.cpp rename to ext/opencv/cvmat.cpp index cbd947cf..ed34cf6a 100644 --- a/ext/cvmat.cpp +++ b/ext/opencv/cvmat.cpp @@ -403,6 +403,7 @@ void define_ruby_class() rb_define_method(rb_klass, "save_image", RUBY_METHOD_FUNC(rb_save_image), 1); } + VALUE rb_allocate(VALUE klass) { @@ -2458,13 +2459,19 @@ VALUE rb_dft(int argc, VALUE *argv, VALUE self) { int type = CV_DXT_FORWARD; + int num_rows = 0; if (argc > 0) { - for (int i = 0; i < argc; i++) { + int num_flags = argc; + if (TYPE(argv[argc -1]) == T_FIXNUM) { + num_flags = argc - 1; + num_rows = FIX2INT(argv[argc - 1]); + } + for (int i = 0; i < num_flags; i++) { type |= CVMETHOD("DXT_FLAG", argv[i]); } } VALUE dest = new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self))); - cvDFT(CVARR(self), CVARR(dest), type); + cvDFT(CVARR(self), CVARR(dest), type, num_rows); return dest; } @@ -5155,6 +5162,7 @@ rb_compute_correspond_epilines(VALUE klass, VALUE points, VALUE which_image, VAL return correspondent_lines; } + VALUE new_object(int rows, int cols, int type) { @@ -5167,5 +5175,6 @@ new_object(CvSize size, int type) return OPENCV_OBJECT(rb_klass, cvCreateMat(size.height, size.width, type)); } + __NAMESPACE_END_OPENCV __NAMESPACE_END_CVMAT diff --git a/ext/cvmat.h b/ext/opencv/cvmat.h similarity index 99% rename from ext/cvmat.h rename to ext/opencv/cvmat.h index 0793c21f..005c2863 100644 --- a/ext/cvmat.h +++ b/ext/opencv/cvmat.h @@ -12,6 +12,7 @@ #include "opencv.h" + #define __NAMESPACE_BEGIN_CVMAT namespace cCvMat{ #define __NAMESPACE_END_CVMAT } @@ -270,8 +271,10 @@ VALUE rb_save_image(VALUE self, VALUE filename); VALUE new_object(int rows, int cols, int type); VALUE new_object(CvSize size, int type); + __NAMESPACE_END_CVMAT + inline CvMat* CVMAT(VALUE object) { diff --git a/ext/cvmatnd.cpp b/ext/opencv/cvmatnd.cpp similarity index 100% rename from ext/cvmatnd.cpp rename to ext/opencv/cvmatnd.cpp diff --git a/ext/cvmatnd.h b/ext/opencv/cvmatnd.h similarity index 100% rename from ext/cvmatnd.h rename to ext/opencv/cvmatnd.h diff --git a/ext/cvmemstorage.cpp b/ext/opencv/cvmemstorage.cpp similarity index 100% rename from ext/cvmemstorage.cpp rename to ext/opencv/cvmemstorage.cpp diff --git a/ext/cvmemstorage.h b/ext/opencv/cvmemstorage.h similarity index 100% rename from ext/cvmemstorage.h rename to ext/opencv/cvmemstorage.h diff --git a/ext/cvmoments.cpp b/ext/opencv/cvmoments.cpp similarity index 100% rename from ext/cvmoments.cpp rename to ext/opencv/cvmoments.cpp diff --git a/ext/cvmoments.h b/ext/opencv/cvmoments.h similarity index 100% rename from ext/cvmoments.h rename to ext/opencv/cvmoments.h diff --git a/ext/cvpoint.cpp b/ext/opencv/cvpoint.cpp similarity index 100% rename from ext/cvpoint.cpp rename to ext/opencv/cvpoint.cpp diff --git a/ext/cvpoint.h b/ext/opencv/cvpoint.h similarity index 100% rename from ext/cvpoint.h rename to ext/opencv/cvpoint.h diff --git a/ext/cvpoint2d32f.cpp b/ext/opencv/cvpoint2d32f.cpp similarity index 100% rename from ext/cvpoint2d32f.cpp rename to ext/opencv/cvpoint2d32f.cpp diff --git a/ext/cvpoint2d32f.h b/ext/opencv/cvpoint2d32f.h similarity index 100% rename from ext/cvpoint2d32f.h rename to ext/opencv/cvpoint2d32f.h diff --git a/ext/cvpoint3d32f.cpp b/ext/opencv/cvpoint3d32f.cpp similarity index 100% rename from ext/cvpoint3d32f.cpp rename to ext/opencv/cvpoint3d32f.cpp diff --git a/ext/cvpoint3d32f.h b/ext/opencv/cvpoint3d32f.h similarity index 100% rename from ext/cvpoint3d32f.h rename to ext/opencv/cvpoint3d32f.h diff --git a/ext/cvrect.cpp b/ext/opencv/cvrect.cpp similarity index 100% rename from ext/cvrect.cpp rename to ext/opencv/cvrect.cpp diff --git a/ext/cvrect.h b/ext/opencv/cvrect.h similarity index 100% rename from ext/cvrect.h rename to ext/opencv/cvrect.h diff --git a/ext/cvscalar.cpp b/ext/opencv/cvscalar.cpp similarity index 100% rename from ext/cvscalar.cpp rename to ext/opencv/cvscalar.cpp diff --git a/ext/cvscalar.h b/ext/opencv/cvscalar.h similarity index 100% rename from ext/cvscalar.h rename to ext/opencv/cvscalar.h diff --git a/ext/cvseq.cpp b/ext/opencv/cvseq.cpp similarity index 100% rename from ext/cvseq.cpp rename to ext/opencv/cvseq.cpp diff --git a/ext/cvseq.h b/ext/opencv/cvseq.h similarity index 100% rename from ext/cvseq.h rename to ext/opencv/cvseq.h diff --git a/ext/cvset.cpp b/ext/opencv/cvset.cpp similarity index 100% rename from ext/cvset.cpp rename to ext/opencv/cvset.cpp diff --git a/ext/cvset.h b/ext/opencv/cvset.h similarity index 100% rename from ext/cvset.h rename to ext/opencv/cvset.h diff --git a/ext/cvsize.cpp b/ext/opencv/cvsize.cpp similarity index 100% rename from ext/cvsize.cpp rename to ext/opencv/cvsize.cpp diff --git a/ext/cvsize.h b/ext/opencv/cvsize.h similarity index 100% rename from ext/cvsize.h rename to ext/opencv/cvsize.h diff --git a/ext/cvsize2d32f.cpp b/ext/opencv/cvsize2d32f.cpp similarity index 100% rename from ext/cvsize2d32f.cpp rename to ext/opencv/cvsize2d32f.cpp diff --git a/ext/cvsize2d32f.h b/ext/opencv/cvsize2d32f.h similarity index 100% rename from ext/cvsize2d32f.h rename to ext/opencv/cvsize2d32f.h diff --git a/ext/cvslice.cpp b/ext/opencv/cvslice.cpp similarity index 100% rename from ext/cvslice.cpp rename to ext/opencv/cvslice.cpp diff --git a/ext/cvslice.h b/ext/opencv/cvslice.h similarity index 100% rename from ext/cvslice.h rename to ext/opencv/cvslice.h diff --git a/ext/cvsparsemat.cpp b/ext/opencv/cvsparsemat.cpp similarity index 100% rename from ext/cvsparsemat.cpp rename to ext/opencv/cvsparsemat.cpp diff --git a/ext/cvsparsemat.h b/ext/opencv/cvsparsemat.h similarity index 100% rename from ext/cvsparsemat.h rename to ext/opencv/cvsparsemat.h diff --git a/ext/cvtermcriteria.cpp b/ext/opencv/cvtermcriteria.cpp similarity index 100% rename from ext/cvtermcriteria.cpp rename to ext/opencv/cvtermcriteria.cpp diff --git a/ext/cvtermcriteria.h b/ext/opencv/cvtermcriteria.h similarity index 100% rename from ext/cvtermcriteria.h rename to ext/opencv/cvtermcriteria.h diff --git a/ext/cvtwopoints.cpp b/ext/opencv/cvtwopoints.cpp similarity index 100% rename from ext/cvtwopoints.cpp rename to ext/opencv/cvtwopoints.cpp diff --git a/ext/cvtwopoints.h b/ext/opencv/cvtwopoints.h similarity index 100% rename from ext/cvtwopoints.h rename to ext/opencv/cvtwopoints.h diff --git a/ext/cvvideowriter.cpp b/ext/opencv/cvvideowriter.cpp similarity index 100% rename from ext/cvvideowriter.cpp rename to ext/opencv/cvvideowriter.cpp diff --git a/ext/cvvideowriter.h b/ext/opencv/cvvideowriter.h similarity index 100% rename from ext/cvvideowriter.h rename to ext/opencv/cvvideowriter.h diff --git a/ext/extconf.rb b/ext/opencv/extconf.rb similarity index 98% rename from ext/extconf.rb rename to ext/opencv/extconf.rb index 5881ee6c..3e522950 100755 --- a/ext/extconf.rb +++ b/ext/opencv/extconf.rb @@ -72,4 +72,4 @@ end # step-final. create Makefile -create_makefile("opencv") +create_makefile("opencv/opencv") diff --git a/ext/gui.cpp b/ext/opencv/gui.cpp similarity index 100% rename from ext/gui.cpp rename to ext/opencv/gui.cpp diff --git a/ext/gui.h b/ext/opencv/gui.h similarity index 100% rename from ext/gui.h rename to ext/opencv/gui.h diff --git a/ext/iplconvkernel.cpp b/ext/opencv/iplconvkernel.cpp similarity index 100% rename from ext/iplconvkernel.cpp rename to ext/opencv/iplconvkernel.cpp diff --git a/ext/iplconvkernel.h b/ext/opencv/iplconvkernel.h similarity index 100% rename from ext/iplconvkernel.h rename to ext/opencv/iplconvkernel.h diff --git a/ext/opencv/iplimage.cpp b/ext/opencv/iplimage.cpp new file mode 100644 index 00000000..b64c35e2 --- /dev/null +++ b/ext/opencv/iplimage.cpp @@ -0,0 +1,536 @@ +/************************************************************ + + iplimage.cpp - + + $Author: lsxi $ + + Copyright (C) 2005-2006 Masakazu Yonekura + +************************************************************/ +#include "iplimage.h" +/* + * Document-class: OpenCV::IplImage + * + * IPL(Intel Image Processing Library) Image class. + * + * IplImage is subclass of CvMat. IplImage support ROI(region of interest) and COI(color of interest). + * Most of CvMat method support ROI, and some of CvMat method support COI. + * + * =What is ROI? + * region of interest. + * + * =What is COI? + * color of interest. + */ +__NAMESPACE_BEGIN_OPENCV +__NAMESPACE_BEGIN_IPLIMAGE + +VALUE rb_klass; + +VALUE +rb_class() +{ + return rb_klass; +} + +void +define_ruby_class() +{ + if (rb_klass) + return; + /* + * opencv = rb_define_module("OpenCV"); + * cvmat = rb_define_class_under(opencv, "CvMat", rb_cObject); + * + * note: this comment is used by rdoc. + */ + VALUE opencv = rb_module_opencv(); + VALUE cvmat = cCvMat::rb_class(); + rb_klass = rb_define_class_under(opencv, "IplImage", cvmat); + rb_define_alloc_func(rb_klass, rb_allocate); + rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load_image), -1); + rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1); + rb_define_method(rb_klass, "get_roi", RUBY_METHOD_FUNC(rb_get_roi), 0); + rb_define_alias(rb_klass, "roi", "get_roi"); + rb_define_method(rb_klass, "set_roi", RUBY_METHOD_FUNC(rb_set_roi), 1); + rb_define_alias(rb_klass, "roi=", "set_roi"); + rb_define_method(rb_klass, "reset_roi", RUBY_METHOD_FUNC(rb_reset_roi), 0); + rb_define_method(rb_klass, "get_coi", RUBY_METHOD_FUNC(rb_get_coi), 0); + rb_define_alias(rb_klass, "coi", "get_coi"); + rb_define_method(rb_klass, "set_coi", RUBY_METHOD_FUNC(rb_set_coi), 1); + rb_define_alias(rb_klass, "coi=", "set_coi"); + rb_define_method(rb_klass, "reset_coi", RUBY_METHOD_FUNC(rb_reset_coi), 0); + + rb_define_method(rb_klass, "smoothness", RUBY_METHOD_FUNC(rb_smoothness), -1); +} + +VALUE +rb_allocate(VALUE klass) +{ + return OPENCV_OBJECT(rb_klass, 0); +} + +/* + * call-seq: + * new(width, height[, depth = CV_8U][, channel = 3]) + * + * Create width * height image. Each element-value set 0. + * + * Each element possigle range is set by depth. Default is unsigned 8bit. + * + * Number of channel is set by channel. channel should be 1..4. + * + * note: width = col, height = row, on CvMat. It is noted not to make a mistake + * because the order of argument is differenct to CvMat. + */ +VALUE +rb_initialize(int argc, VALUE *argv, VALUE self) +{ + VALUE width, height, depth, channel; + rb_scan_args(argc, argv, "22", &width, &height, &depth, &channel); + int _depth = argc < 3 ? CV_8U : FIX2INT(depth); + int _channel = argc < 4 ? 3 : FIX2INT(channel); + DATA_PTR(self) = cvCreateImage(cvSize(FIX2INT(width), FIX2INT(height)), cvIplDepth(_depth), _channel); + return self; +} + +/* + * call-seq: + * IplImage::load(filename[,iscolor = CV_LOAD_IMAGE_COLOR]) + * + * Load an image from file. + * iscolor = CV_LOAD_IMAGE_COLOR, the loaded image is forced to be a 3-channel color image + * iscolor = CV_LOAD_IMAGE_GRAYSCALE, the loaded image is forced to be grayscale + * iscolor = CV_LOAD_IMAGE_UNCHANGED, the loaded image will be loaded as is. + * Currently the following file format are supported. + * * Windows bitmaps - BMP,DIB + * * JPEG files - JPEG,JPG,JPE + * * Portable Network Graphics - PNG + * * Portable image format - PBM,PGM,PPM + * * Sun rasters - SR,RAS + * * TIFF files - TIFF,TIF + */ +VALUE +rb_load_image(int argc, VALUE *argv, VALUE self) +{ + VALUE filename, iscolor; + rb_scan_args(argc, argv, "11", &filename, &iscolor); + Check_Type(filename, T_STRING); + + int _iscolor; + if (TYPE(iscolor) == T_NIL) { + _iscolor = CV_LOAD_IMAGE_COLOR; + } + else { + Check_Type(iscolor, T_FIXNUM); + _iscolor = FIX2INT(iscolor); + } + + IplImage *image; + if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) { + rb_raise(rb_eStandardError, "file does not exist or invalid format image."); + } + return OPENCV_OBJECT(rb_klass, image); +} + +/* + * Get ROI as CvRect. + */ +VALUE +rb_get_roi(VALUE self) +{ + return cCvRect::new_object(cvGetImageROI(IPLIMAGE(self))); +} + +/* + * call-seq: + * set_roi(rect) + * set_roi(rect){|image| ...} + * + * Set ROI. rect should be CvRect or compatible object. + * Return self. + */ +VALUE +rb_set_roi(VALUE self, VALUE roi) +{ + VALUE block = rb_block_given_p() ? rb_block_proc() : 0; + if (block) { + CvRect prev_roi = cvGetImageROI(IPLIMAGE(self)); + cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi)); + rb_yield_values(1, self); + cvSetImageROI(IPLIMAGE(self), prev_roi); + } else { + cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi)); + } + return self; +} + + +/* + * Reset ROI setting. Same as IplImage#roi = nil. Return self. + */ +VALUE +rb_reset_roi(VALUE self) +{ + cvResetImageROI(IPLIMAGE(self)); + return self; +} + +/* + * Return COI as Fixnum. + */ +VALUE +rb_get_coi(VALUE self) +{ + return INT2FIX(cvGetImageCOI(IPLIMAGE(self))); +} + +/* + * call-seq: + * set_coi(coi) + * set_coi(coi){|image| ...} + * + * Set COI. coi should be Fixnum. + * Return self. + */ +VALUE +rb_set_coi(VALUE self, VALUE coi) +{ + VALUE block = rb_block_given_p() ? rb_block_proc() : 0; + if (block) { + int prev_coi = cvGetImageCOI(IPLIMAGE(self)); + cvSetImageCOI(IPLIMAGE(self), FIX2INT(coi)); + rb_yield_values(1, self); + cvSetImageCOI(IPLIMAGE(self), prev_coi); + } else { + cvSetImageCOI(IPLIMAGE(self), FIX2INT(coi)); + } + return self; +} + +/* + * Reset COI setting. Same as IplImage#coi = 0. Return self. + */ +VALUE +rb_reset_coi(VALUE self) +{ + cvSetImageCOI(IPLIMAGE(self), 0); + return self; +} + +/* + * call-seq: + * IplImage.smoothness(lowFreqRatio, blankDensity, messyDensity, highFreqRatio) -> [ symbol, float, float ] + * + * Determines if the image's smoothness is either, :smooth, :messy, or :blank. + */ +VALUE +rb_smoothness(int argc, VALUE *argv, VALUE self) +{ + VALUE lowFreqRatio, blankDensity, messyDensity, highFreqRatio; + rb_scan_args(argc, argv, "04", &lowFreqRatio, &blankDensity, &messyDensity, &highFreqRatio); + + double f_lowFreqRatio, f_blankDensity, f_messyDensity, f_highFreqRatio; + double outLowDensity, outHighDensity; + if (TYPE(lowFreqRatio) == T_NIL) { + f_lowFreqRatio = 10 / 128.0f; + } else { + Check_Type(lowFreqRatio, T_FLOAT); + f_lowFreqRatio = NUM2DBL(lowFreqRatio); + } + if (TYPE(blankDensity) == T_NIL) { + f_blankDensity = 1.2f; + } else { + Check_Type(blankDensity, T_FLOAT); + f_blankDensity = NUM2DBL(blankDensity); + } + if (TYPE(messyDensity) == T_NIL) { + f_messyDensity = 0.151f; + } else { + Check_Type(messyDensity, T_FLOAT); + f_messyDensity = NUM2DBL(messyDensity); + } + if (TYPE(highFreqRatio) == T_NIL) { + f_highFreqRatio = 5 / 128.0f; + } else { + Check_Type(highFreqRatio, T_FLOAT); + f_highFreqRatio = NUM2DBL(highFreqRatio); + } + + IplImage *pFourierImage; + IplImage *p64DepthImage; + + // 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 = 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); + + cvReleaseImage(&pFourierImage); + if (p64DepthImage != NULL) + 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)); + } +} + +/** + * Note: if lowDensity < blankDensityThreshold -> blank; + * else if highDensity > messyDensityThreshold -> messy; + * else -> good; + */ +Smoothness +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; + int totalIntensity; + 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__ ); + } + + high_pass_range(pFourierImage, lowFreqRatio, low, high ); + totalArea = M_PI * (high * high - low * low); + + filteredFourierImage = create_frequency_filtered_image(pFourierImage, low, high); + scalar = cvSum(filteredFourierImage); + totalIntensity = scalar.val[0]; + cvReleaseImage(&filteredFourierImage); + outLowDensity = den = totalIntensity / totalArea; + + if(den <= blankDensity) + { + return BLANK; + } + + low = (int) (high * (1.0 - highFreqRatio)); + + filteredFourierImage = create_frequency_filtered_image(pFourierImage, low, high); + scalar = cvSum(filteredFourierImage); + totalIntensity = scalar.val[0]; + cvReleaseImage(&filteredFourierImage); + outHighDensity = den = totalIntensity / totalArea; + + if(den >= messyDensity) + { + return MESSY; + } + + return SMOOTH; +} + +// Rearrange the quadrants of Fourier image so that the origin is at +// the image center +// src & dst arrays of equal size & type +void +cvShiftDFT(CvArr *src_arr, CvArr *dst_arr ) +{ + CvMat *tmp = NULL; + CvMat q1stub, q2stub; + CvMat q3stub, q4stub; + CvMat d1stub, d2stub; + CvMat d3stub, d4stub; + CvMat *q1, *q2, *q3, *q4; + CvMat *d1, *d2, *d3, *d4; + + CvSize size = cvGetSize(src_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(src_arr==dst_arr){ + tmp = cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr)); + } + + 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) ); + + 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{ + cvCopy(q3, tmp, 0); + cvCopy(q1, q3, 0); + cvCopy(tmp, q1, 0); + cvCopy(q4, tmp, 0); + cvCopy(q2, q4, 0); + cvCopy(tmp, q2, 0); + } + + if (tmp != NULL) + { + cvReleaseMat(&tmp); + } +} + +IplImage* +create_fourier_image(const IplImage *im) +{ + + IplImage *realInput; + IplImage *imaginaryInput; + IplImage *complexInput; + int dft_M, dft_N; + CvMat *dft_A, tmp; + IplImage *image_Re; + IplImage *image_Im; + + realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1); + imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1); + complexInput = 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_A = cvCreateMat( dft_M, dft_N, CV_64FC2 ); + image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1); + image_Im = 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 ); + } + + // 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 ); + + // Split Fourier in real and imaginary parts + 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 ); + + // Compute 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 ); + + cvReleaseImage(&realInput); + cvReleaseImage(&imaginaryInput); + cvReleaseImage(&complexInput); + cvReleaseImage(&image_Im); + + cvReleaseMat(&dft_A); + + return image_Re; + +} + +IplImage* +create_frequency_filtered_image(const IplImage *pImage, int low, int high) +{ + + CvPoint2D32f center; + center.x = pImage->width / 2; + center.y = pImage->height / 2; + CvBox2D box; + box.center = center; + + box.size.width = high; + box.size.height = high; + + IplImage *pFilterMask = cvCreateImage( cvGetSize(pImage), IPL_DEPTH_64F, 1 ); + IplImage *pFiltered = cvCreateImage( cvGetSize(pImage), IPL_DEPTH_64F, 1 ); + + cvZero(pFilterMask); + cvZero(pFiltered); + + 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) + cvEllipseBox(pFilterMask, box, cvScalar(0, 0, 0, 0), CV_FILLED, 8, 0); + + cvAnd(pImage, pFilterMask, pFiltered, NULL); + + cvReleaseImage(&pFilterMask); + + return pFiltered; +} + +void +high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &outHigh) +{ + if(lostPercentage > 1.0f) + { + lostPercentage = 1; + } + else if(lostPercentage < 0.0f ) + { + lostPercentage = 0; + } + + outHigh = (int) min( pImage->width, pImage->height ); + outLow = (int) (lostPercentage * outHigh); +} + + +VALUE +new_object(int width, int height, int type) +{ + return OPENCV_OBJECT(rb_klass, cvCreateImage(cvSize(width, height), cvIplDepth(type), CV_MAT_CN(type))); +} + +VALUE +new_object(CvSize size, int type) +{ + return OPENCV_OBJECT(rb_klass, cvCreateImage(size, cvIplDepth(type), CV_MAT_CN(type))); +} + +__NAMESPACE_END_IPLIMAGE +__NAMESPACE_END_OPENCV diff --git a/ext/iplimage.h b/ext/opencv/iplimage.h similarity index 65% rename from ext/iplimage.h rename to ext/opencv/iplimage.h index 9e7dc081..9997f169 100644 --- a/ext/iplimage.h +++ b/ext/opencv/iplimage.h @@ -37,6 +37,14 @@ VALUE rb_get_coi(VALUE self); VALUE rb_set_coi(VALUE self, VALUE coi); VALUE rb_reset_coi(VALUE self); +VALUE rb_smoothness(int argc, VALUE *argv, VALUE self); +typedef enum { SMOOTH = 1, BLANK = 2, MESSY = 3 } Smoothness; +Smoothness compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, const double blankDensity, const double messyDensity, const double highFreqRatio, double &outLowDensity, double &outHighDensity); +void cvShiftDFT(CvArr *src_arr, CvArr *dst_arr ); +IplImage* create_fourier_image(const IplImage *im); +IplImage* create_frequency_filtered_image(const IplImage *pImage, int low, int high); +void high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &outHigh); + VALUE new_object(int width, int height, int type); VALUE new_object(CvSize size, int type); __NAMESPACE_END_IPLIMAGE diff --git a/ext/mouseevent.cpp b/ext/opencv/mouseevent.cpp similarity index 100% rename from ext/mouseevent.cpp rename to ext/opencv/mouseevent.cpp diff --git a/ext/mouseevent.h b/ext/opencv/mouseevent.h similarity index 100% rename from ext/mouseevent.h rename to ext/opencv/mouseevent.h diff --git a/ext/opencv.cpp b/ext/opencv/opencv.cpp similarity index 100% rename from ext/opencv.cpp rename to ext/opencv/opencv.cpp diff --git a/ext/opencv.h b/ext/opencv/opencv.h similarity index 100% rename from ext/opencv.h rename to ext/opencv/opencv.h diff --git a/ext/point3dset.cpp b/ext/opencv/point3dset.cpp similarity index 100% rename from ext/point3dset.cpp rename to ext/opencv/point3dset.cpp diff --git a/ext/point3dset.h b/ext/opencv/point3dset.h similarity index 100% rename from ext/point3dset.h rename to ext/opencv/point3dset.h diff --git a/ext/pointset.cpp b/ext/opencv/pointset.cpp similarity index 100% rename from ext/pointset.cpp rename to ext/opencv/pointset.cpp diff --git a/ext/pointset.h b/ext/opencv/pointset.h similarity index 100% rename from ext/pointset.h rename to ext/opencv/pointset.h diff --git a/ext/trackbar.cpp b/ext/opencv/trackbar.cpp similarity index 100% rename from ext/trackbar.cpp rename to ext/opencv/trackbar.cpp diff --git a/ext/trackbar.h b/ext/opencv/trackbar.h similarity index 100% rename from ext/trackbar.h rename to ext/opencv/trackbar.h diff --git a/ext/window.cpp b/ext/opencv/window.cpp similarity index 100% rename from ext/window.cpp rename to ext/opencv/window.cpp diff --git a/ext/window.h b/ext/opencv/window.h similarity index 100% rename from ext/window.h rename to ext/opencv/window.h diff --git a/lib/opencv.rb b/lib/opencv.rb index 61058dec..6d39316a 100755 --- a/lib/opencv.rb +++ b/lib/opencv.rb @@ -1,3 +1,3 @@ require (File.dirname(__FILE__) + '/version') -require 'opencv.so' +require 'opencv/opencv.so' diff --git a/lib/version.rb b/lib/version.rb index 54f73d40..dcd6826b 100755 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,3 +1,3 @@ module OpenCV - VERSION = '0.0.6' + VERSION = '0.0.6.pcting' end diff --git a/metadata b/metadata deleted file mode 100644 index c005e75a..00000000 --- a/metadata +++ /dev/null @@ -1,191 +0,0 @@ ---- !ruby/object:Gem::Specification -name: opencv -version: !ruby/object:Gem::Version - version: 0.0.6 -platform: ruby -authors: -- Masakazu Yonekura -- lsxi -autorequire: -bindir: bin -cert_chain: [] - -date: 2008-06-29 00:00:00 +09:00 -default_executable: -dependencies: -- !ruby/object:Gem::Dependency - name: hoe - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -- !ruby/object:Gem::Dependency - name: hoe - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.6.0 - version: -description: OpenCV wrapper for Ruby -email: -- masakazu.yonekura@gmail.com -executables: [] - -extensions: -- ext/extconf.rb -extra_rdoc_files: -- History.txt -- Manifest.txt -- README.txt -- License.txt -files: -- History.txt -- Manifest.txt -- README.txt -- License.txt -- Rakefile -- examples/convexhull.rb -- examples/face_detect.rb -- examples/houghcircle.rb -- examples/inpaint.png -- examples/inpaint.rb -- examples/paint.rb -- examples/snake.rb -- examples/stuff.jpg -- ext/curve.cpp -- ext/curve.h -- ext/cvavgcomp.cpp -- ext/cvavgcomp.h -- ext/cvbox2d.cpp -- ext/cvbox2d.h -- ext/cvcapture.cpp -- ext/cvcapture.h -- ext/cvchain.cpp -- ext/cvchain.h -- ext/cvchaincode.cpp -- ext/cvchaincode.h -- ext/cvcircle32f.cpp -- ext/cvcircle32f.h -- ext/cvcondensation.cpp -- ext/cvcondensation.h -- ext/cvconnectedcomp.cpp -- ext/cvconnectedcomp.h -- ext/cvcontour.cpp -- ext/cvcontour.h -- ext/cvcontourtree.cpp -- ext/cvcontourtree.h -- ext/cvconvexitydefect.cpp -- ext/cvconvexitydefect.h -- ext/cverror.cpp -- ext/cverror.h -- ext/cvfont.cpp -- ext/cvfont.h -- ext/cvhaarclassifiercascade.cpp -- ext/cvhaarclassifiercascade.h -- ext/cvhistogram.cpp -- ext/cvhistogram.h -- ext/cvindex.cpp -- ext/cvindex.h -- ext/cvline.cpp -- ext/cvline.h -- ext/cvmat.cpp -- ext/cvmat.h -- ext/cvmatnd.cpp -- ext/cvmatnd.h -- ext/cvmemstorage.cpp -- ext/cvmemstorage.h -- ext/cvmoments.cpp -- ext/cvmoments.h -- ext/cvpoint.cpp -- ext/cvpoint.h -- ext/cvpoint2d32f.cpp -- ext/cvpoint2d32f.h -- ext/cvpoint3d32f.cpp -- ext/cvpoint3d32f.h -- ext/cvrect.cpp -- ext/cvrect.h -- ext/cvscalar.cpp -- ext/cvscalar.h -- ext/cvseq.cpp -- ext/cvseq.h -- ext/cvset.cpp -- ext/cvset.h -- ext/cvsize.cpp -- ext/cvsize.h -- ext/cvsize2d32f.cpp -- ext/cvsize2d32f.h -- ext/cvslice.cpp -- ext/cvslice.h -- ext/cvsparsemat.cpp -- ext/cvsparsemat.h -- ext/cvtermcriteria.cpp -- ext/cvtermcriteria.h -- ext/cvtwopoints.cpp -- ext/cvtwopoints.h -- ext/cvvector.cpp -- ext/cvvector.h -- ext/cvvideowriter.cpp -- ext/cvvideowriter.h -- ext/extconf.rb -- ext/gui.cpp -- ext/gui.h -- ext/iplconvkernel.cpp -- ext/iplconvkernel.h -- ext/iplimage.cpp -- ext/iplimage.h -- ext/mouseevent.cpp -- ext/mouseevent.h -- ext/opencv.cpp -- ext/opencv.h -- ext/point3dset.cpp -- ext/point3dset.h -- ext/pointset.cpp -- ext/pointset.h -- ext/trackbar.cpp -- ext/trackbar.h -- ext/window.cpp -- ext/window.h -- images/CvMat_sobel.png -- images/CvMat_sub_rect.png -- images/CvSeq_relationmap.png -- images/face_detect_from_lena.jpg -- lib/opencv.rb -- lib/version.rb -- setup/setup.cygwin.rb -- setup/setup.mingw.rb -- setup/setup.mswin32.rb -has_rdoc: true -homepage: http://blueruby.mydns.jp/opencv -post_install_message: -rdoc_options: -- --main -- README.txt -require_paths: -- lib -- ext -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] - -rubyforge_project: opencv -rubygems_version: 1.0.1 -signing_key: -specification_version: 2 -summary: OpenCV wrapper for Ruby. -test_files: -- test/test_opencv.rb diff --git a/opencv.gemspec b/opencv.gemspec new file mode 100644 index 00000000..716dba26 --- /dev/null +++ b/opencv.gemspec @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{opencv} + s.version = "0.0.6.pcting.20110413162541" + + s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= + s.authors = ["lsxi", "pcting"] + s.date = %q{2011-04-13} + s.description = %q{OpenCV wrapper for Ruby +} + s.email = ["masakazu.yonekura@gmail.com", "pcting@gmail.com"] + s.extensions = ["ext/opencv/extconf.rb"] + s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt"] + s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "examples/convexhull.rb", "examples/face_detect.rb", "examples/houghcircle.rb", "examples/inpaint.png", "examples/inpaint.rb", "examples/paint.rb", "examples/snake.rb", "examples/stuff.jpg", "ext/opencv/curve.cpp", "ext/opencv/curve.h", "ext/opencv/cvavgcomp.cpp", "ext/opencv/cvavgcomp.h", "ext/opencv/cvbox2d.cpp", "ext/opencv/cvbox2d.h", "ext/opencv/cvcapture.cpp", "ext/opencv/cvcapture.h", "ext/opencv/cvchain.cpp", "ext/opencv/cvchain.h", "ext/opencv/cvchaincode.cpp", "ext/opencv/cvchaincode.h", "ext/opencv/cvcircle32f.cpp", "ext/opencv/cvcircle32f.h", "ext/opencv/cvcondensation.cpp", "ext/opencv/cvcondensation.h", "ext/opencv/cvconnectedcomp.cpp", "ext/opencv/cvconnectedcomp.h", "ext/opencv/cvcontour.cpp", "ext/opencv/cvcontour.h", "ext/opencv/cvcontourtree.cpp", "ext/opencv/cvcontourtree.h", "ext/opencv/cvconvexitydefect.cpp", "ext/opencv/cvconvexitydefect.h", "ext/opencv/cverror.cpp", "ext/opencv/cverror.h", "ext/opencv/cvfont.cpp", "ext/opencv/cvfont.h", "ext/opencv/cvhaarclassifiercascade.cpp", "ext/opencv/cvhaarclassifiercascade.h", "ext/opencv/cvhistogram.cpp", "ext/opencv/cvhistogram.h", "ext/opencv/cvhumoments.cpp", "ext/opencv/cvhumoments.h", "ext/opencv/cvindex.cpp", "ext/opencv/cvindex.h", "ext/opencv/cvline.cpp", "ext/opencv/cvline.h", "ext/opencv/cvmat.cpp", "ext/opencv/cvmat.h", "ext/opencv/cvmatnd.cpp", "ext/opencv/cvmatnd.h", "ext/opencv/cvmemstorage.cpp", "ext/opencv/cvmemstorage.h", "ext/opencv/cvmoments.cpp", "ext/opencv/cvmoments.h", "ext/opencv/cvpoint.cpp", "ext/opencv/cvpoint.h", "ext/opencv/cvpoint2d32f.cpp", "ext/opencv/cvpoint2d32f.h", "ext/opencv/cvpoint3d32f.cpp", "ext/opencv/cvpoint3d32f.h", "ext/opencv/cvrect.cpp", "ext/opencv/cvrect.h", "ext/opencv/cvscalar.cpp", "ext/opencv/cvscalar.h", "ext/opencv/cvseq.cpp", "ext/opencv/cvseq.h", "ext/opencv/cvset.cpp", "ext/opencv/cvset.h", "ext/opencv/cvsize.cpp", "ext/opencv/cvsize.h", "ext/opencv/cvsize2d32f.cpp", "ext/opencv/cvsize2d32f.h", "ext/opencv/cvslice.cpp", "ext/opencv/cvslice.h", "ext/opencv/cvsparsemat.cpp", "ext/opencv/cvsparsemat.h", "ext/opencv/cvtermcriteria.cpp", "ext/opencv/cvtermcriteria.h", "ext/opencv/cvtwopoints.cpp", "ext/opencv/cvtwopoints.h", "ext/opencv/cvvideowriter.cpp", "ext/opencv/cvvideowriter.h", "ext/opencv/extconf.rb", "ext/opencv/gui.cpp", "ext/opencv/gui.h", "ext/opencv/iplconvkernel.cpp", "ext/opencv/iplconvkernel.h", "ext/opencv/iplimage.cpp", "ext/opencv/iplimage.h", "ext/opencv/mouseevent.cpp", "ext/opencv/mouseevent.h", "ext/opencv/opencv.cpp", "ext/opencv/opencv.h", "ext/opencv/point3dset.cpp", "ext/opencv/point3dset.h", "ext/opencv/pointset.cpp", "ext/opencv/pointset.h", "ext/opencv/trackbar.cpp", "ext/opencv/trackbar.h", "ext/opencv/window.cpp", "ext/opencv/window.h", "images/CvMat_sobel.png", "images/CvMat_sub_rect.png", "images/CvSeq_relationmap.png", "images/face_detect_from_lena.jpg", "lib/opencv.rb", "lib/version.rb", "setup/setup.cygwin.rb", "setup/setup.mingw.rb", "setup/setup.mswin32.rb", "test/helper.rb", "test/runner.rb", "test/samples/airplane.jpg", "test/samples/baboon.jpg", "test/samples/baboon200.jpg", "test/samples/baboon200_rotated.jpg", "test/samples/cat.jpg", "test/samples/contours.jpg", "test/samples/fruits.jpg", "test/samples/inpaint-mask.bmp", "test/samples/lena-256x256.jpg", "test/samples/lena-32x32.jpg", "test/samples/lena-eyes.jpg", "test/samples/lena-inpaint.jpg", "test/samples/lena.jpg", "test/samples/lines.jpg", "test/samples/one_way_train_0000.jpg", "test/samples/one_way_train_0001.jpg", "test/samples/str-cv-rotated.jpg", "test/samples/str-cv.jpg", "test/samples/str-ov.jpg", "test/samples/stuff.jpg", "test/test_cvbox2d.rb", "test/test_cvchain.rb", "test/test_cvcircle32f.rb", "test/test_cvconnectedcomp.rb", "test/test_cvcontour.rb", "test/test_cvfont.rb", "test/test_cvhumoments.rb", "test/test_cvline.rb", "test/test_cvmat.rb", "test/test_cvmat_drawing.rb", "test/test_cvmat_dxt.rb", "test/test_cvmat_imageprocessing.rb", "test/test_cvmoments.rb", "test/test_cvpoint.rb", "test/test_cvpoint2d32f.rb", "test/test_cvpoint3d32f.rb", "test/test_cvrect.rb", "test/test_cvscalar.rb", "test/test_cvseq.rb", "test/test_cvsize.rb", "test/test_cvsize2d32f.rb", "test/test_cvtermcriteria.rb", "test/test_cvtwopoints.rb", "test/test_iplconvkernel.rb", "test/test_iplimage.rb", "test/test_opencv.rb", "test/test_preliminary.rb"] + s.homepage = %q{http://blueruby.mydns.jp/opencv} + s.rdoc_options = ["--main", "README.rdoc"] + s.require_paths = ["lib"] + s.rubyforge_project = %q{opencv} + s.rubygems_version = %q{1.6.2} + s.summary = %q{OpenCV wrapper for Ruby.} + s.test_files = ["test/test_cvmoments.rb", "test/test_cvhumoments.rb", "test/test_cvmat_drawing.rb", "test/test_iplconvkernel.rb", "test/test_cvconnectedcomp.rb", "test/test_cvscalar.rb", "test/test_cvline.rb", "test/test_cvcircle32f.rb", "test/test_cvchain.rb", "test/test_opencv.rb", "test/test_cvrect.rb", "test/test_cvfont.rb", "test/test_cvpoint2d32f.rb", "test/test_cvtermcriteria.rb", "test/test_cvmat_imageprocessing.rb", "test/test_cvpoint.rb", "test/test_cvbox2d.rb", "test/test_cvcontour.rb", "test/test_cvmat_dxt.rb", "test/test_preliminary.rb", "test/test_cvsize.rb", "test/test_cvsize2d32f.rb", "test/test_iplimage.rb", "test/test_cvtwopoints.rb", "test/test_cvseq.rb", "test/test_cvpoint3d32f.rb", "test/test_cvmat.rb"] + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 2.9.4"]) + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 2.9.4"]) + end + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 2.9.4"]) + end +end diff --git a/test/samples/blank0.jpg b/test/samples/blank0.jpg new file mode 100644 index 00000000..878fb3b3 Binary files /dev/null and b/test/samples/blank0.jpg differ diff --git a/test/samples/blank1.jpg b/test/samples/blank1.jpg new file mode 100644 index 00000000..b151a5c6 Binary files /dev/null and b/test/samples/blank1.jpg differ diff --git a/test/samples/blank2.jpg b/test/samples/blank2.jpg new file mode 100644 index 00000000..37dde3cd Binary files /dev/null and b/test/samples/blank2.jpg differ diff --git a/test/samples/blank3.jpg b/test/samples/blank3.jpg new file mode 100644 index 00000000..445c93e7 Binary files /dev/null and b/test/samples/blank3.jpg differ diff --git a/test/samples/blank4.jpg b/test/samples/blank4.jpg new file mode 100644 index 00000000..7f3214ba Binary files /dev/null and b/test/samples/blank4.jpg differ diff --git a/test/samples/blank5.jpg b/test/samples/blank5.jpg new file mode 100644 index 00000000..36ad8704 Binary files /dev/null and b/test/samples/blank5.jpg differ diff --git a/test/samples/blank6.jpg b/test/samples/blank6.jpg new file mode 100644 index 00000000..1500513f Binary files /dev/null and b/test/samples/blank6.jpg differ diff --git a/test/samples/blank7.jpg b/test/samples/blank7.jpg new file mode 100644 index 00000000..0a1813f7 Binary files /dev/null and b/test/samples/blank7.jpg differ diff --git a/test/samples/blank8.jpg b/test/samples/blank8.jpg new file mode 100644 index 00000000..d352c0a6 Binary files /dev/null and b/test/samples/blank8.jpg differ diff --git a/test/samples/blank9.jpg b/test/samples/blank9.jpg new file mode 100644 index 00000000..7bb62bf9 Binary files /dev/null and b/test/samples/blank9.jpg differ diff --git a/test/samples/messy0.jpg b/test/samples/messy0.jpg new file mode 100644 index 00000000..918e943f Binary files /dev/null and b/test/samples/messy0.jpg differ diff --git a/test/samples/messy1.jpg b/test/samples/messy1.jpg new file mode 100644 index 00000000..7405cf58 Binary files /dev/null and b/test/samples/messy1.jpg differ diff --git a/test/samples/partially_blank0.jpg b/test/samples/partially_blank0.jpg new file mode 100644 index 00000000..54c5b489 Binary files /dev/null and b/test/samples/partially_blank0.jpg differ diff --git a/test/samples/partially_blank1.jpg b/test/samples/partially_blank1.jpg new file mode 100644 index 00000000..2ab27b43 Binary files /dev/null and b/test/samples/partially_blank1.jpg differ diff --git a/test/samples/smooth0.jpg b/test/samples/smooth0.jpg new file mode 100644 index 00000000..7b9fbb0a Binary files /dev/null and b/test/samples/smooth0.jpg differ diff --git a/test/samples/smooth1.jpg b/test/samples/smooth1.jpg new file mode 100644 index 00000000..7b2619da Binary files /dev/null and b/test/samples/smooth1.jpg differ diff --git a/test/samples/smooth2.jpg b/test/samples/smooth2.jpg new file mode 100644 index 00000000..5fb4ff87 Binary files /dev/null and b/test/samples/smooth2.jpg differ diff --git a/test/samples/smooth3.jpg b/test/samples/smooth3.jpg new file mode 100644 index 00000000..240c5d53 Binary files /dev/null and b/test/samples/smooth3.jpg differ diff --git a/test/samples/smooth4.jpg b/test/samples/smooth4.jpg new file mode 100644 index 00000000..2a3fd16f Binary files /dev/null and b/test/samples/smooth4.jpg differ diff --git a/test/samples/smooth5.jpg b/test/samples/smooth5.jpg new file mode 100644 index 00000000..cecdb41d Binary files /dev/null and b/test/samples/smooth5.jpg differ diff --git a/test/samples/smooth6.jpg b/test/samples/smooth6.jpg new file mode 100644 index 00000000..d4448e24 Binary files /dev/null and b/test/samples/smooth6.jpg differ diff --git a/test/samples/smooth7.jpg b/test/samples/smooth7.jpg new file mode 100644 index 00000000..ff2d09b9 Binary files /dev/null and b/test/samples/smooth7.jpg differ diff --git a/test/samples/smooth8.jpg b/test/samples/smooth8.jpg new file mode 100644 index 00000000..090958ed Binary files /dev/null and b/test/samples/smooth8.jpg differ diff --git a/test/test_iplimage_smoothness.rb b/test/test_iplimage_smoothness.rb new file mode 100755 index 00000000..da26633e --- /dev/null +++ b/test/test_iplimage_smoothness.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# -*- mode: ruby; coding: utf-8-unix -*- +require 'test/unit' +require 'opencv' +require File.expand_path(File.dirname(__FILE__)) + '/helper' + +include OpenCV + +# Tests for OpenCV::IplImage +class TestIplImage < OpenCVTestCase + def should_classify_images_as(filename, classification) + assert_equal(OpenCV::IplImage::load(filename, OpenCV::CV_LOAD_IMAGE_GRAYSCALE).smoothness[0], classification) + end + + def test_smoothness + asset_path = File.join(File.dirname(__FILE__), 'samples') + + for image in Array.new(9) { |e| e = File.join(asset_path, "smooth%d.jpg") % e } do + should_classify_images_as image, :smooth + end + + for image in Array.new(2) { |e| e = File.join(asset_path, "messy%d.jpg") % e } do + should_classify_images_as image, :messy + end + + for image in Array.new(10) { |e| e = File.join(asset_path, "blank%d.jpg") % e } do + should_classify_images_as image, :blank + end + + for image in Array.new(2) { |e| e = File.join(asset_path, "partially_blank%d.jpg") % e } do + should_classify_images_as image, :blank + end + end +end