Hi, i have a problem in
cvSnakeImage
function. 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
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
__forceinline void * __cdecl _heap_alloc (size_t size)
{
if (_crtheap == 0) {
_FF_MSGBANNER();
_NMSG_WRITE(_RT_CRT_NOTINIT);
__crtExitProcess(255);
}
return HeapAlloc(_crtheap, 0, size ? size : 1);
}
Any suggestions?
Supplementary from OP:
here is my full code...
#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);
}
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;
}