当前位置:网站首页>Opencv learning basic functions
Opencv learning basic functions
2022-07-26 07:07:00 【Heihei_ study】
Catalog
One 、 Color change
cvtColor(InputArray src,outputArray dst,int code)
The first parameter is the input image ;
The second parameter is the output image ;
The third parameter is the identifier of color space conversion ( See table for details );
example : Image converted to grayscale

int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\test.png";
Mat Img = imread(path);
Mat ImgGray;
cvtColor(Img, ImgGray, COLOR_BGR2GRAY);
imshow("Image", Img);
imshow("Image Gray", ImgGray);
waitKey(0);
return 0;
}Two 、 Gaussian blur


API explain :
Parameter interpretation :
. InputArray src: The input image , It can be Mat type , The image depth is CV_8U、CV_16U、CV_16S、 CV_32F、CV_64F.
. OutputArray dst: Output image , Same type and size as the input image .
. Size ksize: Gaussian kernel size , This size with the first two filters kernel Different sizes ,ksize.width and ksize.height It can be different but the two values must be positive and odd , If these two values are 0, Their value will be sigma Calculation .
. double sigmaX: The Gaussian kernel function is in X Standard deviation in direction
. double sigmaY: The Gaussian kernel function is in Y Standard deviation in direction , If sigmaY yes 0, Then the function will automatically sigmaY The value of is set to and sigmaX The same value , If sigmaX and sigmaY All are 0, These two values will be determined by ksize.width and ksize.height Come by calculation . For details, please refer to getGaussianKernel() Function to see the details . It is suggested that size、sigmaX and sigmaY All designated .
. int borderType=BORDER_DEFAULT: Infer some convenient mode of image external pixels , Have default values BORDER_DEFAULT, If there is no special need, don't change it Change , For details, please refer to borderInterpolate() function .
![]()

int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\test.png";
Mat Img = imread(path);
Mat ImgGray,ImgBlur;
cvtColor(Img, ImgGray, COLOR_BGR2GRAY);
GaussianBlur(ImgGray, ImgBlur, Size(11, 11), 3, 3);
imshow("Image", Img);
imshow("Image Gray", ImgGray);
imshow("Image Blur", ImgBlur);
waitKey(0);
return 0;
}3、 ... and 、 Edge test
void Canny( InputArray image,
OutputArray edges,
double threshold1,
double threshold2,
int apertureSize = 3,
bool L2gradient = false);


int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\test.png";
Mat Img = imread(path);
Mat ImgGray,ImgBlur,ImgCanny,ImgDil,ImgErode;
cvtColor(Img, ImgGray, COLOR_BGR2GRAY);
GaussianBlur(ImgGray, ImgBlur, Size(11, 11), 3, 3);
Canny(ImgBlur, ImgCanny, 30, 60);
imshow("Image", Img);
imshow("Image Gray", ImgGray);
imshow("Image Blur", ImgBlur);
imshow("Image Canny", ImgCanny);
waitKey(0);
return 0;
}Four 、 expansion

( notes : First, we should build one that can be used for expansion kernel)
int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\test.png";
Mat Img = imread(path);
Mat ImgGray,ImgBlur,ImgCanny,ImgDil,ImgErode;
cvtColor(Img, ImgGray, COLOR_BGR2GRAY);
GaussianBlur(ImgGray, ImgBlur, Size(11, 11), 3, 3);
Canny(ImgBlur, ImgCanny, 30, 60);
Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));
dilate(ImgCanny, ImgDil, kernel);
imshow("Image", Img);
imshow("Image Gray", ImgGray);
imshow("Image Blur", ImgBlur);
imshow("Image Canny", ImgCanny);
imshow("Image dilate", ImgDil);
waitKey(0);
return 0;
}Four 、 corrosion

int main() {
string path = "C:\\Users\\Rong\\Desktop\\Resources\\test.png";
Mat Img = imread(path);
Mat ImgGray,ImgBlur,ImgCanny,ImgDil,ImgErode;
cvtColor(Img, ImgGray, COLOR_BGR2GRAY);
GaussianBlur(ImgGray, ImgBlur, Size(11, 11), 3, 3);
Canny(ImgBlur, ImgCanny, 30, 60);
Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));
dilate(ImgCanny, ImgDil, kernel);
erode(ImgDil, ImgErode, kernel);
imshow("Image", Img);
imshow("Image Gray", ImgGray);
imshow("Image Blur", ImgBlur);
imshow("Image Canny", ImgCanny);
imshow("Image dilate", ImgDil);
imshow("Image erode", ImgErode);
waitKey(0);
return 0;
}边栏推荐
- 【数据库】CTE(Common Table Expression(公共表表达式))
- 问题:Can‘t download sh shellcheck. Please install it manually及shell脚本的一些命令使用
- 火焰图分析Flink反压
- Image annotation software reference
- [arm learning (8) AXF tool analysis]
- LTS(Light-Task-Scheduler)
- Idea -- use @slf4j to print logs
- "XXXX" is running, which may cause the system to jam, reduce the standby time, and click Close "
- Screen: frame paste, 0 fit, full fit
- String and memory functions
猜你喜欢
![[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

Question: can't download sh shellcheck Please install it manually and some commands of shell script

What are the basics of getting started with spot silver

C # use log4net plug-in to output logs to files

Yolov5 improvements: add attention mechanism (video tutorial)

Delete ^m from VIM

A guide for you to fully use TS

Common CMD instructions

Basic operations and common functions of MySQL table creation

Drools (3): drools basic syntax (1)
随机推荐
优炫数据库JDBC打开日志方式有哪些
【硬十宝典】——7.2【动态RAM】DDR4与DDR3区别解析
NPM command
Do you know what "parts" MySQL contains?
Manifest merger failed with multiple errors, see logs
每周小贴士#142:多参数构造函数和explicit
NIO实现
Is it safe to invest in treasury bonds in 2022? How do individuals buy treasury bonds?
Shell programming
An album has been released, from introductory practical demonstration to advanced live Q & A, playing with container service so easy~
Shared lock
IR tool in JIT and download, compile and use of jitwatch
What to pay attention to when using German chicks for the first time
微信小程序 - 从入门到入土
NiO implementation
vulnhub Lampião: 1
Acwing- daily question
Is there any online account opening process of Huatai Securities? Is online account opening safe
[untitled] reprint
MySQL table read lock