Merge branch 'master' of https://github.com/szmoore/MCTX3420.git
[matches/MCTX3420.git] / server / image.c
1 #include "cv.h"
2 #include "highgui_c.h"
3 #include "image.h"
4 #include <string.h>
5 #include <stdio.h>
6
7 void Image_Handler(FCGIContext * context, char * params)
8 {
9         static CvCapture * capture = NULL;
10         if (capture == NULL) {
11                 capture = cvCreateCameraCapture(0);
12                 //limit resolution to work on bbb
13                 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 352);
14                 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 288);
15         }
16         static int p[] = {CV_IMWRITE_JPEG_QUALITY, 100, 0};
17
18         IplImage * frame = cvQueryFrame(capture);
19         assert(frame != NULL);
20
21 //        CvMat stub;
22  //       CvMat * background = cvGetMat(frame, &stub, 0, 0);
23
24 //      CvMat *cv8u = cvCreateMat(frame->width, frame->height, CV_8U);
25 //      double min, max;
26 //      CvPoint a,b;    
27 //      cvMinMaxLoc(background, &min, &max, &a, &b, 0);
28         
29 //      double ccscale = 255.0/(max-min);
30 //      double ccshift = -min;
31         //cvCvtScale(frame, cv8u, ccscale, ccshift);
32         CvMat * jpg = cvEncodeImage(".jpg", frame, p);
33
34         // Will this work?
35         Log(LOGNOTE, "Sending image!");
36         FCGI_PrintRaw("Content-type: image/jpg\r\n");
37         FCGI_PrintRaw("Cache-Control: no-cache, no-store, must-revalidate\r\n\r\n");
38         //FCGI_PrintRaw("Content-Length: %d", jpg->rows*jpg->cols);
39         FCGI_WriteBinary(jpg->data.ptr,1,jpg->rows*jpg->cols);
40         
41         cvReleaseMat(&jpg);
42         cvReleaseImageHeader(&frame);
43 }

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