#include "opencv2/opencv.hpp"
#include
using namespace cv;
using namespace std;
int main()
{
//图片属性下的路径,E:\Progarm\Images\17.jpg,斜杠需要修改
//需要修改为\\或者/或者//
Mat img = imread("E:/Progarm/Images/17.jpg", IMREAD_COLOR);//IMREAD_COLOR==0单通道,灰度图
Mat gray = imread("E:\\Progarm\\Images\\17.jpg", IMREAD_GRAYSCALE);//IMREAD_GRAYSCALE==1三通道,彩图,可不写默认值为1
namedWindow("img",WINDOW_NORMAL);//标注的,显示图片全景,可调整窗口的大小(没有限制),整幅图跟着缩放,/也可以用来将全屏窗口切换到正常大小。
namedWindow("gray", WINDOW_AUTOSIZE); //自动,不能调整窗口的大小,如果图片太大,只能显示窗口内的一部分,该大小受显示图像的限制。
imshow("img",img);
imshow("gray", gray);
waitKey(0);//(图像显示窗口关闭之后)等待按键按下,程序结束
return 0;
}
如图,彩色图片窗口是WINDOW_NORMAL,可以自由鼠标拉伸大小
灰色图WINDOW_AUTOSIZE,不可调节
enum ImreadModes {
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
};
enum WindowFlags {
WINDOW_NORMAL = 0x00000000, //!< the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.
WINDOW_AUTOSIZE = 0x00000001, //!< the user cannot resize the window, the size is constrainted by the image displayed.
WINDOW_OPENGL = 0x00001000, //!< window with opengl support.
WINDOW_FULLSCREEN = 1, //!< change the window to fullscreen.
WINDOW_FREERATIO = 0x00000100, //!< the image expends as much as it can (no ratio constraint).
WINDOW_KEEPRATIO = 0x00000000, //!< the ratio of the image is respected.
WINDOW_GUI_EXPANDED=0x00000000, //!< status bar and tool bar
WINDOW_GUI_NORMAL = 0x00000010, //!< old fashious way
};
The function destroyWindow destroys the window with the given name.
@param winname Name of the window to be destroyed.
*/
CV_EXPORTS_W void destroyWindow(const String& winname);
/** @brief Destroys all of the HighGUI windows.
The function destroyAllWindows destroys all of the opened HighGUI windows.
*/
CV_EXPORTS_W void destroyAllWindows();