图像文件读写
读文件
Mat cv::imread(const String &filename, int flags = IMREAD_COLOR)
写文件
bool cv::imwrite(const String & filename, InputArray img, const std::vector<int> ¶ms = std::vector<int>())
图像缩放
函数
void cv::resize (
InputArray src,
OutputArray dst,
Size dsize,
double fx = 0,
double fy = 0,
int interpolation = INTER_LINEAR
)
形状绘制
直线
void cv::line (
InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
折线
void cv::polylines (
InputOutputArray img,
const Point *const * pts,
const int * npts,
int ncontours,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
void cv::polylines (
InputOutputArray img,
InputArrayOfArrays pts,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
矩形
void cv::rectangle (
InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
void cv::rectangle (
InputOutputArray img,
Rect rec,
const Scalar &color,
int thickness=1,
int lineType=LINE_8,
int shift=0
)
圆形
void cv::circle (
InputOutputArray img,
Point center,
int radius,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
椭圆
void cv::ellipse (
InputOutputArray img,
Point center,
Size axes,
double angle,
double startAngle,
double endAngle,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
void cv::ellipse (
InputOutputArray img,
const RotatedRect & box,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8
)
颜色空间转换
void cv::cvtColor (
InputArray src,
OutputArray dst,
int code,
int dstCn = 0
)
物体检测
void cv::matchTemplate (
InputArray image,
InputArray templ,
OutputArray result,
int method,
InputArray mask = noArray()
)
例子
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/core/mat.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
int main(void)
{
cv::Mat src, dst;
src = cv::imread("image/lena.jpg");
if (!src.empty()) {
cv::imshow("src", src);
cv::resize(src, dst, cv::Size(0, 0), 2, 1);
if (!dst.empty()) {
cv::imshow("dst", dst);
cv::waitKey(0);
}
}
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/04c2d4e7a7ce64fd2d3707b34613455b.png)