Ask Your Question
-1

OpenCV Error: Assertion failed (std::abs(dsize.width*2 - ssize.width) <= 2

asked 2015-03-22 03:30:18 -0600

M.A gravatar image

updated 2015-03-22 03:34:05 -0600

berak gravatar image

Please help me with this. I am working on Opencv as beginner.I am using Dev C++ please help me with this error Message" OpenCV Error: Assertion failed (std::abs(dsize.width*2 - ssize.width) <= 2

&& st d::abs(dsize.height*2 - ssize.height) <= 2) in pyrDown_, file C:\User\VP

\ocv\ope ncv\src\cv\cvpyramids.cpp, line 206

This application has requested the Runtime to terminate it in an unusual

way. Please contact the application's support team for more information.


Process exited with return value 3 Press any key to continue . . ." ....

My written code is here :

#include <cv.h>
#include<highgui.h>


//..........Rosenfeld80.................


IplImage* doPyrDown(IplImage *in,int filter= IPL_GAUSSIAN_5x5){
    //make sure that input image is divisible by two using
    assert(((int)in->width) % 2==0 && ((int)in->height) % 2==0);
    IplImage *out=cvCreateImage(cvSize(in->depth/2,in->height/2),in->depth,in->nChannels);
    cvPyrDown(in,out);
    return (out);
}


//..........Canny edge detector [Canny86]............


IplImage * doCanny(IplImage* in, double lowThresh, double highThresh, double aperture){
     if(in->nChannels !=1)// Canny works only with gray scale images
         return 0;      
     IplImage *out=cvCreateImage(cvGetSize(in),IPL_DEPTH_8U,1);
     cvCanny( in, out, lowThresh, highThresh, aperture );
     return (out);          
}



int main(int argc,char **argv){
IplImage* out;
IplImage* in=cvLoadImage("E:/Arshad/OpenCv/OpenCv Work/Penguins.jpg");
cvNamedWindow("Input",CV_WINDOW_AUTOSIZE);
cvShowImage("Input",in);
out =doPyrDown( in, IPL_GAUSSIAN_5x5 );
cvNamedWindow("doPyramidDown",CV_WINDOW_AUTOSIZE);
cvShowImage("doPyramidDown",out);
out = doPyrDown( out, IPL_GAUSSIAN_5x5 );
out = doCanny( out, 10, 100, 3 );
cvNamedWindow("doCanny",CV_WINDOW_AUTOSIZE);
cvShowImage("doCanny",out);
cvWaitKey(0);
cvReleaseImage(&out);
cvDestroyWindow("Input");
cvDestroyWindow("doPyramidDown");
cvDestroyWindow("doCanny");

}
edit retag flag offensive close merge delete

Comments

1

first of all: please DO NOT use opencv's legacy C-api. this is a dead end.

berak gravatar imageberak ( 2015-03-22 03:35:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-03-22 03:42:23 -0600

berak gravatar image

updated 2015-03-22 03:50:06 -0600

please use opencv's c++ api, you also will only need half the code:

#include <opencv2/opencv.hpp> // c++ headers
using namespace cv;

#include <iostream>
using namespace std;

int main(int argc, char **argv)
{

    Mat in=imread("E:/Arshad/OpenCv/OpenCv Work/Penguins.jpg");
    if ( in.empty() )
    { 
        cerr << "image was not found !" << endl;
        return -1; 
    }
    namedWindow("Input",CV_WINDOW_AUTOSIZE);
    imshow("Input",in);
    Mat out;  // no need to pre-allocate or release a cv::Mat manually
    pyrDown(in, out);
    namedWindow("doPyramidDown",CV_WINDOW_AUTOSIZE);
    imshow("doPyramidDown",out);
    pyrDown(out, out);
    cvtColor(out, out, CV_BGR2GRAY);  // make it grayscale for canny
    Canny(out, out, 10, 100, 3);
    namedWindow("doCanny",CV_WINDOW_AUTOSIZE);
    imshow("doCanny",out);
    waitKey(0);
    return 0;
}
edit flag offensive delete link more

Comments

Sir I have to work in C not c++ please help me with this problem I am using Dev C++ IDE. Please tell me how can I get ride of this problem?

M.A gravatar imageM.A ( 2015-03-22 03:50:31 -0600 )edit
1

"I have to work in C" - then do not use opencv.

berak gravatar imageberak ( 2015-03-22 03:59:49 -0600 )edit

sir please then re write it for me in c++

M.A gravatar imageM.A ( 2015-03-22 04:17:33 -0600 )edit
1

hey, just look above !

berak gravatar imageberak ( 2015-03-22 04:23:45 -0600 )edit

Sir in this you have used visual studio or something else?

M.A gravatar imageM.A ( 2015-03-22 04:41:08 -0600 )edit
1

The example is not visual studio only, Perhabs the header include is the OpenCV 3 one. Try #include <opencv2/opencv/opencv.hpp> or #include <opencv2/core/core.hpp>, #include <opencv2/imgproc/imgproc.hpp> and #include <opencv2/highgui/highgui.hpp>, but I'm not sure about the OpenCV 2 header includings

matman gravatar imagematman ( 2015-03-22 12:44:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-03-22 03:30:18 -0600

Seen: 3,024 times

Last updated: Mar 22 '15