还是老习惯,分三步走。第一步,功能说明。第二步,结果图显示,第三步,API详解。第四步,代码展示(注释很详细,保证所有有C++基础的人都可以看懂。)

第一步,功能说明cvtcolor()函数是一个颜色空间转换函数,可以实现RGB颜色向HSV,HSI等颜色空间转换。也可以转换为灰度图。

第二步,结果图显示:我们使用了两种方式转换,下面是不同方式的效果图。图1是原图。图2图3分别是效果图,转换方式是他们窗口的名字。

第三步,API详解:void cv::cvtColor(cv::InputArray src, // 输入图

cv::OutputArray dst, // 输出图

int code, // 颜色映射类型,可以查表得到,有很多

int dstCn = 0 // 输出的通道数 (0='automatic'),我们可以使用默认值,什么都不写。

第四步,代码展示:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) 
	{
	 Mat src,dst,dst1;
	 src = imread("image5.jpg");

//判断图片是否载入成功
	if (src.empty()) 
	{
		printf("图片加载失败\n");
		system("pause");
	}
	imshow("原图",src);

	cvtColor(src,dst,CV_BGR2GRAY);//转换方式1,这种是转换为灰度图,经常使用,需要记住
	cvtColor(src,dst1,COLOR_BGR2Lab);//转换方式2

	imshow("CV_BGR2GRAY转换后",dst);
	imshow("COLOR_BGR2Lab转换后",dst1);

	waitKey(0);
	return 0;
}

本人也是学习opencv不久,如有错误,请各位前辈指导。大家如果觉得我的博客讲解通俗易懂,请进我博客专栏查看更多API讲解。博客地址https://blog.csdn.net/fanjiule   。

GitHub 加速计划 / opencv31 / opencv
211
14
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:9 个月前 )
cd0699a3 imgcodecs: jpegxl: support lossless compression #27384 Close https://github.com/opencv/opencv/issues/27382 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake 1 天前
e92cfb35 Add HoughCirclesWithAccumulator binding #27389 ### Pull Request Readiness Checklist Fix #27377 See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐