Progress report 10

March 31, 2010

Last week and this week, we worked on making real life models of the marker with thin dowel sticks and painted Styrofoam spheres taken from a molecular modeling kit. Through various experimentation with different combinations of sphere sizes, we have determined the physical difference in sphere sizes necessary for the camera to accurately detect the marker. We are currently discussing some of the downscaling issues as we try to apply our large model to our current problem.

As you can see from the powerpoint presentation presented last Wednesday, extensive work has been done on researching the surgical process of a total knee arthroplasty or a TKA. Several videos of surgeries have been viewed and a schematic of the surgery has been thoroughly integrated into our step-by-step block diagram of how the entire visual recognition system works.

So far, we have been running some statistical analysis on the camera and the marker. We attached the camera in a fixed position, with the marker in the straight-on orientation. We collected about 180 data entries and exported them into Excel. We found that the average angle to be 92.1 degrees with a standard deviation of 10.6 degrees. The relatively large standard deviation is due to bad lighting condition. Better testing condition will be implemented in later testing.

We have also done some reorganization of our website and we are running into some technical difficulties with the computers in the computer lab. Thus, we have been unable to upload the this progress report and the last one as well as our last powerpoint presentation. We hope this problem will be fixed soon.

The poster and final papers have been started. We are in the process of gathering information about the history of computer navigation systems in surgery aids so that we can do a more accurate comparison in our report and final poster of the Praxim system vs. what we are proposing to do.

Code:

#include"stdafx.h"

#include"math.h"

#include<stdio.h>

#include"cv.h"

#include"highgui.h"

#define PI 3.14159265

//Initiate some variables;

intkey;

intthresh=100;

CvMemStorage*storage=NULL;

CvSeq*contour=0;

CvSeq*lines = 0;

inti= 2;

CvFileStorage* fs = cvOpenFileStorage("result1.xml",0,CV_STORAGE_WRITE);

int _tmain(int argc, _TCHAR* argv[])

{

CvCapture* capture1 = cvCaptureFromCAM(0);

storage = cvCreateMemStorage(0);

// WebCAM 1 frame width,height 320x240

int x= 320;

int y= 240;

cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_WIDTH, x);

cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_HEIGHT, y);

//cvSetCaptureProperty(capture2, CV_CAP_PROP_FRAME_WIDTH, x);

//cvSetCaptureProperty(capture2, CV_CAP_PROP_FRAME_HEIGHT, y);

IplImage* frame1 = cvQueryFrame( capture1 );

IplImage* out1 = 0 ;

IplImage* img = cvCreateImage(cvSize(frame1->width,frame1->height ), frame1->depth,1);

IplImage* edge = cvCreateImage(cvGetSize(frame1),IPL_DEPTH_8U, 1);

IplImage* ds_lines = cvCreateImage(cvGetSize(frame1),IPL_DEPTH_8U, 3);

// now into While-Loop

while( key != 27)

{

frame1 = cvQueryFrame( capture1 );

cvCvtColor(frame1, img, CV_BGR2GRAY); //Change from Color to Grayscale

cvSmooth(img, img, CV_GAUSSIAN, 3);

cvCanny(img, edge, 160, 200);

//cvCvtColor(edge,ds_lines,CV_GRAY2BGR);

ds_lines=cvCloneImage(frame1);

lines = cvHoughCircles(edge,storage,CV_HOUGH_GRADIENT,2, 50, 100, 100, 0, 0);

if (lines->total == 4)

{

{

float* line1 = (float*)cvGetSeqElem(lines,1);

float* line2 = (float*)cvGetSeqElem(lines,2);

float* line3 = (float*)cvGetSeqElem(lines,3);

float* line4 = (float*)cvGetSeqElem(lines,4);

CvPoint pt1 =cvPoint(cvRound(line1[0]),cvRound(line1[1]) );

CvPoint pt2 =cvPoint(cvRound(line2[0]),cvRound(line2[1]) );

CvPoint pt3 =cvPoint(cvRound(line3[0]),cvRound(line3[1]) );

CvPoint pt4 =cvPoint(cvRound(line4[0]),cvRound(line4[1]) );

cvCircle( ds_lines, pt1, line1[2], CV_RGB(255,0,0), 1, 8 );

cvCircle( ds_lines, pt2, line2[2], CV_RGB(255,0,0), 1, 8 );

cvCircle( ds_lines, pt3, line3[2], CV_RGB(255,0,0), 1, 8 );

cvCircle( ds_lines, pt4, line4[2], CV_RGB(255,0,0), 1, 8 );

float length1;

float length2;

float A, B, C;

float degrees;

if (line3[2]/line4[2]<=1.2 & line3[2]/line4[2]>=0.83)

{

cvLine(ds_lines,pt1,pt2,CV_RGB(0,255,0),1,8);

cvLine(ds_lines,pt3,pt4,CV_RGB(0,255,0),1,8);

length1 = sqrt((line3[0]-line4[0])*(line3[0]-line4[0])+(line3[1]-line4[1])*(line3[1]-line4[1]));

length2 = sqrt((line1[0]-line2[0])*(line1[0]-line2[0])+(line1[1]-line2[1])*(line1[1]-line2[1]));

A= length1/2;

B= length2/2;

C= sqrt((line1[0]-line3[0])*(line1[0]-line3[0])+(line1[1]-line3[1])*(line1[1]-line3[1]));

degrees= acos((A*A+B*B-C*C)/(2*A*B))*180/PI;

printf("Radius %f \n",line3[2]/line4[2]);

if (length1>length2){

printf("Length Big %f \n", length1);

printf("Length Small %f \n", length2);

cvWriteReal(fs,"lengthbig",length1);

cvWriteReal(fs,"lengthsmall",length2);

}

else{

printf("Length Big %f \n", length2);

printf("Length Small %f \n", length1);

cvWriteReal(fs,"lengthbig",length2);

cvWriteReal(fs,"lengthsmall",length1);

}

printf("length C is %f \n",C);

printf("Degrees is %f \n \n",degrees);

cvWriteReal(fs,"degrees",degrees);

}

elseif (line2[2]/line4[2]<=1.2 & line2[2]/line4[2] >= 0.83)

{

cvLine(ds_lines,pt1,pt3,CV_RGB(0,255,0),1,8);

cvLine(ds_lines,pt2,pt4,CV_RGB(0,255,0),1,8);

length1 = sqrt((line2[0]-line4[0])*(line2[0]-line4[0])+(line2[1]-line4[1])*(line2[1]-line4[1]));

length2 = sqrt((line1[0]-line3[0])*(line1[0]-line3[0])+(line1[1]-line3[1])*(line1[1]-line3[1]));

A= length1/2;

B= length2/2;

C= sqrt((line4[0]-line3[0])*(line4[0]-line3[0])+(line4[1]-line3[1])*(line4[1]-line3[1]));

degrees= acos((A*A+B*B-C*C)/(2*A*B))*180/PI;

printf("Radius %f \n",line2[2]/line4[2]);

if (length1>length2){

printf("Length Big %f \n", length1);

printf("Length Small %f \n", length2);

cvWriteReal(fs,"lengthbig",length1);

cvWriteReal(fs,"lengthsmall",length2);

}

else{

printf("Length Big %f \n", length2);

printf("Length Small %f \n", length1);

cvWriteReal(fs,"lengthbig",length2);

cvWriteReal(fs,"lengthsmall",length1);

}

printf("length C is %f \n",C);

printf("Degrees is %f \n \n",degrees);

cvWriteReal(fs,"degrees",degrees);

}

elseif (line2[2]/line3[2]<=1.2 & line2[2]/line3[2] >= 0.83)

{

cvLine(ds_lines,pt1,pt4,CV_RGB(0,255,0),1,8);

cvLine(ds_lines,pt2,pt3,CV_RGB(0,255,0),1,8);

length1 = sqrt((line3[0]-line2[0])*(line3[0]-line2[0])+(line3[1]-line2[1])*(line3[1]-line2[1]));

length2 = sqrt((line1[0]-line4[0])*(line1[0]-line4[0])+(line1[1]-line4[1])*(line1[1]-line4[1]));

A= length1/2;

B= length2/2;

C= sqrt((line1[0]-line2[0])*(line1[0]-line2[0])+(line1[1]-line2[1])*(line1[1]-line2[1]));

degrees= acos((A*A+B*B-C*C)/(2*A*B))*180/PI;

printf("Radius %f \n",line2[2]/line3[2]);

if (length1>length2){

printf("Length Big %f \n", length1);

printf("Length Small %f \n", length2);

cvWriteReal(fs,"lengthbig",length1);

cvWriteReal(fs,"lengthsmall",length2);

}

else{

printf("Length Big %f \n", length2);

printf("Length Small %f \n", length1);

cvWriteReal(fs,"lengthbig",length2);

cvWriteReal(fs,"lengthsmall",length1);

}

printf("length C is %f \n",C);

printf("Degrees is %f \n \n",degrees);

cvWriteReal(fs,"degrees",degrees);

}

cvClearMemStorage( storage );

}

key= cvWaitKey(50);

}

else

{

for( i = 0; i < lines->total; i++ )

{

float* line1 = (float*)cvGetSeqElem(lines,i);

CvPoint pt1 =cvPoint(cvRound(line1[0]),cvRound(line1[1]) );

CvCircle( ds_lines, pt1, line1[2], CV_RGB(255,0,0), 1, 8 );

}

}

// display current frame

cvNamedWindow("Edge", CV_WINDOW_AUTOSIZE);

cvNamedWindow("Hough", CV_WINDOW_AUTOSIZE);

cvShowImage( "Edge", edge );

cvShowImage( "Hough",ds_lines );

key = cvWaitKey(50);

}

cvReleaseCapture(&capture1);

return 0;

}