How can I convert a cv::Mat to a gray scale in OpenCv?

前端 未结 2 1224
逝去的感伤
逝去的感伤 2020-12-24 11:11

How can I convert a cv::Mat to a gray scale?

I am trying to run drawKeyPoints func from opencv, however I have been getting an Assertion Filed error. My guess is tha

2条回答
  •  -上瘾入骨i
    2020-12-24 11:21

    Using the C++ API, the function name has slightly changed and it writes now:

    #include 
    
    cv::Mat greyMat, colorMat;
    cv::cvtColor(colorMat, greyMat, CV_BGR2GRAY);
    

    The main difficulties are that the function is in the imgproc module (not in the core), and by default cv::Mat are in the Blue Green Red (BGR) order instead of the more common RGB.

    OpenCV 3

    Starting with OpenCV 3.0, there is yet another convention. Conversion codes are embedded in the namespace cv:: and are prefixed with COLOR. So, the example becomes then:

    #include 
    
    cv::Mat greyMat, colorMat;
    cv::cvtColor(colorMat, greyMat, cv::COLOR_BGR2GRAY);
    

    As far as I have seen, the included file path hasn't changed (this is not a typo).

提交回复
热议问题