+
+ IplImage * src = NULL; // Source Image
+ CvMat * encoded = NULL; // Encoded Image
+
+ 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(encoded->data.ptr,1,encoded->rows*encoded->cols);
+
+ cvReleaseMat(&encoded);
+ cvReleaseImageHeader(&src);
+}
+
+/**
+ * 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;