mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
added raise_typeerror, raise_compatible_typeerror
This commit is contained in:
parent
ecca9a0d66
commit
76f2933061
17 changed files with 65 additions and 42 deletions
|
@ -102,8 +102,6 @@ rb_center(VALUE self)
|
|||
VALUE
|
||||
rb_set_center(VALUE self, VALUE value)
|
||||
{
|
||||
if (!cCvPoint2D32f::rb_compatible_q(rb_klass, value))
|
||||
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(cCvPoint2D32f::rb_class()));
|
||||
CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -38,17 +38,20 @@ VALUE new_object(CvBox2D box);
|
|||
|
||||
__NAMESPACE_END_CVBOX2D
|
||||
|
||||
inline CvBox2D *CVBOX2D(VALUE object){
|
||||
inline CvBox2D*
|
||||
CVBOX2D(VALUE object){
|
||||
CvBox2D *ptr;
|
||||
Data_Get_Struct(object, CvBox2D, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvBox2D VALUE_TO_CVBOX2D(VALUE object){
|
||||
if(rb_obj_is_kind_of(object, cCvBox2D::rb_class())) {
|
||||
inline CvBox2D
|
||||
VALUE_TO_CVBOX2D(VALUE object){
|
||||
if (rb_obj_is_kind_of(object, cCvBox2D::rb_class())) {
|
||||
return *CVBOX2D(object);
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvBox2D::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_typeerror(object, cCvBox2D::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ rb_set_size(VALUE self, VALUE value)
|
|||
result = cvSetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT, height);
|
||||
}
|
||||
else
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSize::rb_class()));
|
||||
raise_compatible_typeerror(object, cCvSize::rb_class());
|
||||
return DBL2NUM(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ rb_detect_objects(int argc, VALUE *argv, VALUE self)
|
|||
rb_scan_args(argc, argv, "11", &image, &options);
|
||||
|
||||
if (!rb_obj_is_kind_of(image, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1(target-image) should be %s.", rb_class2name(cCvMat::rb_class()));
|
||||
raise_typeerror(image, cCvMat::rb_class());
|
||||
|
||||
double scale_factor;
|
||||
int flags, min_neighbors;
|
||||
|
|
|
@ -278,7 +278,6 @@ VALUE new_mat_kind_object(CvSize size, VALUE ref_obj, int cvmat_depth, int chann
|
|||
|
||||
__NAMESPACE_END_CVMAT
|
||||
|
||||
|
||||
inline CvMat*
|
||||
CVMAT(VALUE object)
|
||||
{
|
||||
|
@ -291,22 +290,21 @@ inline CvMat*
|
|||
CVMAT_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
||||
rb_class2name(CLASS_OF(object)), rb_class2name(cCvMat::rb_class()));
|
||||
raise_typeerror(object, cCvMat::rb_class());
|
||||
return CVMAT(object);
|
||||
}
|
||||
|
||||
inline CvMat*
|
||||
MASK(VALUE object)
|
||||
{
|
||||
if(NIL_P(object))
|
||||
if (NIL_P(object))
|
||||
return NULL;
|
||||
else if(rb_obj_is_kind_of(object, cCvMat::rb_class()) &&
|
||||
CV_MAT_DEPTH(CVMAT(object)->type) == CV_8UC1 &&
|
||||
CV_MAT_CN(CVMAT(object)->type) == 1)
|
||||
else if (rb_obj_is_kind_of(object, cCvMat::rb_class()) &&
|
||||
CV_MAT_DEPTH(CVMAT(object)->type) == CV_8UC1 &&
|
||||
CV_MAT_CN(CVMAT(object)->type) == 1)
|
||||
return CVMAT(object);
|
||||
else
|
||||
rb_raise(rb_eTypeError, "object is not mask.");
|
||||
rb_raise(rb_eTypeError, "object is not a mask.");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
|
@ -46,11 +46,12 @@ inline CvPoint *CVPOINT(VALUE object){
|
|||
}
|
||||
|
||||
inline CvPoint VALUE_TO_CVPOINT(VALUE object){
|
||||
if(cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)){
|
||||
if (cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)) {
|
||||
return cvPoint(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("y"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,12 @@ CVPOINT2D32F(VALUE object)
|
|||
inline CvPoint2D32f
|
||||
VALUE_TO_CVPOINT2D32F(VALUE object)
|
||||
{
|
||||
if(cCvPoint2D32f::rb_compatible_q(cCvPoint2D32f::rb_class(), object)){
|
||||
if (cCvPoint2D32f::rb_compatible_q(cCvPoint2D32f::rb_class(), object)) {
|
||||
return cvPoint2D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint2D32f::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint2D32f::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,13 @@ CVPOINT3D32F(VALUE object)
|
|||
inline CvPoint3D32f
|
||||
VALUE_TO_CVPOINT3D32F(VALUE object)
|
||||
{
|
||||
if(cCvPoint3D32f::rb_compatible_q(cCvPoint3D32f::rb_class(), object)){
|
||||
if (cCvPoint3D32f::rb_compatible_q(cCvPoint3D32f::rb_class(), object)) {
|
||||
return cvPoint3D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("z"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint3D32f::rb_class()));
|
||||
}
|
||||
else{
|
||||
raise_compatible_typeerror(object, cCvPoint3D32f::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,10 @@ define_ruby_class()
|
|||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y")) && rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
return (rb_respond_to(object, rb_intern("x")) &&
|
||||
rb_respond_to(object, rb_intern("y")) &&
|
||||
rb_respond_to(object, rb_intern("width")) &&
|
||||
rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -153,12 +156,13 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
|||
break;
|
||||
case 1:
|
||||
object = argv[0];
|
||||
if(rb_compatible_q(rb_klass, object)) {
|
||||
if (rb_compatible_q(rb_klass, object)) {
|
||||
CVRECT(self)->x = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("x"), 0), rb_intern("to_i"), 0));
|
||||
CVRECT(self)->y = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("y"), 0), rb_intern("to_i"), 0));
|
||||
CVRECT(self)->width = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("width"), 0), rb_intern("to_i"), 0));
|
||||
CVRECT(self)->height = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("height"), 0), rb_intern("to_i"), 0));
|
||||
}else{
|
||||
}
|
||||
else{
|
||||
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -63,13 +63,14 @@ CVRECT(VALUE object)
|
|||
inline CvRect
|
||||
VALUE_TO_CVRECT(VALUE object)
|
||||
{
|
||||
if(cCvRect::rb_compatible_q(cCvRect::rb_class(), object)){
|
||||
if (cCvRect::rb_compatible_q(cCvRect::rb_class(), object)) {
|
||||
return cvRect(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("y"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvRect::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvRect::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ VALUE_TO_CVSCALAR(VALUE object)
|
|||
NUM2DBL(rb_funcall(object, rb_intern("[]"), 1, INT2FIX(2))),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("[]"), 1, INT2FIX(3))));
|
||||
else
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvScalar::rb_class()));
|
||||
raise_compatible_typeerror(object, cCvScalar::rb_class());
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
|
@ -50,11 +50,12 @@ CVSIZE(VALUE object)
|
|||
inline CvSize
|
||||
VALUE_TO_CVSIZE(VALUE object)
|
||||
{
|
||||
if(cCvSize::rb_compatible_q(cCvSize::rb_class(), object)){
|
||||
if (cCvSize::rb_compatible_q(cCvSize::rb_class(), object)) {
|
||||
return cvSize(NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSize::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSize::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,12 @@ CVSIZE2D32F(VALUE object)
|
|||
inline CvSize2D32f
|
||||
VALUE_TO_CVSIZE2D32F(VALUE object)
|
||||
{
|
||||
if(cCvSize2D32f::rb_compatible_q(cCvSize2D32f::rb_class(), object)){
|
||||
if (cCvSize2D32f::rb_compatible_q(cCvSize2D32f::rb_class(), object)) {
|
||||
return cvSize2D32f(NUM2DBL(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSize2D32f::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSize2D32f::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ VALUE_TO_CVSLICE(VALUE object)
|
|||
rb_funcall(object, rb_intern("exclude_end?"), 0) ? NUM2INT(rb_funcall(object, rb_intern("end"), 0)) : NUM2INT(rb_funcall(object, rb_intern("end"), 0)) - 1);
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSlice::rb_class()));
|
||||
raise_compatible_typeerror(object, cCvSlice::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ VALUE_TO_CVTERMCRITERIA(VALUE object)
|
|||
return cvTermCriteria(CV_TERMCRIT_EPS, 0, NUM2DBL(object));
|
||||
case T_ARRAY:
|
||||
if (RARRAY_LEN(object) == 2) {
|
||||
return cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,
|
||||
return cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS,
|
||||
NUM2INT(rb_ary_entry(object, 0)),
|
||||
NUM2DBL(rb_ary_entry(object, 1)));
|
||||
}
|
||||
|
|
|
@ -276,6 +276,18 @@ rb_cvCreateMemStorage(int block_size)
|
|||
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;
|
||||
|
||||
|
|
|
@ -160,7 +160,6 @@ extern "C"{
|
|||
#define INT2BOOL(x) (x ? Qtrue : Qfalse)
|
||||
#endif
|
||||
|
||||
|
||||
// wrapper for <= 1.8
|
||||
#ifndef RARRAY_LEN
|
||||
#define RARRAY_LEN(arg) (RARRAY(arg)->len)
|
||||
|
@ -194,6 +193,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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue