{
if (g_capture != NULL)
cvReleaseCapture(&g_capture);
- if (g_srcRGB != NULL)
- cvReleaseMat(&g_srcRGB);
+ if (frame != NULL)
+ cvReleaseImageHeader(&frame);
+ //if (g_srcRGB != NULL)
+ // cvReleaseMat(&g_srcRGB); // Causing run time error in cvReleaseMat
if (g_srcGray != NULL)
cvReleaseMat(&g_srcGray);
if (g_edges != NULL)
cvReleaseMat(&g_edges);
- if (frame != NULL)
- cvReleaseImageHeader(&frame);
}
/**
{
bool result = true;
// If more than one camera is connected, then input needs to be determined, however the camera ID may change after being unplugged
- g_capture = cvCreateCameraCapture(0);
- //If cvCreateCameraCapture returns NULL there is an error with the camera
if( g_capture == NULL)
- result = false;
-
+ {
+ g_capture = cvCreateCameraCapture(0);
+ //If cvCreateCameraCapture returns NULL there is an error with the camera
+ if( g_capture == NULL)
+ {
+ result = false;
+ return;
+ }
+ }
+
// Get the frame and convert it to CvMat
frame = cvQueryFrame(g_capture);
CvMat stub;
//Save the image
//cvSaveImage("test_blurred.jpg",g_edges,0);
- printf("what about here?\n");
- cvShowImage("display", g_edges);
- cvWaitKey(0);
+ //cvShowImage("display", g_edges);
+ //cvWaitKey(0);
+
// Find the edges in the image
cvCanny( g_edges, g_edges, lowThreshold, lowThreshold*ratio, kernel_size );
//Save the image
//cvSaveImage("test_edge.jpg",g_edges,0);
- cvShowImage("display", g_edges);
- cvWaitKey(0);
- printf("hopeful\n");
+ //cvShowImage("display", g_edges);
+ //cvWaitKey(0);
}
double edge;
Dilatometer_GetEdge(&edge,20000);
//For testing purposes, overlay the given average line over the image
- Draw_Edge(edge);
+ //Draw_Edge(edge);
cvDestroyWindow("display");
Dilatometer_Cleanup();
-
}
static CvMat * g_srcRGB = NULL; // Source Image
static CvMat * g_srcGray = NULL; // Gray scale of source image
static CvMat * g_edges = NULL; // Detected Edges
-static CvMat * g_data = NULL;
/** Pointers for capturing image **/
static CvCapture * g_capture = NULL;
}
}
- if (g_data == NULL)
+ if (g_srcGray == NULL)
{
- g_data = cvCreateMat(g_srcRGB->rows,g_srcRGB->cols,CV_8UC1);
+ g_srcGray = cvCreateMat(g_srcRGB->rows,g_srcRGB->cols,CV_8UC1);
}
- cvCvtColor(g_srcRGB,g_data,CV_RGB2GRAY);
+ cvCvtColor(g_srcRGB,g_srcGray,CV_RGB2GRAY);
}
/**
*/
void Dilatometer_Cleanup()
{
- if (g_data != NULL)
- cvReleaseMat(&g_data);
if (g_capture != NULL)
cvReleaseCapture(&g_capture);
- if (g_srcRGB != NULL)
- cvReleaseMat(&g_srcRGB);
+ if (frame != NULL)
+ cvReleaseImageHeader(&frame);
+ //if (g_srcRGB != NULL)
+ // cvReleaseMat(&g_srcRGB); // Causing run time error in cvReleaseMat
if (g_srcGray != NULL)
cvReleaseMat(&g_srcGray);
if (g_edges != NULL)
cvReleaseMat(&g_edges);
- if (frame != NULL)
- cvReleaseImageHeader(&frame);
}
/**
{
bool result = true;
// If more than one camera is connected, then input needs to be determined, however the camera ID may change after being unplugged
- g_capture = cvCreateCameraCapture(0);
-
- //If cvCreateCameraCapture returns NULL there is an error with the camera
if( g_capture == NULL)
- result = false;
-
+ {
+ g_capture = cvCreateCameraCapture(0);
+ //If cvCreateCameraCapture returns NULL there is an error with the camera
+ if( g_capture == NULL)
+ {
+ result = false;
+ return;
+ }
+ }
+
// Get the frame and convert it to CvMat
frame = cvQueryFrame(g_capture);
CvMat stub;
if( g_srcRGB == NULL)
result = false;
-
+
+ // Convert the image to grayscale
+ if (g_srcGray == NULL)
+ {
+ g_srcGray = cvCreateMat(g_srcRGB->rows,g_srcRGB->cols,CV_8UC1);
+ }
+
+ cvCvtColor(g_srcRGB,g_srcGray,CV_RGB2GRAY);
+
return result;
}
void CannyThreshold()
{
-
- if (g_data == NULL)
- {
- g_data = cvCreateMat(g_srcGray->rows,g_srcGray->cols,CV_8UC1);
- }
-
if ( g_edges == NULL)
{
g_edges = cvCreateMat(g_srcGray->rows,g_srcGray->cols,CV_8UC1);
//cvSaveImage("test_blurred.jpg",g_edges,0);
//cvShowImage("display", g_edges);
- //cvWaitKey(0);
-
+ //cvWaitKey(0);
+
// Find the edges in the image
cvCanny( g_edges, g_edges, lowThreshold, lowThreshold*ratio, kernel_size );
//cvShowImage("display", g_edges);
//cvWaitKey(0);
-
+
}
/**
}
cvShowImage("display", g_edges);
cvWaitKey(0);
- cvSaveImage("test_edge_avg.jpg",g_edges,0);
+ //cvSaveImage("test_edge_avg.jpg",g_edges,0);
}
-/*// Test algorithm
+/* // Test algorithm
static void Dilatometer_GetImageTest( )
{
//Generates Test image
Dilatometer_Init();
cvNamedWindow( "display", CV_WINDOW_AUTOSIZE);
-// cvShowImage("display", g_data);
-// cvWaitKey(0);
- double width;
+ //double width;
double edge;
- Dilatometer_Read(&edge,20000);
+ Dilatometer_GetEdge(&edge,20000);
//For testing purposes, overlay the given average line over the image
- Draw_Edge(edge);
-
+ //Draw_Edge(edge);
+
cvDestroyWindow("display");
+ Dilatometer_Cleanup();
}*/