Ask Your Question

kenilworth's profile - activity

2017-09-28 06:12:47 -0600 received badge  Notable Question (source)
2016-03-19 12:38:07 -0600 received badge  Popular Question (source)
2014-09-05 15:20:38 -0600 commented question DescriptorExtractor::create() returns NULL pointer

Well, no. The binary I have is named opencv2.framework. I'm including header files from a directory named opencv2/. Additionally, that function is documented as belonging to v2.4.9.

2014-09-05 14:46:53 -0600 asked a question DescriptorExtractor::create() returns NULL pointer

I'm trying to instantiate a BRIEF Feature extractor:

cv::Ptr<cv::DescriptorExtractor> extractor = cv::DescriptorExtractor::create("BRIEF");

But the returned Ptr is empty (its owner and stored values are NULL).

Note that I have #include "opencv2/features2d/features2d.hpp" on the top of my code.

What's wrong?

2014-09-05 10:01:36 -0600 asked a question Mat leaking memory using Canny

I'm doing live video processing on iOS using OpenCV, without using CvVideoCamera. My app is crashing due to Memory Pressure.

The native iOS camera calls this function every time a frame is captured:

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection
{
    //convert the frame to a UIImage:
    UIImage *image = [self imageFromSampleBuffer:sampleBuffer];

    //convert the UIImage to a Mat:
    Mat srcMat = [self cvMatFromUIImage:image];

    //Process the Mat:
    Mat dst, cdst;
    Canny(srcMat, dst, 50, 200, 3);
    cvtColor(dst, cdst, COLOR_GRAY2BGR);
}

The app crashes about 15 seconds later due to memory pressure.

After some investigation, I found that the call to Canny() is responsible, but I can't figure out why...

It looks like the Mat objects are staying in memory, but aren't Mat objects released automatically?

2014-09-04 17:12:37 -0600 received badge  Editor (source)
2014-09-04 17:12:04 -0600 asked a question Mat memory leak on iOS

I'm trying to do live video processing on iOS, without using CvVideoCamera, and I'm having huge memory problems...

The native iOS camera calls this function everytime a frame is captured:

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection
{
    //convert the frame to a UIImage:
    UIImage *image = [self imageFromSampleBuffer:sampleBuffer];

    //convert the UIImage to a Mat:
    Mat imageMat = [self cvMatFromUIImage:image];

    //Process the Mat
    [self processImage:imageMat]; //<-- Problematic line

    //Create a UIImage from that Mat, and display it:
    UIImage *newImage = [self UIImageFromCVMat:imageMat];
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        imageView.image = newImage;
    }];
}

The app displays the processed image, but crashes about 15 seconds later due to memory pressure. I found that the call [self processImage:imageMat] is responsible for it, but I can't figure out why... It looks like Mat objects are leaking, but I thought aren't Mat objects released automatically?

-(void) processImage:(cv::Mat&)image {
    Mat src = image;

    Mat src_gray;
    int thresh = 80;
    RNG rng(12345);

    /// Convert image to gray and blur it
    cvtColor( src, src_gray, COLOR_BGR2GRAY );
    blur( src_gray, src_gray, cv::Size(3,3) );

    Mat canny_output;
    std::vector<std::vector<cv::Point> > contours;
    std::vector<Vec4i> hierarchy;

    /// Detect edges using canny
    Canny( src_gray, canny_output, thresh, thresh*2, 3 );
    /// Find contours
    findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );
    /// Draw contours
    Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
    for( int i = 0; i< contours.size(); i++ )
    {
        Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
        drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, cv::Point() );
    }

    image = canny_output;
}
2014-09-04 02:31:32 -0600 received badge  Student (source)
2014-09-03 16:37:05 -0600 asked a question NormalBayesClassifier classifier is an abstract class

I'm trying to figure out how to use the Normal Bayes Classifier as explained here.

Mat trainingData;
Mat trainingLabels;
Mat evalData;
Mat results;

cv::ml::NormalBayesClassifier classifier;
//Train classifier...
classifier.train(trainingData, trainingLabels);

//Evaluate classifier...
classifier.predict(evalData,&results);

But I get the following build error: cv::ml::NormalBayesClassifier classifier is an abstract class

I tried making a subclass of NormalBayesClassifier and using that instead but I didn't manage.. What am I doing wrong?

2014-08-25 12:17:33 -0600 received badge  Supporter (source)
2014-08-25 12:17:30 -0600 received badge  Scholar (source)
2014-08-25 11:19:27 -0600 asked a question color.cpp:3380: error: (-215) (scn == 3 || scn == 4) && depth == CV_8U in function cvtColor

Hi!

I'm completed the OpenCV iOS video processing tutorial, but I get this exception when running the completed app:

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/vp/work/opencv/modules/imgproc/src/color.cpp:3380: error: (-215) (scn == 3 || scn == 4) && depth == CV_8U in function cvtColor

The exception is thrown by this function:

- (void)processImage:(Mat&)image;
{
    // Do some OpenCV stuff with the image
    Mat image_copy;
    cvtColor(image, image_copy, COLOR_BGR2GRAY);

    //invert image
    bitwise_not(image_copy, image_copy);
    cvtColor(image_copy, image, COLOR_BGR2BGRA);
}

on the line cvtColor(image_copy, image, COLOR_BGR2BGRA);

What exactly is going on?