Qcam Orbit AF をOpenCVで動かす

やってみた。
画像は問題なくとれてるけどPan/Tiltは動かない。
先日買った某OpenCV本のとこのOpenCV+PWCパッチをみるに、まじめにパッチ作っても取り込まれそうにないので、てきとーに醜いhackをする。
queryFrameと動作を同時にやって問題なし。まあまあ動いてるのでよしとする。
こんなかんじ。

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <uvcvideo.h>
#include <cv.h>
#include <highgui.h>

typedef struct CvCaptureVTable vtable;
typedef struct CvCapture
{
    CvCaptureVTable* vtable;
    int deviceHandle;
}
CvCapture;

int pantilt(CvCapture* capture, int pan, int tilt, int reset)
{
    if(! (capture && capture->deviceHandle)){
      return -2;
    }

    int dev = capture->deviceHandle;
    struct v4l2_ext_control xctrls[2];
    struct v4l2_ext_controls ctrls;

        if (reset) {
                xctrls[0].id = V4L2_CID_PANTILT_RESET;
                xctrls[0].value = 3;

                ctrls.count = 1;
                ctrls.controls = xctrls;
        } else {
                xctrls[0].id = V4L2_CID_PAN_RELATIVE;
                xctrls[0].value = pan;
                xctrls[1].id = V4L2_CID_TILT_RELATIVE;
                xctrls[1].value = tilt;
                ctrls.count = 2;
                ctrls.controls = xctrls;
        }

        return ioctl(dev, VIDIOC_S_EXT_CTRLS, &ctrls);
}

#define PAN_SCALE 64
#define TILT_SCALE 64

int main(int argc, char* argv[]){
  if( argc < 3) return 0;
  printf("set pan:%d, tilt:%d\n", atoi(argv[1]) * PAN_SCALE,atoi(argv[2]) * TILT_SCALE);
  CvCapture *capture = 0;

  capture = cvCaptureFromCAM(0);

  int rv = pantilt(capture,atoi(argv[1]) * PAN_SCALE,atoi(argv[2]) * TILT_SCALE,0);

  printf("rv:%d\n",rv);
  return 0;
}