7 CvCapture *captures[2] = {0};
9 void Image_Handler(FCGIContext * context, char * params)
11 int num = 0, width = 800, height = 600;
13 {"num", &num, FCGI_INT_T},
14 {"width", &width, FCGI_INT_T},
15 {"height", &height, FCGI_INT_T}
17 if (!FCGI_ParseRequest(context, params, val, 3))
19 else if (num < 0 || num > 1) {
20 FCGI_RejectJSON(context, "Invalid capture number");
22 } else if (width <= 0 || height <= 0) {
23 FCGI_RejectJSON(context, "Invalid width/height");
27 CvCapture *capture = captures[num];
28 if (capture == NULL) {
29 capture = cvCreateCameraCapture(num);
30 captures[num] = capture;
33 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width);
34 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height);
36 static int p[] = {CV_IMWRITE_JPEG_QUALITY, 100, 0};
38 IplImage * frame = cvQueryFrame(capture);
39 assert(frame != NULL);
42 // CvMat * background = cvGetMat(frame, &stub, 0, 0);
44 // CvMat *cv8u = cvCreateMat(frame->width, frame->height, CV_8U);
47 // cvMinMaxLoc(background, &min, &max, &a, &b, 0);
49 // double ccscale = 255.0/(max-min);
50 // double ccshift = -min;
51 //cvCvtScale(frame, cv8u, ccscale, ccshift);
52 CvMat * jpg = cvEncodeImage(".jpg", frame, p);
55 Log(LOGNOTE, "Sending image!");
56 FCGI_PrintRaw("Content-type: image/jpg\r\n");
57 FCGI_PrintRaw("Cache-Control: no-cache, no-store, must-revalidate\r\n\r\n");
58 //FCGI_PrintRaw("Content-Length: %d", jpg->rows*jpg->cols);
59 FCGI_WriteBinary(jpg->data.ptr,1,jpg->rows*jpg->cols);
62 cvReleaseImageHeader(&frame);