Class: OpenCV::CvVideoWriter
- Inherits:
-
Object
- Object
- OpenCV::CvVideoWriter
- Defined in:
- ext/opencv/cvvideowriter.cpp,
ext/opencv/cvvideowriter.cpp
Overview
Create video stream from images.
C structure is “black box”.
Instance Method Summary collapse
-
#close ⇒ Object
Close vidoe writer.
-
#initialize(*args) ⇒ Object
constructor
Open new video writer.
-
#write(frame) ⇒ Object
Write image as frame of video stream.
Constructor Details
#new(filname, fourcc, fps, size[, is_color]) ⇒ Object #new(filname, fourcc, fps, size[, is_color]) {|vw| ... } ⇒ nil
Open new video writer. If block given, writer is closed automatically when end of block.
note: if fourcc is nil, popup codec select dialog (Windows only).
38 39 40 41 42 43 44 45 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 79 80 |
# File 'ext/opencv/cvvideowriter.cpp', line 38
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE filename, fourcc, fps, size, is_color_val;
rb_scan_args(argc, argv, "41", &filename, &fourcc, &fps, &size, &is_color_val);
char codec[4] = {' ', ' ', ' ', ' '};
int codec_number;
Check_Type(filename, T_STRING);
if (RSTRING_LEN(filename) == 0)
rb_raise(rb_eArgError, "argument 1 (file name) dose not given");
if (NIL_P(fourcc))
codec_number = -1;
else {
Check_Type(fourcc, T_STRING);
if (RSTRING_LEN(fourcc) > 4)
rb_raise(rb_eStandardError, "argument 2 (fourcc) should be specific 4-character. (i.e \"PIM1\",\"MJPG\")");
else {
int len = RSTRING_LEN(fourcc);
for (int i = 0; i < len; ++i)
codec[i] = RSTRING_PTR(fourcc)[i];
codec_number = CV_FOURCC(codec[0], codec[1], codec[2], codec[3]);
}
}
int is_color;
if (NIL_P(is_color_val))
is_color = 1;
else
is_color = (is_color_val == Qtrue) ? 1 : 0;
try {
DATA_PTR(self) = cvCreateVideoWriter(StringValueCStr(filename), codec_number,
NUM2DBL(fps), VALUE_TO_CVSIZE(size), is_color);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
if (rb_block_given_p()) {
rb_yield(self);
rb_close(self);
return Qnil;
}
else
return self;
}
|
Instance Method Details
#close ⇒ Object
Close vidoe writer.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/opencv/cvvideowriter.cpp', line 104
VALUE
rb_close(VALUE self)
{
CvVideoWriter *writer = CVVIDEOWRITER(self);
try {
if (writer)
cvReleaseVideoWriter(&writer);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return Qnil;
}
|
#write(frame) ⇒ Object
Write image as frame of video stream. frame should be IplImage
89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/opencv/cvvideowriter.cpp', line 89
VALUE
rb_write(VALUE self, VALUE frame)
{
try {
cvWriteFrame(CVVIDEOWRITER(self), IPLIMAGE_WITH_CHECK(frame));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|