+ if (num_edges > 0)
+ average /= num_edges;
+
+ if( average > 0)
+ {
+ result = true; //Successfully found an edge
+ *value = average;
+ }
+ return result;
+}
+
+ /**
+ * Read the dilatometer image. The value changed will correspond to the new location of the edge.
+ * @param val - Will store the read value if successful
+ * @returns true on successful read
+ */
+bool Dilatometer_Read( double * value)
+{
+ bool result = Dilatometer_GetEdge(value, SAMPLES);
+ return result;
+}
+
+/**
+ * Initialise the dilatometer
+ */
+void Dilatometer_Init()
+{
+ // Make an initial reading (will allocate memory the first time only).
+ double val;
+ Dilatometer_GetEdge(&val, 1);
+}
+
+// Overlays a line over the given edge position
+void Draw_Edge(double edge)
+{
+ CvScalar value;
+ value.val[0]=244;
+ for( int i = 0; i < g_srcGray->rows; i++)
+ {
+ cvSet2D(g_edges,i,edge,value);
+ }
+ cvShowImage("display", g_edges);
+ cvWaitKey(0);
+ //cvSaveImage("test_edge_avg.jpg",g_edges,0);
+}
+
+/* // Test algorithm
+static void Dilatometer_GetImageTest( )
+{
+ //Generates Test image
+ //Dilatometer_TestImage();
+
+ //Load Test image
+ g_srcGray = cvLoadImageM ("testimage4.jpg",CV_LOAD_IMAGE_GRAYSCALE );
+}*/
+
+/**
+ * For testing purposes
+ */
+int main(int argc, char ** argv)
+{
+ //cvNamedWindow( "display", CV_WINDOW_AUTOSIZE );// Create a window for display.
+ //gettimeofday(&start, NULL);
+ test_left = 100;
+ test_right = 500;
+ Dilatometer_Init();
+
+ cvNamedWindow( "display", CV_WINDOW_AUTOSIZE);
+ //double width;
+
+ double edge;
+ Dilatometer_GetEdge(&edge,20000);
+ //For testing purposes, overlay the given average line over the image
+ //Draw_Edge(edge);
+
+ cvDestroyWindow("display");
+
+ Dilatometer_Cleanup();