Home › Forums › Forums › Technical Support for BerryIMU › openCV Video Stabilizer
- This topic has 2 replies, 2 voices, and was last updated 5 years, 6 months ago by Guido.
- AuthorPosts
- January 3, 2016 at 9:07 am #4390GuidoParticipant
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
January 9, 2016 at 12:57 pm #4401Mark WilliamsKeymasterHi, 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 --
November 23, 2017 at 7:04 am #6979GuidoParticipantI’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
- AuthorPosts
- You must be logged in to reply to this topic.