[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


OpenCV, c++ problem

Posted on 2010-08-12
Medium Priority
Last Modified: 2012-08-14
Hello experts!

I am C++ and OpenCV newbie.

Please have a look at the attached image.

This is my code:

int _tmain(int argc, _TCHAR* argv[])
              IplImage* src;

      IplImage* dst = cvCreateImage(cvGetSize(src), 8, 1);
      IplImage* color_dst = cvCreateImage(cvGetSize(src), 8, 3);
      CvMemStorage* storage = cvCreateMemStorage(0);
      CvSeq* lines = 0;

      int i;
      cvCanny(src, dst, 50, 200, 3); //<- program crashes inside this method

      cvCvtColor(dst, color_dst, CV_GRAY2BGR);

      lines = cvHoughLines2(dst,      storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80, 30, 10);

      for( i = 0; i < lines->total; i++)
            CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
            cvLine(color_dst, line[0], line[1], CV_RGB(255,0,0), 3, 8);

      cvNamedWindow("Source", 1);
      cvShowImage("Source", src);
      cvNamedWindow("Hough", 1);
      cvShowImage("Hough", color_dst);



Any ideas? For me it looks like program crashed inside dll library, maybe dll contains bug?

Thank you

Question by:panJames
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 20

Expert Comment

ID: 33421692
Just press the "Break" button in the dialog that you posted, then the debugger will jump to the code-line where the crash occured.
LVL 20

Expert Comment

ID: 33421715
Most likely "pic1.bmp" cant be found.
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 33421733
Well, it's not a crash, it's a diagnotic exception raised by OpenCV telling you that there's something wrong with the parameters you are passing to 'cvCanny()' (or 'cvSobel()' respectively, which is called by that function) - here it is that the number of color channels does not seem to match both the source and destination image ('src.channels() == dst.channels()' in your console window).
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 33424139
ikework: -> it can find the image

jkr:it may be the reason. I will try different images.

LVL 86

Expert Comment

ID: 33424200
Try specifying compatible parameters with 'cvCreateImage()'.

Author Comment

ID: 33429087
In "Learning OpenCV" I found that I need 8bit image. And according to IrfanView I actually use such file (8 bitsperpixel).

Still I get errors as you can see on attached image.

Any ideas?



Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question