Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4091570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:23:01+00:00 2026-05-20T19:23:01+00:00

Apparently, this code gives me error at the last line cvCvtColor(), what is wrong?

  • 0

Apparently, this code gives me error at the last line cvCvtColor(), what is wrong? Is there anything that can be improved in this function?

+(IplImage*) LoadPbmAsIplImage: (NSString*) fileName{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pbm"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSArray *lines = [content componentsSeparatedByString:@"\n"];
    NSString *secondLine = [lines objectAtIndex:1]; //because first line (index 0) contains meta data
    int width = [secondLine length];
    int height = [lines count]-1;
    Mat *mat = new Mat(width, height, CV_8UC4);
    MatIterator_<uint> it = mat->begin<uint>();
    for (int i=0; i<[lines count]; i++){
        for (int j=0; j<[[lines objectAtIndex:i] length]; j++){
            int pixelValue = 0;
            if ([[lines objectAtIndex:i] characterAtIndex:j] == '1'){
                pixelValue = 255;
            }
            *it = pixelValue;
        }
    }
    IplImage iplImage = *mat;
    IplImage* rv = cvCreateImage(cvSize(iplImage.width, iplImage.height), IPL_DEPTH_8U, 3);
    cvCvtColor(mat, rv, CV_RGBA2BGR);
    return rv;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:23:02+00:00Added an answer on May 20, 2026 at 7:23 pm

    You mix the C++ interface (cv::Mat) with the C interface (IplImage), why do you do that?

    Mat *mat = new Mat(width, height, CV_8UC4);
    

    This is a memory leak, you never delete that map, also there’s almost no reason to create a Mat with new – just Mat mat(width, height, CV_8UC4) does the job fine, and you don’t need to delete it.

    cvCvtColor(mat, rv, CV_RGBA2BGR);
    

    cvCvtColor expects two IplImage*s as arguments, you give it a cv::Mat* and an IplImage*, this can’t work. Replace the first mat with &iplImage, or just consistently use the c++ interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm porting some code from lisp, but I got stuck at this part (apparently
SQL Server a stored procedure written in C# on the .NET 2.0 framework that
I use the latest version of numpy/scipy. The following script does not work: import
I'm converting a D2006 program to D2010. I have a value stored in a
I was turned on to nstrees from another question, and have been working through
Alright, so I've been doing some poking around, and I realize my problem, but
Ok, I have a question relating to an issue I've previously had. I know
class A { public: A(const int n_); A(const A& that_); A& operator=(const A& that_);
I'm trying to debug and resolve some issues with a Win32 macro application written
I am trying to convert compressed swf files to uncompressed swf files using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.