OpenCV转换成灰度图像

OpenCV转换成灰度图像

// BGR -> Gray cv::Mat BGR2GRAY(cv::Mat img){ // get height and width int width = img.cols; int height = img.rows; cv::Mat out = cv::Mat::zeros(height,width,CV_8UC1); for(int y = 0; y< height ; y++){ for(int x = 0; x < width; x++){ out.at(y,x) = img.at(y,x)[0]*0.3 + img.at(y,x)[1]*0.59 + img.at(y,x)[1]*0.11; } } return out; }

    推荐阅读