How to fill OpenCV image with one solid color?

前端 未结 8 1464
陌清茗
陌清茗 2020-12-01 11:32

How to fill OpenCV image with one solid color?

8条回答
  •  感情败类
    2020-12-01 12:04

    Using the OpenCV C API with IplImage* img:

    Use cvSet(): cvSet(img, CV_RGB(redVal,greenVal,blueVal));

    Using the OpenCV C++ API with cv::Mat img, then use either:

    cv::Mat::operator=(const Scalar& s) as in:

    img = cv::Scalar(redVal,greenVal,blueVal);
    

    or the more general, mask supporting, cv::Mat::setTo():

    img.setTo(cv::Scalar(redVal,greenVal,blueVal));
    

提交回复
热议问题