How do i turn off Kinect RGB auto exposure

Hi,

I’m writing a program that uses multiple kinects. To avoid the interference I’m serially snapping a frame from each kinect and moving on to the next one. So i make the kinect quickly open, snap an image and close. All works fine and I like to keep my kinect camera open time less. However kinect rgb camera adaptive exposure takes like a second or two to set the exposure. Since I open the camera only for 500 milliseconds I get a dark image. Is there a way I can control the exposure and set it to a value as soon as the kinect opens without letting the camera figure it out by itself?

Will this have to be a feature request?

Since I am mainly running the kinect on a raspberry pi2 I would hope the addon supports the exposure control on it. I’m asking because the tilt of the kinect motor for now does not go below 0 degrees on the Pi2 but works fine on windows and linux.

Thanks.

Hi @usama_, assuming you’re using libfreenect, see:
https://github.com/OpenKinect/libfreenect/pull/332

You can freenect_set_flag(dev, FREENECT_AUTO_EXPOSURE, FREENECT_ON). However, this function seems not wrapped by ofxKinect, so you probably need to edit ofxKinect::open() or something to experiment (and better submit a pull request when you made a wrapper in ofxKinect!).

Btw, I tried to open, capture, and close Kinect to get a snapshot before to get RGB/IR/depth images. I recall this process takes more than a second, so your system captures a static object?

Hey thanks @micuat. Yes I was thinking of doing the same. I came across this forum where they have patches for libfreenect but I think it might be an old post since it’s of Aug 2012 and I can use the freenect_set_flag() to do what I want now. Just that there was this issue Auto exposure (gain), auto white balance switching does not work in freenect-glview example and this is of April 2014. Let me try to add this to the wrapper.

Btw, you are right, 500 milliseconds was only working for the first kinect which was already open. i saw that 1000 millisec was working but i got black/dark images since the auto exposure didn’t kick in. 1500 and later milliseconds was fine… and my object which may or may not be static. That is the whole issue. Else i was okay with the auto exposure.

FYI, what I did before is capture RGB and then reload for IR capture:

kinect.init();
while( !kinect.isFrameNewVideo() ) {
	kinect.update();
	image.setFromPixels(kinect.getPixelsRef());
	ofSleepMillis(500);
}
kinect.close();

image.saveImage(path);

// re-open with IR mode
kinect.init(true);

kinect.open();		// opens first available kinect

hmm,

so since i knew that I wont be using the auto exposure and other things I added these lines to the open function in ofxKinect.cpp

in

bool ofxKinect::open(int id)

and in

bool ofxKinect::open(string serial)



    freenect_set_flag(kinectDevice, FREENECT_AUTO_EXPOSURE, FREENECT_OFF);
    freenect_set_flag(kinectDevice, FREENECT_AUTO_WHITE_BALANCE, FREENECT_OFF);
    freenect_set_flag(kinectDevice, FREENECT_RAW_COLOR, FREENECT_OFF);

and after building it I saw no change :frowning: it still seems to be on auto exposure

so the function becomes

//--------------------------------------------------------------------
bool ofxKinect::open(int id) {
    if(!bGrabberInited) {
        ofLogWarning("ofxKinect") << "open(): cannot open, init not called";
        return false;
    }

    if(!kinectContext.open(*this, id)) {
        return false;
    }

    if(serial == "0000000000000000") {
        bHasMotorControl = false;
        //if we do motor control via the audio device ( ie: 1473 or k4w ) and we have firmware uploaded
        //then we can do motor stuff! :)
        if( kinectDevice->motor_control_with_audio_enabled ){
            bHasMotorControl = true;
        }else{
            ofLogVerbose("ofxKinect") << "open(): device " << deviceId << " does not have motor control";
        }
    }
    else {
        bHasMotorControl = true;
    }

    lastDeviceId = deviceId;
    timeSinceOpen = ofGetElapsedTimef();
    bGotData = false;

    freenect_set_user(kinectDevice, this);
    freenect_set_depth_buffer(kinectDevice, depthPixelsRawBack.getPixels());
    freenect_set_video_buffer(kinectDevice, videoPixelsBack.getPixels());
    freenect_set_depth_callback(kinectDevice, &grabDepthFrame);
    freenect_set_video_callback(kinectDevice, &grabVideoFrame);

//adding auto exposure OFF code here
    freenect_set_flag(kinectDevice, FREENECT_AUTO_EXPOSURE, FREENECT_OFF);         
    freenect_set_flag(kinectDevice, FREENECT_AUTO_WHITE_BALANCE, FREENECT_OFF);
    freenect_set_flag(kinectDevice, FREENECT_RAW_COLOR, FREENECT_OFF);

    startThread(true, false); // blocking, not verbose

    return true;
}

Seconding @usama_'s troubles here. I’m also wanting to turn off autoexposure on a Kinect and running the code he pasted above doesn’t appear to change any behavior. (I haven’t investigated the cmos traffic, as is referred to on this related GitHub discussion.)

Anybody have any ideas? My project would be greatly improved if I could manage lighting internally to the Kinect rather than having to manually shade and light my work area!

@rzach Auto-exposure and auto-white balancing can only be turned off on “Kinect for Windows” devices, not the original XBox 360 Kinect connected to a pc, it seems…