We all have come across various OpenCV libraries and have been using them to get the brightest area’s or spot’s on images. Apparently, we have our cv2.minMaxLoc(…) in OpenCV to do this and get our location. But have you ever wondered could we employ an dynamic programming method for this approach.

This is a problem that’s called the maximum contiguous subarray sum in Algorithms. We usually have a 1d array and are asked to find the maximum sum that’s possible out of all subarrays of that array. We can employ brute force method to solve it in O(n²) times or a divide and conquer to get it in O(log n) times. We will use dynamic programming for our approach to get it in O(n) times.

Coming to our problem, we have an image which we can read using an OpenCV method and we process the image to get a 2D array out of it.

#data-structures #python #opencv #dynamic-programming #kadanes-algorithm

Dynamic Programming with OpenCV : Implementing Kadane’s Algorithm
1.60 GEEK