CXX = gcc
FLAGS = -std=c99 -Wall -pedantic -g -I/usr/include/opencv -I/usr/include/opencv2/highgui -L/usr/lib
LIB = -lfcgi -lssl -lcrypto -lpthread -lm -lopencv_highgui -lopencv_core -lopencv_ml -lopencv_imgproc
-OBJ = log.o control.o data.o fastcgi.o main.o sensor.o actuator.o
+OBJ = log.o control.o data.o fastcgi.o main.o sensor.o actuator.o image.o
RM = rm -f
BIN = server
#include "actuator.h"
#include "control.h"
#include "options.h"
+#include "image.h"
/**The time period (in seconds) before the control key expires @ */
#define CONTROL_TIMEOUT 180
va_end(list);
}
+
+/**
+ * Write binary data
+ * See fwrite
+ */
+void FCGI_WriteBinary(void * data, size_t size, size_t num_elem)
+{
+ Log(LOGDEBUG,"Writing!");
+ FCGI_fwrite(data, size, num_elem, FCGI_stdout);
+}
+
/**
* Main FCGI request loop that receives/responds to client requests.
* @param data Reserved.
module_handler = Sensor_Handler;
} else if (!strcmp("actuators", module)) {
module_handler = Actuator_Handler;
+ } else if (!strcmp("image", module)) {
+ module_handler = Image_Handler;
}
context.current_module = module;
extern void FCGI_RejectJSONEx(FCGIContext *context, StatusCodes status, const char *description);
extern void *FCGI_RequestLoop (void *data);
+extern void FCGI_WriteBinary(void * data, size_t size, size_t num_elem);
+
/**
* Shortcut to calling FCGI_RejectJSONEx. Sets the error code
* to STATUS_ERROR.
--- /dev/null
+#include "cv.h"
+#include "highgui_c.h"
+#include "image.h"
+#include <string.h>
+#include <stdio.h>
+
+void Image_Handler(FCGIContext * context, const char * params)
+{
+ static CvCapture * capture = NULL;
+ if (capture == NULL)
+ capture = cvCreateCameraCapture(-1);
+
+ static int p[] = {CV_IMWRITE_JPEG_QUALITY, 100, 0};
+
+ IplImage * frame = cvQueryFrame(capture);
+ assert(frame != NULL);
+ CvMat * jpg = cvEncodeImage(".jpg", frame, p);
+
+ // Will this work?
+ Log(LOGNOTE, "Sending image!");
+ FCGI_PrintRaw("Content-type: image/jpg\r\n\r\n");
+ //FCGI_PrintRaw("Content-Length: %d", jpg->rows*jpg->cols);
+ FCGI_WriteBinary(jpg->data.ptr,1,jpg->rows*jpg->cols);
+
+}
--- /dev/null
+/**
+ * @file image.h
+ * @purpose Helper functions for image processing
+ */
+
+#ifndef _IMAGE_H
+#define _IMAGE_H
+
+#include "common.h"
+
+extern void Image_Handler(FCGIContext * context, const char * params);
+
+#endif //_IMAGE_H
+
+//EOF