Class: OpenCV::CvCapture
- Inherits:
-
Data
- Object
- Data
- OpenCV::CvCapture
- Defined in:
- ext/opencv/cvcapture.cpp,
ext/opencv/cvcapture.cpp
Overview
Class for video capturing from video files or cameras
Constant Summary collapse
- INTERFACE =
:any, :mil, :vfw, :v4l, :v4l2, :fireware, :ieee1394, :dc1394, :cmu1394, :stereo, :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime
video_interface
- APPROX_OPTION =
approx_option
Class Method Summary collapse
-
.open(dev = nil) ⇒ CvCapture
Open video file or a capturing device for video capturing.
Instance Method Summary collapse
-
#approx_poly(options) ⇒ CvContour?
(also: #approx)
Approximates polygonal curves with desired precision.
-
#avi_ratio ⇒ Number
Get relative position of video file.
-
#avi_ratio= ⇒ Number
Set relative position of video file.
-
#bounding_rect ⇒ CvRect
Calculates up-right bounding rectangle of point set.
-
#brightness ⇒ Number
Get brightness of the image (only for cameras).
-
#color ⇒ Number
Returns color of the contour.
-
#color= ⇒ Object
Set color of the contour.
-
#contrast ⇒ Number
Get contrast of the image (only for cameras).
-
#convert_rgb ⇒ Boolean
Get boolean flags indicating whether images should be converted to RGB.
-
#create_tree(threshold = 0.0) ⇒ CvContourTree
Creates hierarchical representation of contour.
-
#exposure ⇒ Number
Get exposure (only for cameras).
-
#format ⇒ Number
Get format of images returned by CvCapture#retrieve.
-
#fourcc ⇒ Number
Get 4 character code of codec.
-
#fps ⇒ Number
Get frame rate.
-
#fps= ⇒ Number
Set frame rate.
-
#frame_count ⇒ Number
Get number of frames in video file.
-
#frames ⇒ Number
Get 0-based index of the frame to be decoded/captured next.
-
#frames= ⇒ Number
Set 0-based index of the frame to be decoded/captured next.
-
#gain ⇒ Number
Get gain of the image (only for cameras).
-
#grab ⇒ Boolean
Grabs the next frame from video file or capturing device.
-
#height ⇒ Number
Get height of frames in the video stream.
-
#height= ⇒ Number
Set height of frames in the video stream.
-
#hue ⇒ Number
Get hue of the image (only for cameras).
-
#in?(point) ⇒ Boolean
Performs a point-in-contour test.
-
#new(storage = nil) ⇒ CvContour
constructor
Constructor.
-
#measure_distance(point) ⇒ Object
Calculates distance between a point and the nearest contour edgex.
-
#millisecond ⇒ Number
Get film current position in milliseconds or video capture timestamp.
-
#millisecond= ⇒ Number
Set film current position in milliseconds or video capture timestamp.
-
#mode ⇒ Number
Get a backend-specific value indicating the current capture mode.
-
#point_polygon_test(point, measure_dist) ⇒ Number
Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
-
#query ⇒ IplImage?
Grabs, decodes and returns the next video frame.
-
#rect ⇒ CvRect
Returns bounding box of the contour.
-
#rectification ⇒ Number
Get rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently).
-
#reserved ⇒ Array<Number>
Returns reserved region values of the contour.
-
#retrieve ⇒ IplImage?
Decodes and returns the grabbed video frame.
-
#saturation ⇒ Number
Get saturation of the image (only for cameras).
-
#size ⇒ Size
Get size of frames in the video stream.
-
#size= ⇒ Number
Set size of frames in the video stream.
-
#width ⇒ Number
Get width of frames in the video stream.
-
#width= ⇒ Number
Set width of frames in the video stream.
Methods included from Curve
#arc_length, #closed?, #convex?, #hole?, #simple?
Methods included from PointSet
#check_contour_convexity, #contour_area, #convex_hull2, #convexity_defects, #fit_ellipse2, #min_area_rect2, #min_enclosing_circle
Constructor Details
#new(storage = nil) ⇒ CvContour
Constructor
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'ext/opencv/cvcontour.cpp', line 50
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE storage;
rb_scan_args(argc, argv, "01", &storage);
if (NIL_P(storage))
storage = cCvMemStorage::new_object(0);
else
storage = CHECK_CVMEMSTORAGE(storage);
try {
DATA_PTR(self) = (CvContour*)cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvContour),
sizeof(CvPoint), CVMEMSTORAGE(storage));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
cCvSeq::register_elem_class(self, cCvPoint::rb_class());
register_root_object(CVSEQ(self), storage);
return self;
}
|
Class Method Details
.open(dev = nil) ⇒ CvCapture
Open video file or a capturing device for video capturing
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'ext/opencv/cvcapture.cpp', line 46
VALUE
rb_open(int argc, VALUE *argv, VALUE self)
{
VALUE device;
rb_scan_args(argc, argv, "01", &device);
CvCapture *capture = 0;
try {
switch (TYPE(device)) {
case T_STRING:
capture = cvCaptureFromFile(StringValueCStr(device));
break;
case T_FIXNUM:
capture = cvCaptureFromCAM(FIX2INT(device));
break;
case T_SYMBOL: {
VALUE cap_index = rb_hash_lookup(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
if (NIL_P(cap_index))
rb_raise(rb_eArgError, "undefined interface.");
capture = cvCaptureFromCAM(NUM2INT(cap_index));
break;
}
case T_NIL:
capture = cvCaptureFromCAM(CV_CAP_ANY);
break;
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
if (!capture)
rb_raise(rb_eStandardError, "Invalid capture format.");
return Data_Wrap_Struct(rb_klass, 0, cvcapture_free, capture);
}
|
Instance Method Details
#approx_poly(options) ⇒ CvContour? Also known as: approx
Approximates polygonal curves with desired precision
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/opencv/cvcontour.cpp', line 136
VALUE
rb_approx_poly(int argc, VALUE *argv, VALUE self)
{
VALUE approx_poly_option;
rb_scan_args(argc, argv, "01", &approx_poly_option);
approx_poly_option = APPROX_POLY_OPTION(approx_poly_option);
VALUE storage = cCvMemStorage::new_object();
CvSeq *contour = cvApproxPoly(CVCONTOUR(self), sizeof(CvContour), CVMEMSTORAGE(storage),
APPROX_POLY_METHOD(approx_poly_option),
APPROX_POLY_ACCURACY(approx_poly_option),
APPROX_POLY_RECURSIVE(approx_poly_option));
if (contour && contour->total > 0) {
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
}
return Qnil;
}
|
#avi_ratio ⇒ Number
Get relative position of video file
243 244 245 246 247 |
# File 'ext/opencv/cvcapture.cpp', line 243
VALUE
rb_get_avi_ratio(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO);
}
|
#avi_ratio= ⇒ Number
Set relative position of video file
255 256 257 258 259 |
# File 'ext/opencv/cvcapture.cpp', line 255
VALUE
rb_set_avi_ratio(VALUE self, VALUE value)
{
return rb_set_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO, value);
}
|
#bounding_rect ⇒ CvRect
Calculates up-right bounding rectangle of point set.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'ext/opencv/cvcontour.cpp', line 160
VALUE
rb_bounding_rect(VALUE self)
{
CvRect rect;
try {
rect = cvBoundingRect(CVCONTOUR(self), 1);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return cCvRect::new_object(rect);
}
|
#brightness ⇒ Number
Get brightness of the image (only for cameras)
437 438 439 440 441 |
# File 'ext/opencv/cvcapture.cpp', line 437
VALUE
rb_get_brightness(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_BRIGHTNESS);
}
|
#color ⇒ Number
Returns color of the contour
90 91 92 93 94 |
# File 'ext/opencv/cvcontour.cpp', line 90
VALUE
rb_color(VALUE self)
{
return INT2NUM(CVCONTOUR(self)->color);
}
|
#color= ⇒ Object
Set color of the contour
101 102 103 104 105 106 |
# File 'ext/opencv/cvcontour.cpp', line 101
VALUE
rb_set_color(VALUE self, VALUE color)
{
CVCONTOUR(self)->color = NUM2INT(color);
return self;
}
|
#contrast ⇒ Number
Get contrast of the image (only for cameras)
449 450 451 452 453 |
# File 'ext/opencv/cvcapture.cpp', line 449
VALUE
rb_get_contrast(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_CONTRAST);
}
|
#convert_rgb ⇒ Boolean
Get boolean flags indicating whether images should be converted to RGB
508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'ext/opencv/cvcapture.cpp', line 508
VALUE
rb_get_convert_rgb(VALUE self)
{
int flag = 0;
try {
flag = (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_CONVERT_RGB);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return flag ? Qtrue : Qfalse;
}
|
#create_tree(threshold = 0.0) ⇒ CvContourTree
Creates hierarchical representation of contour
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'ext/opencv/cvcontour.cpp', line 181
VALUE
rb_create_tree(int argc, VALUE *argv, VALUE self)
{
VALUE threshold, storage;
rb_scan_args(argc, argv, "01", &threshold);
storage = cCvMemStorage::new_object();
CvContourTree *tree = NULL;
try {
tree = cvCreateContourTree(CVSEQ(self), CVMEMSTORAGE(storage), IF_DBL(threshold, 0.0));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return cCvSeq::new_sequence(cCvContourTree::rb_class(), (CvSeq*)tree, cCvPoint::rb_class(), storage);
}
|
#exposure ⇒ Number
Get exposure (only for cameras)
496 497 498 499 500 |
# File 'ext/opencv/cvcapture.cpp', line 496
VALUE
rb_get_exposure(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_EXPOSURE);
}
|
#format ⇒ Number
Get format of images returned by CvCapture#retrieve
413 414 415 416 417 |
# File 'ext/opencv/cvcapture.cpp', line 413
VALUE
rb_get_format(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_FORMAT);
}
|
#fourcc ⇒ Number
Get 4 character code of codec. see www.fourcc.org/
386 387 388 389 390 391 392 393 |
# File 'ext/opencv/cvcapture.cpp', line 386
VALUE
rb_get_fourcc(VALUE self)
{
char str[4];
double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
sprintf(str, "%s", (char*)&fourcc);
return rb_str_new2(str);
}
|
#fps ⇒ Number
Get frame rate
361 362 363 364 365 |
# File 'ext/opencv/cvcapture.cpp', line 361
VALUE
rb_get_fps(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_FPS);
}
|
#fps= ⇒ Number
Set frame rate
374 375 376 377 378 |
# File 'ext/opencv/cvcapture.cpp', line 374
VALUE
rb_set_fps(VALUE self, VALUE value)
{
return rb_set_capture_property(self, CV_CAP_PROP_FPS, value);
}
|
#frame_count ⇒ Number
Get number of frames in video file.
401 402 403 404 405 |
# File 'ext/opencv/cvcapture.cpp', line 401
VALUE
rb_get_frame_count(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_FRAME_COUNT);
}
|
#frames ⇒ Number
Get 0-based index of the frame to be decoded/captured next
219 220 221 222 223 |
# File 'ext/opencv/cvcapture.cpp', line 219
VALUE
rb_get_frames(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_POS_FRAMES);
}
|
#frames= ⇒ Number
Set 0-based index of the frame to be decoded/captured next
232 233 234 235 236 |
# File 'ext/opencv/cvcapture.cpp', line 232
VALUE
rb_set_frames(VALUE self, VALUE value)
{
return rb_set_capture_property(self, CV_CAP_PROP_POS_FRAMES, value);
}
|
#gain ⇒ Number
Get gain of the image (only for cameras)
484 485 486 487 488 |
# File 'ext/opencv/cvcapture.cpp', line 484
VALUE
rb_get_gain(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_GAIN);
}
|
#grab ⇒ Boolean
Grabs the next frame from video file or capturing device.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'ext/opencv/cvcapture.cpp', line 86
VALUE
rb_grab(VALUE self)
{
int grab = 0;
try {
grab = cvGrabFrame(CVCAPTURE(self));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return grab ? Qtrue : Qfalse;
}
|
#height ⇒ Number
Get height of frames in the video stream.
336 337 338 339 340 |
# File 'ext/opencv/cvcapture.cpp', line 336
VALUE
rb_get_height(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT);
}
|
#height= ⇒ Number
Set height of frames in the video stream.
349 350 351 352 353 |
# File 'ext/opencv/cvcapture.cpp', line 349
VALUE
rb_set_height(VALUE self, VALUE value)
{
return rb_set_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT, value);
}
|
#hue ⇒ Number
Get hue of the image (only for cameras)
472 473 474 475 476 |
# File 'ext/opencv/cvcapture.cpp', line 472
VALUE
rb_get_hue(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_HUE);
}
|
#in?(point) ⇒ Boolean
Performs a point-in-contour test. The method determines whether the point is inside a contour, outside, or lies on an edge (or coincides with a vertex).
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'ext/opencv/cvcontour.cpp', line 207
VALUE
rb_in_q(VALUE self, VALUE point)
{
double n = 0;
try {
n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
}
|
#measure_distance(point) ⇒ Object
Calculates distance between a point and the nearest contour edgex
227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'ext/opencv/cvcontour.cpp', line 227
VALUE
rb_measure_distance(VALUE self, VALUE point)
{
double distance = 0;
try {
distance = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return rb_float_new(distance);
}
|
#millisecond ⇒ Number
Get film current position in milliseconds or video capture timestamp.
194 195 196 197 198 |
# File 'ext/opencv/cvcapture.cpp', line 194
VALUE
rb_get_millisecond(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_POS_MSEC);
}
|
#millisecond= ⇒ Number
Set film current position in milliseconds or video capture timestamp.
207 208 209 210 211 |
# File 'ext/opencv/cvcapture.cpp', line 207
VALUE
rb_set_millisecond(VALUE self, VALUE value)
{
return rb_set_capture_property(self, CV_CAP_PROP_POS_MSEC, value);
}
|
#mode ⇒ Number
Get a backend-specific value indicating the current capture mode
425 426 427 428 429 |
# File 'ext/opencv/cvcapture.cpp', line 425
VALUE
rb_get_mode(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_MODE);
}
|
#point_polygon_test(point, measure_dist) ⇒ Number
Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'ext/opencv/cvcontour.cpp', line 250
VALUE
rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
{
int measure_dist_flag;
if (measure_dist == Qtrue)
measure_dist_flag = 1;
else if (measure_dist == Qfalse)
measure_dist_flag = 0;
else
measure_dist_flag = NUM2INT(measure_dist);
double dist = Qnil;
try {
dist = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), measure_dist_flag);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
/* cvPointPolygonTest returns 100, -100 or 0 when measure_dist = 0 */
if ((!measure_dist_flag) && ((int)dist) != 0)
dist = (dist > 0) ? 1 : -1;
return rb_float_new(dist);
}
|
#query ⇒ IplImage?
Grabs, decodes and returns the next video frame.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/opencv/cvcapture.cpp', line 138
VALUE
rb_query(VALUE self)
{
VALUE image = Qnil;
IplImage *frame = NULL;
try {
if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
return Qnil;
}
image = cIplImage::new_object(frame->width, frame->height,
CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
if (frame->origin == IPL_ORIGIN_TL) {
cvCopy(frame, CVARR(image));
}
else {
cvFlip(frame, CVARR(image));
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return image;
}
|
#rect ⇒ CvRect
Returns bounding box of the contour
79 80 81 82 83 |
# File 'ext/opencv/cvcontour.cpp', line 79
VALUE
rb_rect(VALUE self)
{
return cCvRect::new_object(CVCONTOUR(self)->rect);
}
|
#rectification ⇒ Number
Get rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
527 528 529 530 531 |
# File 'ext/opencv/cvcapture.cpp', line 527
VALUE
rb_get_rectification(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_RECTIFICATION);
}
|
#reserved ⇒ Array<Number>
Returns reserved region values of the contour
113 114 115 116 117 118 119 120 |
# File 'ext/opencv/cvcontour.cpp', line 113
VALUE
rb_reserved(VALUE self)
{
return rb_ary_new3(3,
INT2NUM(CVCONTOUR(self)->reserved[0]),
INT2NUM(CVCONTOUR(self)->reserved[1]),
INT2NUM(CVCONTOUR(self)->reserved[2]));
}
|
#retrieve ⇒ IplImage?
Decodes and returns the grabbed video frame.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/opencv/cvcapture.cpp', line 106
VALUE
rb_retrieve(VALUE self)
{
VALUE image = Qnil;
IplImage *frame = NULL;
try {
if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
return Qnil;
}
image = cIplImage::new_object(frame->width, frame->height,
CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
if (frame->origin == IPL_ORIGIN_TL) {
cvCopy(frame, CVARR(image));
}
else {
cvFlip(frame, CVARR(image));
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return image;
}
|
#saturation ⇒ Number
Get saturation of the image (only for cameras)
461 462 463 464 465 |
# File 'ext/opencv/cvcapture.cpp', line 461
VALUE
rb_get_saturation(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_SATURATION);
}
|
#size ⇒ Size
Get size of frames in the video stream.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'ext/opencv/cvcapture.cpp', line 267
VALUE
rb_get_size(VALUE self)
{
CvSize size;
try {
CvCapture* self_ptr = CVCAPTURE(self);
size = cvSize((int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return cCvSize::new_object(size);
}
|
#size= ⇒ Number
Set size of frames in the video stream.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'ext/opencv/cvcapture.cpp', line 289
VALUE
rb_set_size(VALUE self, VALUE value)
{
double result = 0;
CvSize size = VALUE_TO_CVSIZE(value);
try {
CvCapture* self_ptr = CVCAPTURE(self);
cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH, size.width);
result = cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT, size.height);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return DBL2NUM(result);
}
|
#width ⇒ Number
Get width of frames in the video stream.
311 312 313 314 315 |
# File 'ext/opencv/cvcapture.cpp', line 311
VALUE
rb_get_width(VALUE self)
{
return rb_get_capture_property(self, CV_CAP_PROP_FRAME_WIDTH);
}
|
#width= ⇒ Number
Set width of frames in the video stream.
324 325 326 327 328 |
# File 'ext/opencv/cvcapture.cpp', line 324
VALUE
rb_set_width(VALUE self, VALUE value)
{
return rb_set_capture_property(self, CV_CAP_PROP_FRAME_WIDTH, value);
}
|