$(BIN) : $(OBJ)
$(CXX) $(FLAGS) -o $(BIN) $(OBJ) $(LIB)
+microscope : microscope.o
+ $(CXX) $(FLAGS) -o microscope microscope.o $(LIB)
+
%.o : %.c
$(CXX) $(FLAGS) -c $<
bool Pregulator_Set(int id, double value)
{
double anti_calibrated = Data_Calibrate(value, preg_cal, pwm_raw, sizeof(pwm_raw)/sizeof(double));
+ Log(LOGDEBUG, "Pregulator value %f -> PWM duty cycle %f", value, anti_calibrated);
if (anti_calibrated < 0)
anti_calibrated = 0;
if (anti_calibrated > 1)
#include <stdio.h>
#include <pthread.h>
-CvCapture *capture;
-IplImage *frame;
-int captureID = -1;
+static CvCapture * g_capture = NULL;
+static int g_captureID = -1;
void Image_Handler(FCGIContext * context, char * params)
{
return;
}
- CvMat * g_src = NULL; // Source Image
- CvMat * g_encoded; // Encoded Image
+ IplImage * src = NULL; // Source Image
+ CvMat * encoded = NULL; // Encoded Image
- Camera_GetImage( num, width, height ,g_src);
- g_encoded = cvEncodeImage("test_encode.jpg",g_src,0);
+ Camera_GetImage( num, width, height ,&src);
+
+ Log(LOGDEBUG, "About to encode");
+ encoded = cvEncodeImage(".jpg",src,0);
+ Log(LOGDEBUG, "Encoded");
Log(LOGNOTE, "Sending image!");
FCGI_PrintRaw("Content-type: image/jpg\r\n");
FCGI_PrintRaw("Cache-Control: no-cache, no-store, must-revalidate\r\n\r\n");
//FCGI_PrintRaw("Content-Length: %d", g_encoded->rows*g_encoded->cols);
- FCGI_WriteBinary(g_encoded->data.ptr,1,g_encoded->rows*g_encoded->cols);
+ FCGI_WriteBinary(encoded->data.ptr,1,encoded->rows*encoded->cols);
- cvReleaseMat(&g_encoded);
- cvReleaseMat(&g_src);
+ cvReleaseMat(&encoded);
+ cvReleaseImageHeader(&src);
}
- bool Camera_GetImage(int num, int width, int height, CvMat * image)
+/**
+ * Attempts to get an image from a camera
+ * @param num - Camera id
+ * @param width - Width to force
+ * @param height - Height to force
+ * @param image - Pointer to CvMat* to set with result
+ * @returns true on success, false on error
+ */
+ bool Camera_GetImage(int num, int width, int height, IplImage ** frame)
{
+ Log(LOGDEBUG, "Called with arguments num=%d width=%d height=%d frame=%p", num,width,height, frame);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // Need to use a mutex to ensure 2 captures are not open at once
pthread_mutex_lock(&mutex);
bool result = false;
- if( capture == NULL)
+ if( g_capture == NULL)
{
- capture = cvCreateCameraCapture(num);
- captureID = num;
+ g_capture = cvCreateCameraCapture(num);
+ g_captureID = num;
}
- else if( num != captureID)
+ else if( num != g_captureID)
{
- cvReleaseCapture(&capture);
- capture = cvCreateCameraCapture(num);
- captureID = num;
+ cvReleaseCapture(&g_capture);
+ g_capture = cvCreateCameraCapture(num);
+ g_captureID = num;
}
- cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width);
- cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height);
-
- frame = cvQueryFrame(capture);
- if( frame == NULL)
- return result;
+ //cvSetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_WIDTH, width);
+ //cvSetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_HEIGHT, height);
- // Convert the IplImage pointer to CvMat
- CvMat stub;
- image = cvGetMat(frame, &stub, 0, 0);
- if( image == NULL)
- return result;
+ *frame = cvQueryFrame(g_capture);
+ result = (*frame != NULL);
+ //cvShowImage("display", *image);
+ //cvWaitKey(0);
+ //cvSaveImage("test.jpg",*image,0);
+
+ Log(LOGDEBUG, "At end of mutex");
+
pthread_mutex_unlock(&mutex); //Close the mutex
- return true;
+
+ //NOTE: Never have a "return" statement before the mutex is unlocked; it causes deadlocks!
+ return result;
}
void Image_Cleanup()
{
// Release the capture and IplImage pointers
- cvReleaseImageHeader(&frame);
- cvReleaseCapture(&capture);
+ //cvReleaseImageHeader(&g_frame);
+ cvReleaseCapture(&g_capture);
}
extern void Image_Init();
extern void Image_Handler(FCGIContext * context, char * params);
extern void Image_Cleanup();
-extern bool Camera_GetImage(int num, int width, int height, CvMat * image);
+extern bool Camera_GetImage(int num, int width, int height, IplImage ** image);
#endif //_IMAGE_H
#auth_uri="ldaps://ldap.pheme.uwa.edu.au#ou=Users,ou=UWA,dc=uwads,dc=uwa,dc=edu,dc=au" #UWA
#auth_uri="/etc/shadow"
#auth_uri="shadow"
-auth_uri="mysql://localhost#root,$(cat mysql_password)"
+#auth_uri="mysql://localhost#root,$(cat mysql_password)"
## OPTIONS TO BE PASSED TO SERVER; DO NOT EDIT
-parameters="-v $verbosity -p $pin_test -A $auth_uri"
+parameters="-v $verbosity -p $pin_test"
+# -A $auth_uri"
Sensor_Add("pressure_high1", PRES_HIGH1, Pressure_Read, Pressure_Init, Pressure_Cleanup, NULL);
Sensor_Add("pressure_low0", PRES_LOW0, Pressure_Read, Pressure_Init, Pressure_Cleanup, NULL);
//Sensor_Add("../testing/count.py", 0, Piped_Read, Piped_Init, Piped_Cleanup, 1e50,-1e50,1e50,-1e50);
- Sensor_Add("strain0", STRAIN0, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
- Sensor_Add("strain1", STRAIN1, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
- Sensor_Add("strain2", STRAIN2, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
- Sensor_Add("strain3", STRAIN3, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
+ Sensor_Add("strain0_endhoop", STRAIN0, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
+ Sensor_Add("strain1_endlong", STRAIN1, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
+ Sensor_Add("strain2_midhoop", STRAIN2, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
+ Sensor_Add("strain3_midlong", STRAIN3, Strain_Read, Strain_Init, Strain_Cleanup, Strain_Sanity);
//Sensor_Add("pressure0", PRESSURE0, Pressure_Read, Pressure_Init, 5000,0,5000,0);
//Sensor_Add("pressure1", PRESSURE1, Pressure_Read, Pressure_Init, 5000,0,5000,0);
//Sensor_Add("pressure_feedback", PRESSURE_FEEDBACK, Pressure_Read, Pressure_Init, 5000,0,5000,0);
//Sensor_Add("enclosure", ENCLOSURE, Enclosure_Read, Enclosure_Init, 1,1,1,1);
Sensor_Add("dilatometer_pos", DIL_POS, Dilatometer_Read, Dilatometer_Init, Dilatometer_Cleanup, NULL);
- Sensor_Add("dilatometer_diff",DIL_DIFF, Dilatometer_Read, Dilatometer_Init, Dilatometer_Cleanup, NULL);
+ //Sensor_Add("dilatometer_diff",DIL_DIFF, Dilatometer_Read, Dilatometer_Init, Dilatometer_Cleanup, NULL);
}
/**
#include "cv.h"
#include "highgui_c.h"
#include "dilatometer.h"
+#include "../image.h"
#include <math.h>
// test positions
void CannyThreshold()
{
+
+ // Create greyscale array
+ if (g_srcGray == NULL)
+ {
+ Log(LOGDEBUG, "%d %d %d", g_srcRGB->rows, g_srcRGB->cols, CV_8UC1);
+ g_srcGray = cvCreateMat(g_srcRGB->rows,g_srcRGB->cols,CV_8UC1);
+ }
+
// Convert the RGB source file to grayscale
+ Log(LOGDEBUG, "About to cvCvtColor(%p, %p, %d)", g_srcRGB, g_srcGray, CV_RGB2GRAY);
cvCvtColor(g_srcRGB,g_srcGray,CV_RGB2GRAY);
+
+ Log(LOGDEBUG, "About to cvCreateMat");
if ( g_edges == NULL)
{
g_edges = cvCreateMat(g_srcGray->rows,g_srcGray->cols,CV_8UC1);
bool result = false;
double average = 0;
// Get the image from the camera
- result = Camera_GetImage( 0, 1600, 1200 ,&g_srcRGB); // Get a 1600x1200 image and place it into src
+ Log(LOGDEBUG, "GET IMAGE?");
+
+ IplImage * frame = NULL;
+ result = Camera_GetImage( 0, 1600, 1200 ,&frame); // Get a 1600x1200 image and place it into src
+ Log(LOGDEBUG, "Got image...");
// If an error occured when capturing image then return
+
+
+ if (result)
+ {
+ CvMat stub;
+ g_srcRGB = cvGetMat(frame,&stub,0,0);
+ result = (g_srcRGB != NULL);
+ Log(LOGDEBUG, "Converted image %d %p", result, g_srcRGB);
+ }
+ cvReleaseImageHeader(&frame);
+
if (!result)
return result;
+
+ Log(LOGDEBUG, "GOT IMAGE (without error)!");
+
// Apply the Canny Edge theorem to the image
CannyThreshold();
+ Log(LOGDEBUG, "Got past CannyThreshold()");
+
int width = g_edges->cols;
int height = g_edges->rows;
// Make an initial reading (will allocate memory the first time only).
double val;
lastPosition = 0; // Reset the last position
- bool result = Dilatometer_GetExpansion(DIL_POS, &val, 1);
- return result;
+ Dilatometer_GetExpansion(DIL_POS, &val, 1);
+ return true;
}
// Overlays a line over the given edge position
#ifndef _STRAIN_H
#define _STRAIN_H
+#include "../common.h"
#include <stdbool.h>
/**