Changed capture initilisation
authorCallum <callum@callum-ubuntu.(none)>
Tue, 29 Oct 2013 15:02:46 +0000 (23:02 +0800)
committerCallum <callum@callum-ubuntu.(none)>
Tue, 29 Oct 2013 15:02:46 +0000 (23:02 +0800)
server/image.c
server/sensors/dilatometer.c

index 3c30467..164dc09 100644 (file)
@@ -6,6 +6,7 @@
 #include <pthread.h>
 
 CvCapture *capture;
+IplImage *frame;
 int captureID = -1;
 
 void Image_Handler(FCGIContext * context, char * params)
@@ -31,7 +32,7 @@ void Image_Handler(FCGIContext * context, char * params)
        CvMat * g_src = NULL;   // Source Image
        CvMat * g_encoded;      // Encoded Image
 
-       Camera_GetImage( num, width, height ,g_src); 
+       result = Camera_GetImage( num, width, height ,g_src); 
        g_encoded = cvEncodeImage("test_encode.jpg",g_src,0);
 
        Log(LOGNOTE, "Sending image!");
@@ -43,19 +44,29 @@ void Image_Handler(FCGIContext * context, char * params)
        cvReleaseMat(&g_encoded);
        cvReleaseMat(&g_src);
 }
-
+       
  bool Camera_GetImage(int num, int width, int height,  CvMat * image)
  {
        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;
 
-       capture = cvCreateCameraCapture(num);
+       if( capture == NULL)
+       {
+               capture = cvCreateCameraCapture(num);
+               captureID = num;
+       }
+       else if( num != captureID)
+       {
+               cvReleaseCapture(&capture);
+               capture = cvCreateCameraCapture(num);   
+               captureID = num;
+       }
 
        cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width);
        cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height);
 
-       IplImage * frame = cvQueryFrame(capture);
+       frame = cvQueryFrame(capture);
        if( frame == NULL)
                return result;
 
@@ -65,11 +76,14 @@ void Image_Handler(FCGIContext * context, char * params)
        if( image == NULL)
                return result;
 
+       pthread_mutex_unlock(&mutex);   //Close the mutex
+       return true;
+}
+
+void Image_Cleanup()
+{
        // Release the capture and IplImage pointers
        cvReleaseImageHeader(&frame);
        cvReleaseCapture(&capture);
-
-       pthread_mutex_unlock(&mutex);   //Close the mutex
-       return true;
 }
 
index 10b2e61..18d5e68 100644 (file)
@@ -165,7 +165,7 @@ void CannyThreshold()
  * @param samples - Number of rows to scan (increasing will slow down performance!)
  * @returns true on successful read
  */
-bool Dilatometer_GetEdge( double * value, int samples)
+bool Dilatometer_GetExpansion( double * value, int samples)
 {
        bool result = false; 
        double average = 0;
@@ -244,7 +244,7 @@ bool Dilatometer_GetEdge( double * value, int samples)
  */
 bool Dilatometer_Read(int id, double * value)
 {
-       bool result = Dilatometer_GetEdge(value, SAMPLES);
+       bool result = Dilatometer_GetExpansion(value, SAMPLES);
        return result;
 }
 
@@ -256,7 +256,7 @@ bool Dilatometer_Init(const char * name, int id)
        // Make an initial reading (will allocate memory the first time only).
        double val;
        lastPosition = 0;  // Reset the last position
-       bool result = Dilatometer_GetEdge(&val, 1); 
+       bool result = Dilatometer_GetExpansion(&val, 1); 
        return result;
 }
 

UCC git Repository :: git.ucc.asn.au