Monday, January 23, 2012

HDR on Canon 50D! (hacking a hack!)

Finally! The Magic Lantern Firmware had solved my ultimate problem! HDR video on a DSLR! My Lovely 50D is like super powered now :) !

I had been working with the PointGrey Flea3 camera for the HDR video, but the resolution and the noise performance are just too disappointing! 640x480, 10bits A/D... The only great thing about that camera would be the frame rate! 120fps.

Here I will show you how to compile the Magic Lantern Firmware on Mac OS X (10.6.8) with Macport!

Basically you only need to install through Macport using the following command.

sudo port install arm-elf-gcc 

arm-elf-gcc @4.6.1 (cross, devel)
    gcc cross-compilers for arm-elf, with newlib runtime library.

Then, you will need to grab the source code from the official website or directly from my hacked version that runs on mac


Well, good luck if you can get any support from that team? I tried to email them but I believe they are all busy working on something? and ignored me totally.

Anyways, today I will show you how to hack the camera firmware hack so it will use alternating shutter speed instead of ISO to create the HDR video sequence. The key advantage is we can get better noise performance by utilizing a much lower ISO settings. (i.e., using ISO 100 constantly instead of alternating ISO 100 and ISO 1600).

#ifdef CONFIG_500D
#define MOVREC_STATE (*(struct state_object **)0x7AF4)
#define LV_STRUCT_PTR 0x1d78
#define FRAME_ISO *(uint16_t*)(MEM(LV_STRUCT_PTR) + 0x56)

void hdr_step()
    if (!hdrv_enabled) return;
    if (!lv) return;
    if (!is_movie_mode()) return;
    static int odd_frame = 0;
    static int frame;
    if (recording)
        #ifdef MOVREC_STATE // sync by Canon frame number
        frame = MVR_FRAME_NUMBER;
        if (!HALFSHUTTER_PRESSED) odd_frame = (frame / video_mode_fps) % 2;

    int iso_low, iso_high;
    hdr_get_iso_range(&iso_low, &iso_high);

    //if we enable the HDR mode with the same ISO settings, we will use
    //alternating shutter to accomplish the same thing
    //now we use 3 exposures- that will cover a very very wide dynamic range!!
    if(iso_high == iso_low){
     odd_frame = frame % 3;
   int shutter_speed = 8000/16;
  }else if(odd_frame==1){
   int shutter_speed = 8000;
   int shutter_speed = 8000/16/16;
        odd_frame = frame % 2;
        //int iso = iso_high;
        int iso = odd_frame ? iso_low : iso_high; // ISO 100-1600
        FRAME_ISO = iso | (iso << 8);
    //FRAME_SHUTTER_TIMER = 8000/16*10; //lower the max by 4 stops
    //~ *(uint8_t*)(lv_struct + 0x54) = iso;

I have packaged everything for this hack and you can try compiling this using

make 50D

make install

I haven't confirmed if it will compile and run on the 60D or other DSLRs. If you give me your camera, maybe I will give that a try? :)

Demo Video:
Coming up soon. I have a new real-time HDR rendering engine to present next. Follow me to get the latest update.

1 comment:

  1. it's actually a knowledge full post. thanks to shear . this post has removed my a number of wrong thing . i thing if you to-do your acctivetice you will achive much popularety.. at last..thanks.
    Information visualization Low