openCV Video Stabilizer

Home Forums Forums Technical Support for BerryIMU openCV Video Stabilizer

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4390
    Guido
    Participant

    Hi,
    I’m trying to make a realtime video stabilization with raspberry pi 2 + berry IMU + picamera and openCV.

    Using your python code to get values, I use “CFangleY” to stabiliza the rotation of the image from camera and it works good but with some noise. So i made a kalman function that you made in c++ but in python. It work very well for noise values but it’s very slow and if i modify the DT or R_angle the noise return.
    Could you give me suggestions to make it better?

    This is a video on how it works:

    In the video you can see the noise value that de-stabilize the image from horizon.
    (here I use the CFangleY values to rotate the image from picamera and not the kalman filter)

    Thanks

    #4401
    Mark Williams
    Keymaster

    Hi, sorry for the late reply.. our Forum wasn’t sending us notifications of new posts.

    Do you know C? it would be better to run the code in C, as you will be able to get better timed loops.
    Looking at your video I can see that the loop isn’t constant, this would affect the values for the gyro.
    This is one of the problems with Python. Where as C, you will be able to run perfectly time loops.

    Look at applying low pass, high pass or a median filter to your raw data before calculating the angles.

    I have code for a low pass filter and median below. It is being used for compass, but you can try and test it with gyro and accel values..

    It is also ideal to print out your pre filtered values and then post filtered values and plot them in a graph. (i use excel) and you should be able to see the noise reduction.

    BTW: are you willing to share your Python code for the Kalman filter? I would love to add it to our GIT repo.

    
    Low Pass
    float kLowPassFilterFactor = 0.1;
    float kHighPassFilterFactor = 0.1;
    *mag_raw =    *mag_raw  * kLowPassFilterFactor + oldXMagRawValue*(1 - kLowPassFilterFactor);
    *(mag_raw+1) =    *(mag_raw+1)  * kLowPassFilterFactor + oldYMagRawValue*(1 - kLowPassFilterFactor);
    *(mag_raw+2) =    *(mag_raw+2)  * kLowPassFilterFactor + oldZMagRawValue*(1 - kLowPassFilterFactor);
    oldXMagRawValue = *mag_raw;
    oldYMagRawValue = *(mag_raw+1);
    oldZMagRawValue = *(mag_raw+2);
    Median
    #define FILTERED_LP 1
    #define FILTERED_M 2
    #define  MEDIANTABLESIZE 3
    		for (f = MEDIANTABLESIZE-1; f > 0 ; f--){
    			medianTable1.x[f] = medianTable1.x[f-1];
    			medianTable1.y[f] = medianTable1.y[f-1];
    			medianTable1.z[f] = medianTable1.z[f-1];
    		}
    		medianTable1.x[0] = *mag_raw;
    		medianTable1.y[0] = *(mag_raw+1);
    		medianTable1.z[0] = *(mag_raw+2);
    		medianTable2 = medianTable1;
    		qsort(medianTable2.x, MEDIANTABLESIZE, sizeof(int), cmpfunc);
    		qsort(medianTable2.y, MEDIANTABLESIZE, sizeof(int), cmpfunc);
    		qsort(medianTable2.z, MEDIANTABLESIZE, sizeof(int), cmpfunc);
    		*mag_raw  = medianTable2.x[(int)MEDIANTABLESIZE/2];
    		*(mag_raw+1)  = medianTable2.y[(int)MEDIANTABLESIZE/2];
    		*(mag_raw+2)  = medianTable2.z[(int)MEDIANTABLESIZE/2];

    Mark --OzzMaker.com --

    #6979
    Guido
    Participant

    I’m sorry for late reply ๐Ÿ™ and sorry for my dirty code, i attached the python file.

    I used many codes from other people, one is by http://nghiaho.com/?p=2093

    • This reply was modified 4 years, 10 months ago by Guido.
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Blip, blop, bloop…