Merge pull request #50 from RowanHeinrich/patch-6
[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                 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
13                 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
14         }
15         static int p[] = {CV_IMWRITE_JPEG_QUALITY, 100, 0};
16
17         IplImage * frame = cvQueryFrame(capture);
18         assert(frame != NULL);
19
20 //        CvMat stub;
21  //       CvMat * background = cvGetMat(frame, &stub, 0, 0);
22
23 //      CvMat *cv8u = cvCreateMat(frame->width, frame->height, CV_8U);
24 //      double min, max;
25 //      CvPoint a,b;    
26 //      cvMinMaxLoc(background, &min, &max, &a, &b, 0);
27         
28 //      double ccscale = 255.0/(max-min);
29 //      double ccshift = -min;
30         //cvCvtScale(frame, cv8u, ccscale, ccshift);
31         CvMat * jpg = cvEncodeImage(".jpg", frame, p);
32
33         // Will this work?
34         Log(LOGNOTE, "Sending image!");
35         FCGI_PrintRaw("Content-type: image/jpg\r\n");
36         FCGI_PrintRaw("Cache-Control: no-cache, no-store, must-revalidate\r\n\r\n");
37         //FCGI_PrintRaw("Content-Length: %d", jpg->rows*jpg->cols);
38         FCGI_WriteBinary(jpg->data.ptr,1,jpg->rows*jpg->cols);
39         
40         cvReleaseMat(&jpg);
41         cvReleaseImageHeader(&frame);
42 }

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