Better ways to create a rectangular mask by openCV

前端 未结 2 845
故里飘歌
故里飘歌 2021-02-02 12:28

Creating a mask in openCV

      /** result I want
          0 0 0 0 0 0 0 0
          0 0 0 0 0 0 0 0
          0 0 1 1 1 1 0 0
          0 0 1 1 1 1 0 0
                


        
2条回答
  •  春和景丽
    2021-02-02 13:01

    sure, there's an easier way, use the roi operator:

    cv::Mat mask = cv::Mat::zeros(8, 8, CV_8U); // all 0
    mask(Rect(2,2,4,4)) = 1;
    

    done!

提交回复
热议问题