I\'m using OpenCV 3.0.0 on Python 2.7.9. I\'m trying to track an object in a video with a still background, and estimate some of its properties. Since there can be multiple movi
I am sorry I cannot add this as a comment in the first correct answer since I have not enough reputation to do so.
Actually, there is a little improvement in the nice code from above: we can skip the line in which we were getting the points because of both grayscale image and np.zeros temp image have the same shape, we could use that 'where' inside the brackets directly. Something like this:
# (...) opening image, converting into grayscale, detect contours (...)
intensityPer = 0.15
for c in contours:
temp = np.zeros_like(grayImg)
cv2.drawContours(temp, [c], 0, (255,255,255), -1)
if np.mean(grayImg[temp==255]) > intensityPer*255:
pass # here your code
By this sample, we assure the mean intensity of the area within the contour will be at least 15% of the maximum intensity