当前位置:网站首页>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!!!
边栏推荐
- "Series after reading" my God! It's so simple to understand throttling and anti shake~
- SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
- When OSPF specifies that the connection type is P2P, it enables devices on both ends that are not in the same subnet to Ping each other
- NGUI-UILabel
- IPv6 experiment
- 牛客网刷题网址
- 【PyTorch实战】用RNN写诗
- OSPF exercise Report
猜你喜欢

idea 2021中文乱码

MPLS experiment

【统计学习方法】学习笔记——支持向量机(下)

消息队列消息丢失和消息重复发送的处理策略

SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)

Cookie

Decrypt gd32 MCU product family, how to choose the development board?

@What happens if bean and @component are used on the same class?

盘点JS判断空对象的几大方法

RHSA first day operation
随机推荐
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
Epp+dis learning road (2) -- blink! twinkle!
JS to convert array to tree data
BGP actual network configuration
Solutions to cross domain problems
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
The left-hand side of an assignment expression may not be an optional property access. ts(2779)
Object. Simple implementation of assign()
牛客网刷题网址
VSCode的学习使用
Learning and using vscode
Realize all, race, allsettled and any of the simple version of promise by yourself
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
OSPF exercise Report
Completion report of communication software development and Application
An error occurred when vscade tried to create a file in the target directory: access denied [resolved]
数据库系统原理与应用教程(010)—— 概念模型与数据模型练习题