10 void Image_Handler(FCGIContext * context, char * params)
12 int num = 0, width = 800, height = 600;
14 {"num", &num, FCGI_INT_T},
15 {"width", &width, FCGI_INT_T},
16 {"height", &height, FCGI_INT_T}
18 if (!FCGI_ParseRequest(context, params, val, 3))
20 else if (num < 0 || num > 1) {
21 FCGI_RejectJSON(context, "Invalid capture number");
23 } else if (width <= 0 || height <= 0) {
24 FCGI_RejectJSON(context, "Invalid width/height");
28 if (captureID != num) {
30 cvReleaseCapture(&capture);
32 capture = cvCreateCameraCapture(num);
36 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width);
37 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height);
39 static int p[] = {CV_IMWRITE_JPEG_QUALITY, 100, 0};
41 IplImage * frame = cvQueryFrame(capture);
42 assert(frame != NULL);
45 // CvMat * background = cvGetMat(frame, &stub, 0, 0);
47 // CvMat *cv8u = cvCreateMat(frame->width, frame->height, CV_8U);
50 // cvMinMaxLoc(background, &min, &max, &a, &b, 0);
52 // double ccscale = 255.0/(max-min);
53 // double ccshift = -min;
54 //cvCvtScale(frame, cv8u, ccscale, ccshift);
55 CvMat * jpg = cvEncodeImage(".jpg", frame, p);
58 Log(LOGNOTE, "Sending image!");
59 FCGI_PrintRaw("Content-type: image/jpg\r\n");
60 FCGI_PrintRaw("Cache-Control: no-cache, no-store, must-revalidate\r\n\r\n");
61 //FCGI_PrintRaw("Content-Length: %d", jpg->rows*jpg->cols);
62 FCGI_WriteBinary(jpg->data.ptr,1,jpg->rows*jpg->cols);
65 cvReleaseImageHeader(&frame);