图像色彩空间转换2
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
//图像色彩空间转换
void inrange_demo(cv::Mat& image)
{
Mat hsv;
cvtColor(image, hsv, COLOR_BGR2HSV);
//提取mask
Mat mask;
inRange(hsv, Scalar(35,43,46), Scalar(255, 255, 255), mask);
imshow("mask", mask);
Mat redback = Mat::zeros(image.size(), image.type());
redback = Scalar(40, 40, 200);
bitwise_not(mask, mask);
imshow("mask", mask);
image.copyTo(redback, mask);
imshow("roi区域提取", redback);
}
int main()
{
string path = "C:\\Users\\四明\\Pictures\\index.jpg";
Mat img = imread(path);
if (img.empty())
{
cout << "图片加载失败!" << endl;
return -1;
}
namedWindow("image", WINDOW_FREERATIO);
imshow("image", img);
inrange_demo(img);
waitKey(0);
destroyAllWindows();
return 0;
}
renderings
文章出处登录后可见!
已经登录?立即刷新