1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

moved some functions to cvutils

This commit is contained in:
ser1zw 2011-07-03 15:12:36 +09:00
parent 76f2933061
commit aaa0de3810
7 changed files with 199 additions and 170 deletions

View file

@ -80,6 +80,8 @@ ext/opencv/cvtermcriteria.cpp
ext/opencv/cvtermcriteria.h
ext/opencv/cvtwopoints.cpp
ext/opencv/cvtwopoints.h
ext/opencv/cvutils.cpp
ext/opencv/cvutils.h
ext/opencv/cvvideowriter.cpp
ext/opencv/cvvideowriter.h
ext/opencv/gui.cpp

View file

@ -283,7 +283,7 @@ rb_set_size(VALUE self, VALUE value)
result = cvSetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT, height);
}
else
raise_compatible_typeerror(object, cCvSize::rb_class());
raise_compatible_typeerror(value, cCvSize::rb_class());
return DBL2NUM(result);
}

170
ext/opencv/cvutils.cpp Normal file
View file

@ -0,0 +1,170 @@
/************************************************************
cvutils.cpp -
$Author: ser1zw $
Copyright (C) 2011 ser1zw
************************************************************/
#include "cvutils.h"
void
raise_typeerror(VALUE object, VALUE expected_class) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
rb_obj_classname(object), rb_class2name(expected_class));
}
void
raise_compatible_typeerror(VALUE object, VALUE expected_class) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s or compatible object)",
rb_obj_classname(object), rb_class2name(expected_class));
}
/*
* Allocates a memory buffer
* When memory allocation is failed, run GC and retry it
*/
void*
rb_cvAlloc(size_t size)
{
void* ptr = NULL;
try {
ptr = cvAlloc(size);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvAlloc(size);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Creates CvMat and underlying data
* When memory allocation is failed, run GC and retry it
*/
CvMat*
rb_cvCreateMat(int height, int width, int type)
{
CvMat* ptr = NULL;
try {
ptr = cvCreateMat(height, width, type);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateMat(height, width, type);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Create IplImage header and allocate underlying data
* When memory allocation is failed, run GC and retry it
*/
IplImage*
rb_cvCreateImage(CvSize size, int depth, int channels)
{
IplImage* ptr = NULL;
try {
ptr = cvCreateImage(size, depth, channels);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateImage(size, depth, channels);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Creates a structuring element
* When memory allocation is failed, run GC and retry it
*/
IplConvKernel*
rb_cvCreateStructuringElementEx(int cols, int rows,
int anchorX, int anchorY,
int shape, int *values)
{
IplConvKernel* ptr = NULL;
try {
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Creates memory storage
* When memory allocation is failed, run GC and retry it
*/
CvMemStorage*
rb_cvCreateMemStorage(int block_size)
{
CvMemStorage* ptr = NULL;
try {
ptr = cvCreateMemStorage(block_size);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateMemStorage(block_size);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}

24
ext/opencv/cvutils.h Normal file
View file

@ -0,0 +1,24 @@
/************************************************************
cvutils.h -
$Author: ser1zw $
Copyright (C) 2011 ser1zw
************************************************************/
#include <ruby.h>
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
void raise_typeerror(VALUE object, VALUE expected_class);
void raise_compatible_typeerror(VALUE object, VALUE expected_class);
void* rb_cvAlloc(size_t size);
CvMat* rb_cvCreateMat(int height, int width, int type);
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
CvMemStorage* rb_cvCreateMemStorage(int block_size);

View file

@ -129,165 +129,6 @@ release_iplconvkernel_object(void *ptr)
}
}
/*
* Allocates a memory buffer
* When memory allocation is failed, run GC and retry it
*/
void*
rb_cvAlloc(size_t size)
{
void* ptr = NULL;
try {
ptr = cvAlloc(size);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvAlloc(size);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Creates CvMat and underlying data
* When memory allocation is failed, run GC and retry it
*/
CvMat*
rb_cvCreateMat(int height, int width, int type)
{
CvMat* ptr = NULL;
try {
ptr = cvCreateMat(height, width, type);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateMat(height, width, type);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Create IplImage header and allocate underlying data
* When memory allocation is failed, run GC and retry it
*/
IplImage*
rb_cvCreateImage(CvSize size, int depth, int channels)
{
IplImage* ptr = NULL;
try {
ptr = cvCreateImage(size, depth, channels);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateImage(size, depth, channels);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Creates a structuring element
* When memory allocation is failed, run GC and retry it
*/
IplConvKernel*
rb_cvCreateStructuringElementEx(int cols, int rows,
int anchorX, int anchorY,
int shape, int *values)
{
IplConvKernel* ptr = NULL;
try {
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
/*
* Creates memory storage
* When memory allocation is failed, run GC and retry it
*/
CvMemStorage*
rb_cvCreateMemStorage(int block_size)
{
CvMemStorage* ptr = NULL;
try {
ptr = cvCreateMemStorage(block_size);
}
catch(cv::Exception& e) {
if (e.code != CV_StsNoMem)
rb_raise(rb_eRuntimeError, "%s", e.what());
rb_gc_start();
try {
ptr = cvCreateMemStorage(block_size);
}
catch (cv::Exception& e) {
if (e.code == CV_StsNoMem)
rb_raise(rb_eNoMemError, "%s", e.what());
else
rb_raise(rb_eRuntimeError, "%s", e.what());
}
}
return ptr;
}
void
raise_typeerror(VALUE object, VALUE expected_class) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
rb_obj_classname(object), rb_class2name(expected_class));
}
void
raise_compatible_typeerror(VALUE object, VALUE expected_class) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s or compatible object)",
rb_obj_classname(object), rb_class2name(expected_class));
}
VALUE rb_module;
VALUE rb_opencv_constants;

View file

@ -81,6 +81,7 @@ extern "C"{
#endif
// Ruby/OpenCV headers
#include "cvutils.h"
#include "cverror.h"
#include "cvpoint.h"
#include "cvpoint2d32f.h"
@ -193,18 +194,9 @@ void free_object(void *ptr);
void release_object(void *ptr);
void release_iplconvkernel_object(void *ptr);
void raise_typeerror(VALUE object, VALUE expected_class);
void raise_compatible_typeerror(VALUE object, VALUE expected_class);
VALUE rb_module_opencv();
void define_ruby_module();
void* rb_cvAlloc(size_t size);
CvMat* rb_cvCreateMat(int height, int width, int type);
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
CvMemStorage* rb_cvCreateMemStorage(int block_size);
// Ruby/OpenCV inline functions
inline CvArr*
CVARR(VALUE object)

View file

@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.email = ["masakazu.yonekura@gmail.com", "", "pcting@gmail.com"]
s.extensions = ["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/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/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", "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.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/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/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/cvutils.cpp", "ext/opencv/cvutils.h", "ext/opencv/cvvideowriter.cpp", "ext/opencv/cvvideowriter.h", "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"]