目录
opencv显示图片
imread,读取图片
?namedWindow,创建窗口
imshow,显示图片?
waitKey,等待窗口关闭
destroyAllWindows,销毁窗口
opencv显示图片
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv) {
Mat src = imread("E://images//test.jpg");
if (src.empty()) {
printf("未能找到图片\n");
return -1;
}
namedWindow("显示图片", WINDOW_AUTOSIZE);
imshow("显示图片", src);
waitKey(0);
destroyAllWindows();
return 0;
}
imread,读取图片
Mat imread( const String& filename, int flags = IMREAD_COLOR );
参数一 filename类型const String& ,是图片的位置,不能直接复制图片的位置E:\images\test.jpg,应该将'\'转换为‘/’或“//”;
参数二 flags 类型int,图片加载类型
常用有
- 默认为IMREAD_COLOR,加载彩色图片
- IMREAD_UNCHANGED 原样加载,新版已废弃
- IMREAD_GRAYSCALE转换为灰色图片
- IMREAD_ANYDEPTH 加载原深度
- IMREAD_ANYCOLOR 加载原颜色
-1 | IMREAD_UNCHANGED?????????? | If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation. | 0 | IMREAD_GRAYSCALE?????????? | If set, always convert image to the single channel grayscale image (codec internal conversion). | 1 | IMREAD_COLOR?????????????? | If set, always convert image to the 3 channel BGR color image. | 2 | IMREAD_ANYDEPTH??????????? | If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. | 4 | IMREAD_ANYCOLOR??????????? | If set, the image is read in any possible color format. | 8 | IMREAD_LOAD_GDAL?????????? | If set, use the gdal driver for loading the image. | 16 | IMREAD_REDUCED_GRAYSCALE_2 | If set, always convert image to the single channel grayscale image and the image size reduced 1/2. | 17 | IMREAD_REDUCED_COLOR_2???? | If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. | 32 | IMREAD_REDUCED_GRAYSCALE_4 | If set, always convert image to the single channel grayscale image and the image size reduced 1/4. | 33 | IMREAD_REDUCED_COLOR_4???? | If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. | 64 | IMREAD_REDUCED_GRAYSCALE_8 | If set, always convert image to the single channel grayscale image and the image size reduced 1/8. | 65 | IMREAD_REDUCED_COLOR_8???? | If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. | 128 | IMREAD_IGNORE_ORIENTATION? | If set, do not rotate the image according to EXIF's orientation flag. |
?namedWindow,创建窗口
void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);
?参数一winname类型const String& ,窗口名称
参数二flags类型flags,窗口类型
WINDOW_NORMAL????? | the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size. | WINDOW_AUTOSIZE??? | the user cannot resize the window, the size is constrainted by the image displayed. | WINDOW_OPENGL????? | window with opengl support. | WINDOW_FULLSCREEN? | change the window to fullscreen. | WINDOW_FREERATIO?? | the image expends as much as it can (no ratio constraint). | WINDOW_KEEPRATIO?? | the ratio of the image is respected. | WINDOW_GUI_EXPANDED | status bar and tool bar | WINDOW_GUI_NORMAL? | old fashious way |
imshow,显示图片?
void imshow(const String& winname, InputArray mat);
?参数一winname类型const String& ,窗口名称
参数二mat类型InputArray,显示图片
waitKey,等待窗口关闭
int waitKey(int delay = 0);
参数delay,等待用户按键时间,单位毫秒,在delay时间内用户按键或等待时间超过delay,窗口自动退出,0表示一直等待用户按键
destroyAllWindows,销毁窗口
void destroyAllWindows();
|