cvFindContours() not working in OpenCV 2.3.1-Collection of common programming errors

I have been having some problems running my application on OpenCV 2.3.1. It works like a charm on OpenCV 2.1 but gives a run time error in OpenCV 2.3.1. OpenCV Error: Assertion failed in unknown function,

#include 
#include
#include 
#include 
#define MAXX_CONTOUR_AREA  200

CvMemStorage* storage=0;
CvSeq* lines;
CvSeq* lines1;
CvSeq* contours;
CvSeq* _contours;

void segment()
{

    IplImage *img = cvLoadImage("save.jpg",0);
    int height =img->height;
    IplImage *cnt_img = cvCreateImage( cvGetSize(img), 8, 3 );
    CvPoint* line;
    storage = cvCreateMemStorage(0); 
    //********************Find contours****************************************//       
int i=cvFindContours( img, storage, &contours, sizeof(CvContour),
       CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
lines1=contours;
_contours = contours;
void* element;
CvRect rect;
CvPoint p,p1,p2;
while(_contours->h_next!=NULL)  
{
_contours = _contours->h_next;
cvDrawContours( cnt_img, _contours, CV_RGB(0,255,0), CV_RGB(0,0,0), 7, 3, CV_AA, cvPoint(0,0));
rect=cvContourBoundingRect (_contours,0); 
//*****************Get the co-ordinates of the bounding rectangle***************//
p.x=(int)rect.x;
p.y=(int)rect.y;
p1.x=(int) rect.x+ (int) rect.width;
p1.y=(int) rect.y+ (int) rect.height;
p2.x=(p.x+p1.x)/2;
if((rect.height*rect.width)>=MAXX_CONTOUR_AREA)
{cvRectangle(cnt_img,p,p1,CV_RGB(255,255,255),1);
printf("\nCo-ordinates: (%d,%d)",(p.x+p1.x)/2,(p1.y+p.y)/2);
}
}
lines1=cvApproxChains(contours, storage, CV_CHAIN_APPROX_SIMPLE, 0, 0, 0);
cvSaveImage("saved.jpg",cnt_img);
}            


main()
{
IplImage *src=cvLoadImage("u.JPG",0); //-1-->color,0-->b&w
IplImage *dst = cvCreateImage( cvGetSize(src), 8, 1 );
cvCanny( src, dst, 150,200 , 3 );
cvSaveImage("save.jpg",dst);
//cvShowImage("Display",dst);
segment();
system("PAUSE");
}    

I am using DEV C++ with OpenCV 2.3.1 Earlier i was using OpenCV 2.1 with DEV C++.

Originally posted 2013-11-06 03:31:08.