22:41 -!- Irssi: #mctxuwa_softdev: Total of 2 nicks [0 ops, 0 halfops, 0 voices, 2 normal]
22:41 -!- Irssi: Join to #mctxuwa_softdev was synced in 2 secs
22:41 -!- You're now known as sam_moore
+--- Day changed Sun Oct 13 2013
+10:18 < jtanx> yeah, about the django stuff, I'm not sure if we should do that now
+10:18 < jtanx> two options I considered:
+10:19 < jtanx> if you kept the 'bind' module, but added a method to authenticate against the django database, that could work, but it's a lot of effort
+10:19 < jtanx> - there's two ways - one is to manually do it via interaction with the sqlite database and parsing the user string etc etc
+10:20 < jtanx> the other way is to call the python function from c
+10:20 < jtanx> I explored the 'call python from c' option and it does work, but it's quite cumbersome
+10:20 < jtanx> I didn't bother exploring the 'manual interaction with sqlite' because that would be even more cumbersome
+10:21 < jtanx> The other way, which I got working quite easily
+10:21 < jtanx> is to protect one of the modules with nginx
+10:21 < jtanx> say /api/control now becomes an 'internal' only module
+10:21 < jtanx> so it's not usually accessible from outside
+10:22 < jtanx> with django, say you got the address /databases/control
+10:23 < jtanx> it can send back a request with header 'X-Accel-Redirect' to /api/control
+10:23 < jtanx> Because it was sent by django, which is an internal application, it works
+10:23 < jtanx> such that /databases/control looks like /api/control to the user
+10:24 < jtanx> the problem with this setup is that then your api becomes entirely dependent on django to work
+10:24 < jtanx> I guess you could replace 'django' with any other authrorization frontend
+10:31 < jtanx> let's just stick with what we've got
+10:36 < jtanx> hahahaha and that x-accel-redirect just crashed my server after I held down f5
+19:19 < jtanx> I think I'll try to get in early tomorrow to work on whatever needs to be done
+19:56 < jtanx> For the actuators, do you really want it to crash (Fatal) if the user supplies a step say of 0,1,40000,2?
+21:19 < jtanx> working on the graphs now
+23:29 < jtanx> ookay
+23:29 < jtanx> too tired to check, but I refactored it and I think it still works
+23:30 < jtanx> I'll just leave it in my fork for now
/**
* @file dilatometer.c
- * @brief Implementation of dilatometer related functions
+ * @purpose Implementation of dilatometer related functions
*/
#include "cv.h"
#include "dilatometer.h"
#include <math.h>
+// test positions
+static double test_left, test_right;
+
/** Buffer for storing image data. Stored as a **/
static CvMat * g_data = NULL;
/** Camera capture pointer **/
static CvCapture * g_capture = NULL;
+/**
+ * Create a test image using left as left edge and right as right edge positions
+ */
+void Dilatometer_TestImage()
+{
+
+ CvMat *g_dataRGB;
+ g_dataRGB = cvCreateMat(480, 640, CV_8UC3);
+ //Make sure left and right positions are sane
+ if( test_left < 0)
+ test_left = 0;
+ if( test_right > 639)
+ test_right = 639;
+ if( test_left > test_right)
+ {
+ int tmp = test_right;
+ test_right = test_left;
+ test_left = tmp;
+ }
+
+ for( int x = 0; x < 640; ++x)
+ {
+ for (int y = 0; y < 480; ++y)
+ {
+ CvScalar s;
+ for( int i = 0; i < 3; ++i)
+ {
+ s.val[i] = 220 + (rand() % 1000) * 1e-2 - (rand() % 1000) * 1e-2;
+ // Produce an exponential decay around left edge
+ if( x < test_left)
+ s.val[i] *= exp( (x - test_left) / 25);
+ else if( x < 320)
+ s.val[i] *= exp( (test_left - x) / 25);
+ // Produce an exponential decay around right edge
+ else if( x < test_right)
+ s.val[i] *= exp( (x - test_right) / 25);
+ else
+ s.val[i] *= exp( (test_right - x) / 25);
+ }
+ cvSet2D(g_dataRGB,y,x,s);
+ // if( s.val[0] > 200)
+ // printf("row: %d, col: %d, %f\n", y, x, s.val[0]);
+ }
+
+ }
+ 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
* Get an image from the Dilatometer
*/
static void Dilatometer_GetImage()
-{
- //Need to supply test image
-
+{
//Need to implement camera
}
+
+// Test algorithm
+static void Dilatometer_GetImageTest( )
+{
+ //Test image
+ Dilatometer_TestImage();
+}
+
+
/**
* Read the dilatometer; gets the latest image, processes it, THEN DOES WHAT
* @param samples - Number of rows to scan (increasing will slow down performance!)
double Dilatometer_Read(int samples)
{
//Get the latest image
- Dilatometer_GetImage();
+ //Dilatometer_GetImage();
+ Dilatometer_GetImageTest();
+
int width = g_data->cols;
int height = g_data->rows;
// 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;
}
for (int i=0; i<samples; i++)
{
// Contains the locations of the 2 edges
- double edges[2] = {0};
+ double edges[2] = {0.0,0.0};
int pos = 0; // Position in the edges array (start at left edge)
int num = 0; // Keep track of the number of columns above threshold
// Determine the position in the rows to find the edges.
sample_height = ceil(height * (i + 1) / samples) -1;
-
+ //printf("sample height is %d\n", sample_height);
+
+ //CvScalar test = cvGet2D(g_data, 150,300);
+ //printf("test is %f,%f,%f,%f\n", test.val[0], test.val[1], test.val[2], test.val[3]);
+
+
for ( int col = 0; col < width; col++)
{
- if ( CV_MAT_ELEM( *g_data, double, col, sample_height) > THRES)
+ CvScalar value = cvGet2D(g_data, sample_height, col);
+ if( value.val[0]> THRES)
{
- edges[pos] += col;
+ edges[pos] += (double) col;
num++;
}
// 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;
//widths[i] = edges[1] - edges[0];
average_width += (edges[1] - edges[0]);
}
- average_width /= samples;
- return average_width;
+ average_width /= (double) samples;
+ 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);
+ test_left = 100;
+ test_right = 500;
+ Dilatometer_Init();
+
+ cvNamedWindow( "display", CV_WINDOW_AUTOSIZE);
+ cvShowImage("display", g_data);
+ cvWaitKey(0);
+ double width;
+ for( int i = 0; i < 20; ++i)
+ {
+ test_left -= i * (rand() % 1000) * 1e-3;
+ test_right += i * (rand() % 1000) * 1e-3;
+ width = Dilatometer_Read(5);
+ cvNamedWindow( "display", CV_WINDOW_AUTOSIZE);
+ cvShowImage("display", g_data);
+ cvWaitKey(0);
+ double expected = test_right - test_left;
+ double perc = 100 * (expected - width) / expected;
+ printf("%d: Left: %.4f. Width: %.4f.\n Right: %.4f. Expected: %.4f. Percentage: %.4f\n", i, test_left, width, test_right, expected, perc);
+ }
}