Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi, i have a problem in cvSnakeImagefunction. i have written small code for draw active contour among an image..but when i run the code it exists when execute the cvSnakeImag() function...Need Help

C++
void AactiveSnake(IplImage* image)
{

    points  = (CvPoint*)cvAlloc(15*sizeof(CvPoint*));
     int x,y;
    for(int i = 0;i < 14 ; i++){
                 x =  Xvalues[i];
                 y =  Yvalues[i];
                 points[i].x = x;
                 points[i].y = y;
    }

    cvSnakeImage(image,points,15,&Alfa,&Beta,&Gamma,CV_VALUE,win,criteria,0);

}



i get points when user clicks on the image and store them in an array...code works until i call the cvSnakeImage fucntion...when i execute it

Windows has triggered a breakpoint in MCodeToCV.exe.

This may be due to a corruption of the heap, which indicates a bug in MCodeToCV.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while MCodeToCV.exe has focus.

The output window may have more diagnostic information.


displayed and VS2010 opens malloc.c and pointed to

C++
__forceinline void * __cdecl _heap_alloc (size_t size)

{

    if (_crtheap == 0) {
        _FF_MSGBANNER();    /* write run-time error banner */
        _NMSG_WRITE(_RT_CRT_NOTINIT);  /* write message */
        __crtExitProcess(255);  /* normally _exit(255) */
    }

    return HeapAlloc(_crtheap, 0, size ? size : 1);
}


Any suggestions?


Supplementary from OP:

here is my full code...

C++
// MCodeToCV.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2\legacy\legacy.hpp"
#include <string>
#include <sstream>

void connect_points(IplImage* img,int x,int y,int x1,int y1);
void my_mouse_callback( int event, int x, int y, int flags, void* param );
void AactiveSnake(IplImage* image);

int xC,yC;
int *Xvalues = new int[15];
int *Yvalues = new int[15];
int count = 0;
bool drawing_box = false;
bool val = false;

float sigma = 1.00;
float Alfa ;
float Beta ;
float Gamma ;
float* Kappa;
float W_Eline = 0.30;
float W_Edge = 0.40;
float W_Eterm = 0.70;
CvPoint* points = new CvPoint[15];
CvSize win;
CvTermCriteria criteria;

void draw_box( IplImage* img, int x,int y ){
	
	 cvCircle(img,cvPoint(x,y),1,CV_RGB(0,255,0),-1);
	 Xvalues[count] = x;
	 Yvalues[count] = y;
	 count++;
	 drawing_box = false;
}

void assign(int i,IplImage* image)
{
    int x,y,x1,y1;
    x =  Xvalues[i];
    y =  Yvalues[i];
    x1 =  Xvalues[i + 1];
    y1 =  Yvalues[i + 1];
    connect_points(image,x,y,x1,y1);
    
    if(i+1 == 14)
    {
        connect_points(image,Xvalues[0],Yvalues[0],Xvalues[14],Yvalues[14]);
    }
}

void AactiveSnake(IplImage* image)
{
	
    points  = (CvPoint*)cvAlloc(15*sizeof(CvPoint*));
    int x,y;
    for(int i = 0;i < 14 ; i++){	
        x =  Xvalues[i];
        y =  Yvalues[i];
        points[i].x = x;
        points[i].y = y;
    }
    
    cvSnakeImage(image,points,15,&Alfa,&Beta,&Gamma,CV_VALUE,win,criteria,0);
    
}


void connect_points(IplImage* img,int x,int y,int x1,int y1)
{
    cvLine(img, cvPoint(x,y), cvPoint(x1,y1), CV_RGB(255,0,0), 1, 8, 0);
}
// Implement mouse callback
void my_mouse_callback( int event, int x, int y, int flags, void* param ){
	IplImage* image = (IplImage*) param;

    switch( event ){
    
    case CV_EVENT_LBUTTONDOWN:
        drawing_box = true;
        xC = x;
        yC = y;
        break;
        
    case CV_EVENT_RBUTTONDOWN:
         drawing_box = false;
         for(int i = 0; i<14; i++)
         {
            assign(i,image);
         }
         val = true;
        break;
        }
}

int _tmain(int argc, _TCHAR* argv[])
{
    const char* name = "Box Example";
    
    win.width = 9;
    win.height = 9;
    
    criteria.type = 1;
    criteria.max_iter = 200;
    
    Alfa = 0.40;
    Beta = 0.20;
    Gamma = 1.00;
    IplImage* image = cvLoadImage( "bb.jpg" );
    
    cvSmooth(image,image,2,3,0,1.0,0.0);
    cvNamedWindow(name);
    
    
    cvSetMouseCallback( name, my_mouse_callback, (void*) image);
    
    
    while( 1 ){
    
        if( drawing_box ) 
        {
            draw_box( image, xC,yC );
        
        }
        
        else if( val)
        {
        
        }
        cvShowImage( name, image );
        
        char key = cvWaitKey(25);
        char value;
        
        
        if( key == 'k')
        {
            AactiveSnake(image);    
        }
        
        
        if( cvWaitKey( 15 )==27 ) 
            break;
    }
    
    cvReleaseImage( &image );
    cvDestroyWindow( name );
    cvFree_(&Alfa);
    cvFree_(&Beta);
    cvFree_(&Gamma);
    cvFree_(&points);
    return 0;
}
Posted
Updated 4-Mar-13 5:27am
v4
Comments
Richard MacCutchan 2-Mar-13 11:33am    
Without seeing the code for the cvSnakeImage function it's impossible to guess what you are doing.
Dilan Shaminda 4-Mar-13 8:23am    
hi i have posted my code blowe....could you plz help me? thank you
Dilan Shaminda 2-Mar-13 11:37am    
here is my full code...

// MCodeToCV.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2\legacy\legacy.hpp"
#include <string>
#include <sstream>

void connect_points(IplImage* img,int x,int y,int x1,int y1);
void my_mouse_callback( int event, int x, int y, int flags, void* param );
void AactiveSnake(IplImage* image);

int xC,yC;
int *Xvalues = new int[15];
int *Yvalues = new int[15];
int count = 0;
bool drawing_box = false;
bool val = false;

float sigma = 1.00;
float Alfa ;
float Beta ;
float Gamma ;
float* Kappa;
float W_Eline = 0.30;
float W_Edge = 0.40;
float W_Eterm = 0.70;
CvPoint* points = new CvPoint[15];
CvSize win;
CvTermCriteria criteria;

void draw_box( IplImage* img, int x,int y ){

cvCircle(img,cvPoint(x,y),1,CV_RGB(0,255,0),-1);
Xvalues[count] = x;
Yvalues[count] = y;
count++;
drawing_box = false;
}

void assign(int i,IplImage* image)
{
int x,y,x1,y1;
x = Xvalues[i];
y = Yvalues[i];
x1 = Xvalues[i + 1];
y1 = Yvalues[i + 1];
connect_points(image,x,y,x1,y1);

if(i+1 == 14)
{
connect_points(image,Xvalues[0],Yvalues[0],Xvalues[14],Yvalues[14]);
}
}

void AactiveSnake(IplImage* image)
{

points = (CvPoint*)cvAlloc(15*sizeof(CvPoint*));
int x,y;
for(int i = 0;i < 14 ; i++){
x = Xvalues[i];
y = Yvalues[i];
points[i].x = x;
points[i].y = y;
}

cvSnakeImage(image,points,15,&Alfa,&Beta,&Gamma,CV_VALUE,win,criteria,0);

}


void connect_points(IplImage* img,int x,int y,int x1,int y1)
{
cvLine(img, cvPoint(x,y), cvPoint(x1,y1), CV_RGB(255,0,0), 1, 8, 0);
}
// Implement mouse callback
void my_mouse_callback( int event, int x, int y, int flags, void* param ){
IplImage* image = (IplImage*) param;

switch( event ){

case CV_EVENT_LBUTTONDOWN:
drawing_box = true;
xC = x;
yC = y;
break;

case CV_EVENT_RBUTTONDOWN:
drawing_box = false;
for(int i = 0; i<14; i++)
{
assign(i,image);
}
val = true;
break;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
const char* name = "Box Example";

win.width = 9;
win.height = 9;

criteria.type = 1;
criteria.max_iter = 200;

Alfa = 0.40;
Beta = 0.20;
Gamma = 1.00;
IplImage* image = cvLoadImage( "bb.jpg" );

cvSmooth(image,image,2,3,0,1.0,0.0);
cvNamedWindow(name);


cvSetMouseCallback( name, my_mouse_callback, (void*) image);


while( 1 ){

if( drawing_box )
{
draw_box( image, xC,yC );

}

else if( val)
{

}
cvShowImage( name, image );

char key = cvWaitKey(25);
char value;


if( key == 'k')
{

AactiveSnake(image);


}


if( cvWaitKey( 15 )==27 )
break;
}



cvReleaseImage( &image );
cvDestroyWindow( name );
cvFree_(&Alfa);
cvFree_(&Beta);
cvFree_(&Gamma);
cvFree_(&points);
return 0;
}
Dilan Shaminda 2-Mar-13 11:45am    
here user can mark 15 points and after right click program will draw line connecting those points...it works..but i want do execute cvSnakeImage function as well...Thank you
Richard MacCutchan 4-Mar-13 9:15am    
I don't see any declaration of cvSnakeImage, so no idea what it may do. You really need to spend some time with your debugger and capture some useful information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900