当前位置:网站首页>opencv的四个函数
opencv的四个函数
2022-07-07 10:33:00 【什么时候上岸?】
正式开始opencv的学习了!
1.imshow
2.imread
3.cvtcolor
4.imwrite
imshow("显示窗口的名字",图像名字);//显示图片
img=imread("图片路径");//读入图片
cvtcolor(待转换的图片名字,转换后储存的图片名字,转换效果);//变换图片,如变灰度图
imwrite("路径",图片名字);//储存图片
示例代码:
源文件1
#include<tupian.h>
void demo::color_demo(Mat &image)
{
Mat hsv, gray;
cvtColor(image, hsv, COLOR_BGR2HSV);
cvtColor(image, gray, COLOR_BGR2GRAY);
imshow("灰度", gray);
imshow("HSV", hsv);
imwrite("D:/hsv.png", hsv);
imwrite("D:/gray.png", gray);
}
源文件2
#include <iostream>
#include<tupian.h>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc,char** argv)
{
Mat img;
img = imread("C:/Users/guoyongbin123/Desktop/C++/opencv4/opencv4/Lena.png");//图片路径
if (img.empty())
{
cout << "请确认图像文件名称是否正确" << endl;
return -1;
}
//Mat img1;
namedWindow("test", WINDOW_FREERATIO);
imshow("test", img);
demo me;
me.color_demo(img);
waitKey(0);
return 0;
}
头文件
#pragma once
#include<opencv2/opencv.hpp>using namespace cv;
class demo
{
public:
void color_demo(Mat &image);
};
注意:
1.把要导入的图片放在C文件同一目录。
2.把文件路径加入到包含目录,即在解决方案资源管理器找到本次的文件,右击,找到属性,VC++目录,找到包含目录,把上图的文件路径添加进去。
结果如下:
over!!!
边栏推荐
- 静态Vxlan 配置
- 2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
- SQL head injection -- injection principle and essence
- About web content security policy directive some test cases specified through meta elements
- 【统计学习方法】学习笔记——第五章:决策树
- 2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
- ENSP MPLS layer 3 dedicated line
- Customize the web service configuration file
- 广州市召开安全生产工作会议
- MPLS experiment
猜你喜欢
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
leetcode刷题:二叉树19(合并二叉树)
College entrance examination composition, high-frequency mention of science and Technology
Hi3516 full system type burning tutorial
Tutorial on principles and applications of database system (007) -- related concepts of database
How to use PS link layer and shortcut keys, and how to do PS layer link
Completion report of communication software development and Application
Solutions to cross domain problems
Processing strategy of message queue message loss and repeated message sending
随机推荐
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
千人规模互联网公司研发效能成功之路
跨域问题解决方案
2022聚合工艺考试题模拟考试题库及在线模拟考试
通讯协议设计与实现
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
[statistical learning method] learning notes - support vector machine (Part 2)
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
【统计学习方法】学习笔记——支持向量机(下)
SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
【统计学习方法】学习笔记——提升方法
Cookie
【统计学习方法】学习笔记——支持向量机(上)
idea 2021中文乱码
leetcode刷题:二叉树23(二叉搜索树中的众数)
[statistical learning methods] learning notes - improvement methods
Decrypt gd32 MCU product family, how to choose the development board?
Zhimei creative website exercise
【玩转 RT-Thread】 RT-Thread Studio —— 按键控制电机正反转、蜂鸣器
NGUI-UILabel