Calculating difference between colors

I did a script that analyze every frame of a video and puts a square with the average color of that frame. I need to trigger some function when the difference of the current and the last color is bigger than "x" value. How can I achieve this? --i tried to hex() the colors and dehex() but the detection of difference isn't working and usually shows a "0" all the time (even if the color changes a lot). This is urgent --a homework that i need to present in few hours--Thanks for any help, I really appreciate it.


  • edited May 2015 Answer ✓

    Take the red, green, and blue values of the current and previous colors

    After you have done that there is more than one way to determine if the colors are different enough beyond some threshold. One way to do it is to find the difference of the reds, the greens, and the blues and if any of them are beyond a threshold then your event happened. Another way to do it is to sum the previous frame's red / green / blue, sum the current frame's red / green / blue, and then find the difference of the two sums. The first method will probably be more sensitive while the second one will detect difference in brightness




  • thanks! really helpful.

Sign In or Register to comment.