mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
Added gemspec to be able to bundle install from git.
Added IplImage#smoothness that returns :smooth, :messy, or :blank. Rake compile will now compile the C extension code.
This commit is contained in:
parent
9f801045b8
commit
08a9655dc1
127 changed files with 826 additions and 540 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -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/
|
||||
|
|
5
Gemfile
Normal file
5
Gemfile
Normal file
|
@ -0,0 +1,5 @@
|
|||
source :gemcutter
|
||||
|
||||
gem "hoe"
|
||||
gem "hoe-gemspec"
|
||||
gem "rspec"
|
239
Manifest.txt
239
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
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
42
Rakefile
42
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 = <<EOF
|
||||
OpenCV wrapper for Ruby
|
||||
EOF
|
||||
p.rubyforge_name = 'opencv'
|
||||
p.developer('lsxi', 'masakazu.yonekura@gmail.com')
|
||||
p.email = ['masakazu.yonekura@gmail.com']
|
||||
|
||||
p.developer('pcting', 'pcting@gmail.com')
|
||||
|
||||
p.need_tar = false
|
||||
p.need_zip = false
|
||||
# p.rdoc_pattern =
|
||||
# p.remote_rdoc_dir =
|
||||
# p.rsync =
|
||||
p.readme_file = 'README.rdoc'
|
||||
p.history_file = 'History.txt'
|
||||
p.spec_extras = {
|
||||
:extensions => %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
|
||||
|
|
233
ext/iplimage.cpp
233
ext/iplimage.cpp
|
@ -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(<i>width, height[, depth = CV_8U][, channel = 3]</i>)
|
||||
*
|
||||
* Create width * height image. Each element-value set 0.
|
||||
*
|
||||
* Each element possigle range is set by <i>depth</i>. Default is unsigned 8bit.
|
||||
*
|
||||
* Number of channel is set by <i>channel</i>. <i>channel</i> 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(<i>filename[,iscolor = CV_LOAD_IMAGE_COLOR]</i>)
|
||||
*
|
||||
* 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(<i>rect</i>)
|
||||
* set_roi(<i>rect</i>){|image| ...}
|
||||
*
|
||||
* Set ROI. <i>rect</i> 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(<i>coi</i>)
|
||||
* set_coi(<i>coi</i>){|image| ...}
|
||||
*
|
||||
* Set COI. <i>coi</i> 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
|
|
@ -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
|
|
@ -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)
|
||||
{
|
|
@ -72,4 +72,4 @@ else
|
|||
end
|
||||
|
||||
# step-final. create Makefile
|
||||
create_makefile("opencv")
|
||||
create_makefile("opencv/opencv")
|
536
ext/opencv/iplimage.cpp
Normal file
536
ext/opencv/iplimage.cpp
Normal file
|
@ -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(<i>width, height[, depth = CV_8U][, channel = 3]</i>)
|
||||
*
|
||||
* Create width * height image. Each element-value set 0.
|
||||
*
|
||||
* Each element possigle range is set by <i>depth</i>. Default is unsigned 8bit.
|
||||
*
|
||||
* Number of channel is set by <i>channel</i>. <i>channel</i> 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(<i>filename[,iscolor = CV_LOAD_IMAGE_COLOR]</i>)
|
||||
*
|
||||
* 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(<i>rect</i>)
|
||||
* set_roi(<i>rect</i>){|image| ...}
|
||||
*
|
||||
* Set ROI. <i>rect</i> 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(<i>coi</i>)
|
||||
* set_coi(<i>coi</i>){|image| ...}
|
||||
*
|
||||
* Set COI. <i>coi</i> 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(<i>lowFreqRatio, blankDensity, messyDensity, highFreqRatio</i>) -> [ 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
|
|
@ -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
|
|
@ -1,3 +1,3 @@
|
|||
require (File.dirname(__FILE__) + '/version')
|
||||
require 'opencv.so'
|
||||
require 'opencv/opencv.so'
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue