Пример #1
0
CvSeq*
create_seq(int seq_flags, size_t header_size, VALUE storage_value)
{
  VALUE klass = Qnil;
  int eltype = seq_flags & CV_SEQ_ELTYPE_MASK;
  storage_value = CHECK_CVMEMSTORAGE(storage_value);

  if (!eltype2class(eltype, &klass)) {
    seq_flags = CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_GENERIC;
  }

  int mat_type = CV_MAT_TYPE(seq_flags);
  size_t elem_size = (size_t)(CV_ELEM_SIZE(mat_type));
  CvSeq* seq = NULL;
  try {
    seq = cvCreateSeq(seq_flags, header_size, elem_size, CVMEMSTORAGE(storage_value));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  register_elem_class(seq, klass);
  register_root_object(seq, storage_value);
  
  return seq;
}
Пример #2
0
/*
 * call-seq:
 *   CvSeq.new(type[,storage])
 *
 * Return a new CvSeq. <i>type</i> should be following classes.
 *
 * * CvIndex
 * * CvPoint
 */
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE klass, storage_value;

  rb_scan_args(argc, argv, "11", &klass, &storage_value);
  if (!rb_obj_is_kind_of(klass, rb_cClass))
    raise_typeerror(klass, rb_cClass);

  int type = 0, size = 0;
  if (klass == rb_cFixnum) {
    type = CV_SEQ_ELTYPE_INDEX;
    size = sizeof(int);
  }
  else if (klass == cCvPoint::rb_class()) {
    type = CV_SEQ_ELTYPE_POINT;
    size = sizeof(CvPoint);
  }
  else if (klass == cCvPoint2D32f::rb_class()) {
    type = CV_SEQ_ELTYPE_POINT;
    size = sizeof(CvPoint2D32f);
  }
  else if (klass == cCvPoint3D32f::rb_class()) {
    type = CV_SEQ_ELTYPE_POINT3D;
    size = sizeof(CvPoint3D32f);
  }
  else
    rb_raise(rb_eArgError, "unsupport %s class for sequence-block.", rb_class2name(klass));
  
  CvSeq* seq = NULL;
  if (NIL_P(storage_value)) {
    storage_value = cCvMemStorage::new_object(0);
  }
  else {
    storage_value = CHECK_CVMEMSTORAGE(storage_value);
  }
  
  try {
    seq = cvCreateSeq(type, sizeof(CvSeq), size, CVMEMSTORAGE(storage_value));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  DATA_PTR(self) = seq;
  register_elem_class(seq, klass);
  register_root_object(seq, storage_value);
  
  return self;
}
Пример #3
0
CvSeq*
create_seq(int seq_flags, size_t header_size, VALUE storage_value)
{
  VALUE klass = Qnil;
  int eltype = seq_flags & CV_SEQ_ELTYPE_MASK;
  storage_value = CHECK_CVMEMSTORAGE(storage_value);

  switch (eltype) {
  case CV_SEQ_ELTYPE_POINT:
    klass = cCvPoint::rb_class();
    break;
  case CV_32FC2:
    klass = cCvPoint2D32f::rb_class();
    break;
  case CV_SEQ_ELTYPE_POINT3D:
    klass = cCvPoint3D32f::rb_class();
    break;
  case CV_SEQ_ELTYPE_CODE:
  case CV_SEQ_ELTYPE_INDEX:
    klass = rb_cFixnum;
    break;
  case CV_SEQ_ELTYPE_PPOINT: // or CV_SEQ_ELTYPE_PTR:
    // Not supported
    rb_raise(rb_eArgError, "seq_flags %d is not supported.", eltype);
    break;
  default:
    seq_flags = CV_SEQ_ELTYPE_POINT | CV_SEQ_KIND_GENERIC;
    klass = cCvPoint::rb_class();
    break;
  }

  int mat_type = CV_MAT_TYPE(seq_flags);
  size_t elem_size = (size_t)(CV_ELEM_SIZE(mat_type));
  CvSeq* seq = NULL;
  try {
    seq = cvCreateSeq(seq_flags, header_size, elem_size, CVMEMSTORAGE(storage_value));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  register_elem_class(seq, klass);
  register_root_object(seq, storage_value);
  
  return seq;
}