Access pixel values within a contour boundary using OpenCV in Python

后端 未结 3 1314
自闭症患者
自闭症患者 2021-02-01 09:02

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

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 09:08

    Answer from @rayryeng is excellent!

    One small thing from my implementation is: The np.where() returns a tuple, which contains an array of row indices and an array of column indices. So, pts[0] includes a list of row indices, which correspond to height of the image, pts[1] includes a list of column indices, which correspond to the width of the image. The img.shape returns (rows, cols, channels). So I think it should be img[pts[0], pts[1]] to slice the ndarray behind the img.

提交回复
热议问题