From: Callum Date: Fri, 11 Oct 2013 05:26:54 +0000 (+0800) Subject: simple test function X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=26d56750cbdc70df836612ab8d142a9a21bf2f35;p=matches%2FMCTX3420.git simple test function --- diff --git a/server/dilatometer.c b/server/dilatometer.c index 6610cac..dd578d3 100644 --- a/server/dilatometer.c +++ b/server/dilatometer.c @@ -15,6 +15,36 @@ static CvMat * g_data = NULL; /** Camera capture pointer **/ static CvCapture * g_capture = NULL; +/** + * Create a test image + */ +void Dilatometer_TestImage() +{ + + CvMat *g_dataRGB; + g_dataRGB = cvCreateMat(480, 640, CV_8UC3); //32 + + //Make a rectangle from col=300 to 500, row=150 to 350 + /*for (int x = 100; x < 500; ++x) + { + CvScalar s; + s.val[0] = 150; s.val[1] = 233; s.val[2] = 244; + cvSet2D(g_dataRGB,150,x,s); + cvSet2D(g_dataRGB,350,x,s); + }*/ + for (int y = 0; y < 480; ++y) + { + CvScalar s; + s.val[0] = 200; s.val[1] = 233; s.val[2] = 244; + cvSet2D(g_dataRGB,y,100,s); + cvSet2D(g_dataRGB,y,500,s); + } + if (g_data == NULL) + { + g_data = cvCreateMat(g_dataRGB->rows,g_dataRGB->cols,CV_8UC1); //IPL_DEPTH_8U? + cvCvtColor(g_dataRGB,g_data,CV_RGB2GRAY); + } +} /** * Initialise the dilatometer @@ -43,9 +73,9 @@ void Dilatometer_Cleanup() * Get an image from the Dilatometer */ static void Dilatometer_GetImage() -{ - //Need to supply test image - +{ + //Test image + Dilatometer_TestImage(); //Need to implement camera } /** @@ -63,7 +93,7 @@ double Dilatometer_Read(int samples) // If the number of samples is greater than the image height, sample every row if( samples > height) { - Log(LOGNOTE, "Number of samples is greater than the dilatometer image height, sampling every row instead.\n"); + //Log(LOGNOTE, "Number of samples is greater than the dilatometer image height, sampling every row instead.\n"); samples = height; } @@ -72,25 +102,39 @@ double Dilatometer_Read(int samples) // The average width of the can double average_width; int sample_height; + printf("here2; %d\n", width); for (int i=0; i THRES) + //if ( CV_MAT_ELEM( *g_data, double, col, sample_height) > THRES) + + //printf("val is %f\n", cvGet2D(g_data, col, sample_height)); + //printf("position is col: %d, row: %d\n",col, sample_height); + CvScalar value = cvGet2D(g_data, sample_height, col); + //printf("value is %f\n", value.val[0]); + if( value.val[0]> THRES) { - edges[pos] += col; + edges[pos] += (double) col; num++; + printf("here; %f\n", edges[pos]); } // If num > 0 and we're not above threshold, we have left the threshold of the edge - else if( num > 0); + else if( num > 0) { // Find the mid point of the edge edges[pos] /= num; @@ -108,6 +152,23 @@ double Dilatometer_Read(int samples) average_width += (edges[1] - edges[0]); } average_width /= samples; + printf("the average width is %f\n", average_width); return average_width; } +/** + * For testing purposes + */ +int main(int argc, char ** argv) +{ + //cvNamedWindow( "display", CV_WINDOW_AUTOSIZE );// Create a window for display. + //gettimeofday(&start, NULL); + + Dilatometer_Init(); + + cvNamedWindow( "display", CV_WINDOW_AUTOSIZE); + cvShowImage("display", g_data); + cvWaitKey(0); + Dilatometer_Read(5); +} +