Hi thanks commontater,
Can you please explain further how to use the simpler method please?
Code:
/*This function will take an input image from a webcam and apply FAST corner detection
algorithm so to find the corners in the image.*/
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#include <stdlib.h>
#include "stdbool.h"
#define start_tree 17
#define stop_tree 18
#define corner 19
#define not_corner 20
#define frame_width 640
#define frame_height 480
//This stucture will be used as the template node of the FAST tree
struct tree_node {
int pixel;
struct tree_node *parent;
struct tree_node *brighter;
struct tree_node *similar;
struct tree_node *darker;
};
//global variables
struct tree_node *root_node;//root node of the tree
struct tree_node *current_node; //root node of the tree
FILE *file_pointer; //pointer to the file 'FAST_tree_array.txt'
IplImage *frame_ = 0; //Grayscale frame
int counter = 3;
//function prototypes here
void load_tree(void);
void load_tree_recursively(void);
void FAST_corner_detector();
void ummy(void);
//main function begins here
int main(void)
{
int data= 0;
//Initialize camera using the OpenCV library
CvCapture *capture = 0;
IplImage *frame = 0; //RGB frame
//IplImage *frame_ = 0; //Grayscale frame
capture = cvCaptureFromCAM(0);
//check whether camera initialised correctly
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
//create a window for the captured image
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
//First thing to do is to setup the FAST tree structure.
//'root_node' is the first node of the tree.
load_tree();
//Pre-processing settings
frame = cvQueryFrame( capture );
frame_ = cvCreateImage( cvSize( frame_width, frame_height ), IPL_DEPTH_8U, 1 ); //This matrix will hold the grayscale version of
//the input frame
//Process camera frames until escape button is pressed
while(1){
//capture frame
frame = cvQueryFrame( capture );
cvCvtColor(frame,frame_,CV_RGB2GRAY);
//Extract Corners
ummy();
ummy();
FAST_corner_detector();
//print frame
cvShowImage( "result", frame_);
//Break is Esc button is pressed
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
return 0;
}
//This function will convert the text file 'FAST_tree_array.txt' to a data structure of
//tree_node.
void load_tree(void)
{
int data = 0;
root_node = (struct tree_node *)malloc(sizeof(struct tree_node)); //allocate memory to the tree
current_node = (struct tree_node *)malloc(sizeof(struct tree_node)); //allocate memory to the tree
//check that file exists
if((file_pointer = fopen ("FAST_tree_array.txt", "rt")) == NULL){
printf("Filecould not be found \n");
}
else{
data = read_file(); //read first value
//Initial test
if(data<=16){ //load tree only if non trivial case
current_node = root_node; //copy pointer
current_node->pixel = data;
data = read_file(); //dummy read start_tree
counter = 0;
counter = counter + 1;
printf("%d\n",counter);
load_tree_recursively();
printf("%d\n",counter);
}
else{
root_node->pixel = data; //trivial case, when all training set image pixels are corners or non corners.
}
fclose(file_pointer);
}
}
//This function will recursively create the tree structure of tree_nodes'
void load_tree_recursively(void){
int dummy, data;
int section =1; //this variable will record the status of the operation
//1 = brighter, 2 = similar, 3 = darker.
struct tree_node *temp_node; //will temporary hold a pointer to the current tree node
while(1){
temp_node = current_node; //keep record of mother node address
switch(section)
{
case 1: //brighter
current_node -> brighter = (struct tree_node *)malloc(sizeof(struct tree_node));
current_node = current_node->brighter;
current_node -> parent = temp_node;
break;
case 2: //similar
current_node -> similar = (struct tree_node *)malloc(sizeof(struct tree_node));
current_node = current_node->similar;
current_node -> parent = temp_node;
break;
case 3: //darker
current_node -> darker = (struct tree_node *)malloc(sizeof(struct tree_node));
current_node = current_node->darker;
current_node -> parent = temp_node;
break;
case 4: //finished processing subtree therefore return from recursive call
current_node = current_node->parent; //go back one tree node
data = read_file();
counter = counter - 1;
printf("%d\n",counter);
return;
}
data = read_file(); //read first value
if(data<=16){
current_node -> pixel = data; //update tree
data = read_file(); //dummy read start_tree
counter = counter + 1;
printf("%d\n",counter);
load_tree_recursively(); //recursive call
printf("%d\n",counter);
section = section + 1;
}
else if(data == corner){
current_node -> pixel = corner;
current_node = current_node->parent;
section = section + 1;
}
else if(data == not_corner){
current_node -> pixel = not_corner;
current_node = current_node->parent;
section = section + 1;
}
}
}
int read_file(void){
//Reads an element from the text file pointed to by the global pointer 'file_pointer'
//sequentially
char string[2] = {0,0}; //will hold data from file, max sequence is 1 9
int string_counter = 0;
char temp = 'a';
int result = 0;
while(1){
fread(&temp,sizeof(temp),1,file_pointer);
if(temp != ','){
if(string_counter == 0){
string[0] = temp;
string_counter = string_counter + 1;
}
else{
string[1] = temp;
string_counter = 0;
}
}
else{
break;
}
}
//convert string to integer
result = atoi(string);
return result;
}
void FAST_corner_detector()
{
//This function will be used to extract corners from 'image' using the FAST tree.
int row=1,column=1;
uchar* data = (uchar *)frame_->imageData;
int pixel_value;
int hey[480][640] ={0};
//bool corner_image[frame_height][frame_width] = {false};
for(row=0;row<frame_height;row++){
for(column=0;column<frame_height;column++){
pixel_value = data[row*(frame_ ->widthStep) + column];
hey[row][column] = pixel_value;
printf("%d \n",pixel_value);
//uchar* data = (uchar *)(image->imageData + row*(image ->widthStep) + column);
}
}
cvShowImage( "result", hey);
}
void ummy(void){
printf("heyyy");
}
The code is shown above. the function load tree() is a recursive loop to build a tree.. When I process load_tree() it functions correctly. When I then process the dummy function ummy() there is no problem also...but as soon as i process the next function "FAST_corner_detector" the debugger goes into chkstk.asm and breaks there saying "Unhandled exception at 0x00cf2157 in run_FAST_corner_detection.exe: 0xC0000005: Access violation reading location 0x000f0000."...
Thanks for anybody's help in advance