Dealing with pixels in contours (OpenCV)?

后端 未结 3 1258
一生所求
一生所求 2020-12-30 06:49

I have retrieved a contour from an image and want to specifically work on the pixels in the contour. I need to find the sum (not area) of the pixel values in the contour. Op

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 07:19

    If I understand right you want to sum all the pixel intensities from a gray image that are inside a contour. If so, the method that i think of is to draw that contour on a blank image and fill it , in so making yourself a mask. After that to optimize the process you can also compute the bounding rect of the contour with :

    CvRect cvBoundingRect(CvArr* points, int update=0 );
    

    After this you can make an intermediate image with :

    void cvAddS(const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL);
    

    using the value 0, the mask obtained from the contour and setting before as ROI the bounding rect.

    After this, a sum on the resulting image will be a little faster.

提交回复
热议问题