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

  • SEARCH
  • Home
  • 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 7446769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:24:19+00:00 2026-05-29T12:24:19+00:00

I am tryint to read an image with OpenCV 2.1 (started just today), C++

  • 0

I am tryint to read an image with OpenCV 2.1 (started just today), C++ using the code below.
I can not see what is the problem in the following. Thank you if you can provide some help.

int main( int argc, char** argv )
{
int height,width,step,channels;

//Load the image and make sure that it loads correctly
IplImage* im = cvLoadImage("kermit.jpg", 1); 
if(!im )
{
    //Drop out if the image isn't found
    cout << "Failed to load: "<<"kermit.jpg"<<"\n";
return 0;
}
else
{
    cout<<"Image was loaded with success "<<"kermit.jpg"<<"\n";
return (0);
}

height=im->height;
width=im->width;
step=im->widthStep;
channels=im->nChannels;

cout<<"(height, width)"<<height<<width<<"\n";


cvNamedWindow("kermit.jpj",CV_WINDOW_AUTOSIZE);

cvShowImage( "kermit.jpg", im );
cvWaitKey(0);
cvDestroyWindow ("kermit.jpg");

return 0;
}
  • 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-29T12:24:21+00:00Added an answer on May 29, 2026 at 12:24 pm

    Since you didn’t tell us what the problem really is, I want to point out the following code:

    if(!im )
    {
        //Drop out if the image isn't found
        cout << "Failed to load: "<<"kermit.jpg"<<"\n";
        return 0;
    }
    else
    {
        cout<<"Image was loaded with success "<<"kermit.jpg"<<"\n";
        return (0);
    }
    

    This means that if the loading fails you quit the application, and if the loading succeeds, you also quit. Sounds wrong, right? You shouldn’t return on success.

    You don’t need the else block, so please remove it and try again. The rest of the code seems to be OK.

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

Sidebar

Related Questions

I'm trying to display an image using OpenCV. I have the following very basic
I am trying to parallelize some Image Matching code written in OpenCV using TBB.
I'm trying to read a TIFF image from file using BufferedImage. The following is
Trying to read an RSS and select information using Linq but can't seem to
I have this code where I am trying to read an image from Url:
I'm very new to OpenCV (started using it two days ago), I'm trying to
Im trying to read in image file from a server , with the code
I'm trying to read an image from the net using ImageIO: URL url =
Hey trying to read stream into image control can any one help also I
I am trying to detect solid circles using opencv. The example code from 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.