#include
#include
using namespace std;
using namespace cv;
//图像色彩空间转换
void colorSpace(Mat &image)
{
Mat gray, hsv;
//色彩空间转换
cvtColor(image, hsv, COLOR_BGR2HSV);
cvtColor(image, gray, COLOR_BGR2GRAY);
//图片显示
imshow("HSV", hsv);
imshow("灰度", gray);
//图片保存
imwrite("C:\Users\四明\Pictures\hsv.jpg", hsv);
imwrite("C:\Users\四明\Pictures\gray.jpg", gray);
}
int main()
{
string path = "C:\Users\四明\Pictures\QQ图片20200608155343.jpg";
Mat img = imread(path);
if (img.empty())
{
cout << "加载图片失败" << endl;
return -1;
}
namedWindow("image", WINDOW_FREERATIO);
imshow("image", img);
colorSpace(img);
waitKey(0);
destroyAllWindows();
return 0;
}
效果图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)