知识点:
读取图像 - imread
显示图像 - imshow
imread
头文件 #include <opencv2/imgcodecs.hpp>
函数原型
Python:retval=cv.imread(filename[, flags])
参数
filename | Name of file to be loaded. 要读取文件的名称 |
flags | Flag that can take values of cv::ImreadModes 打开文件的方式 |
ImreadModes
Enumerator |
---|
IMREAD_UNCHANGED Python: cv.IMREAD_UNCHANGED | If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation. |
IMREAD_GRAYSCALE Python: cv.IMREAD_GRAYSCALE | If set, always convert image to the single channel grayscale image (codec internal conversion). 常用 |
IMREAD_COLOR Python: cv.IMREAD_COLOR | If set, always convert image to the 3 channel BGR color image. 常用 |
IMREAD_ANYDEPTH Python: cv.IMREAD_ANYDEPTH | If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. |
IMREAD_ANYCOLOR Python: cv.IMREAD_ANYCOLOR | If set, the image is read in any possible color format. |
IMREAD_LOAD_GDAL Python: cv.IMREAD_LOAD_GDAL | If set, use the gdal driver for loading the image. |
IMREAD_REDUCED_GRAYSCALE_2 Python: cv.IMREAD_REDUCED_GRAYSCALE_2 | If set, always convert image to the single channel grayscale image and the image size reduced 1/2. |
IMREAD_REDUCED_COLOR_2 Python: cv.IMREAD_REDUCED_COLOR_2 | If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. |
IMREAD_REDUCED_GRAYSCALE_4 Python: cv.IMREAD_REDUCED_GRAYSCALE_4 | If set, always convert image to the single channel grayscale image and the image size reduced 1/4. |
IMREAD_REDUCED_COLOR_4 Python: cv.IMREAD_REDUCED_COLOR_4 | If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. |
IMREAD_REDUCED_GRAYSCALE_8 Python: cv.IMREAD_REDUCED_GRAYSCALE_8 | If set, always convert image to the single channel grayscale image and the image size reduced 1/8. |
IMREAD_REDUCED_COLOR_8 Python: cv.IMREAD_REDUCED_COLOR_8 | If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. |
IMREAD_IGNORE_ORIENTATION Python: cv.IMREAD_IGNORE_ORIENTATION | If set, do not rotate the image according to EXIF's orientation flag. |
imshow
头文件#include <opencv2/highgui.hpp>
函数原型
Python: |
---|
| None | = | cv.imshow( | winname, mat | ) |
Parameters
winname | Name of the window. 显示图片窗口的名称,自己命名 |
mat | Image to be shown. 要显示的图片 |
视频教程 bili教程直接点击
环境配置好以后,代码如下:
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src = imread("D:/tool/opencv/opencv_tutorial_data-master/opencv_tutorial_data-master/images/hist_02.jpg");
imshow("input", src);
waitKey(0);
destroyAllWindows();
return 0;
}