From: Callum Date: Tue, 29 Oct 2013 15:02:46 +0000 (+0800) Subject: Changed capture initilisation X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f316d3b0234badc48d97ef3fcc607f7eddcb9a62;p=matches%2FMCTX3420.git Changed capture initilisation --- diff --git a/server/image.c b/server/image.c index 3c30467..164dc09 100644 --- a/server/image.c +++ b/server/image.c @@ -6,6 +6,7 @@ #include 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; } diff --git a/server/sensors/dilatometer.c b/server/sensors/dilatometer.c index 10b2e61..18d5e68 100644 --- a/server/sensors/dilatometer.c +++ b/server/sensors/dilatometer.c @@ -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; }