#include <pthread.h>
CvCapture *capture;
+IplImage *frame;
int captureID = -1;
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!");
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;
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;
}
* @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;
*/
bool Dilatometer_Read(int id, double * value)
{
- bool result = Dilatometer_GetEdge(value, SAMPLES);
+ bool result = Dilatometer_GetExpansion(value, SAMPLES);
return result;
}
// 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;
}