mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fix issue #22
Use Ruby's memory allocation function xmalloc() instead of OpenCV's cvAlloc() to run GC when running out of memory
This commit is contained in:
parent
20ba28b3bf
commit
21adfe1035
3 changed files with 67 additions and 61 deletions
|
@ -187,21 +187,25 @@ VALUE
|
|||
rb_retrieve(VALUE self)
|
||||
{
|
||||
VALUE image = Qnil;
|
||||
IplImage *frame = NULL;
|
||||
try {
|
||||
IplImage *frame = cvRetrieveFrame(CVCAPTURE(self));
|
||||
if (!frame)
|
||||
if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
|
||||
return Qnil;
|
||||
image = cIplImage::new_object(cvSize(frame->width, frame->height),
|
||||
CV_MAKETYPE(CV_8U, frame->nChannels));
|
||||
if (frame->origin == IPL_ORIGIN_TL)
|
||||
}
|
||||
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
|
||||
}
|
||||
else {
|
||||
cvFlip(frame, CVARR(image));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return image;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -214,16 +218,19 @@ VALUE
|
|||
rb_query(VALUE self)
|
||||
{
|
||||
VALUE image = Qnil;
|
||||
IplImage *frame = NULL;
|
||||
try {
|
||||
IplImage *frame = cvQueryFrame(CVCAPTURE(self));
|
||||
if (!frame)
|
||||
if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
|
||||
return Qnil;
|
||||
image = cIplImage::new_object(cvSize(frame->width, frame->height),
|
||||
CV_MAKETYPE(CV_8U, frame->nChannels));
|
||||
if (frame->origin == IPL_ORIGIN_TL)
|
||||
}
|
||||
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
|
||||
}
|
||||
else {
|
||||
cvFlip(frame, CVARR(image));
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue