赞
踩
Mat cv::imread ( const String & filename, //载入的图像文件名,支持一般的图像格式:bmp;dib;jpeg;jpg;jp2;png;tif;tiff等
int flags = IMREAD_COLOR //IMREAD_UNCHANGED : 如有alpha通道,不会丢失
//IMREAD_GRAYSCALE :载入图像转换为单通道灰度图
//IMREAD_COLOR :缺省,载入图像转换为三通道BGR图
//IMREAD_ANYDEPTH:当输入具有相应的深度时返回16位/ 32位图像,否则将其转换为8位
//IMREAD_ANYCOLOR:以任何可能的颜色格式读取图像
//IMREAD_ANYDEPTH|IMREAD_ANYCOLOR:无损载入
);
读多幅图像
bool cv::imreadmulti (const String &filename, std::vector< Mat > &mats, int flags=IMREAD_ANYCOLOR)void cv::imshow ( const String & winname, //窗口名
InputArray mat //显示的图像
);
- #include <opencv.hpp>
- using namespace cv;
-
-
- int main()
- {
- String fileName = "e:\\qetang\\Studyopencv\\images\\ox.jpg";
-
-
- Mat imgSrc = imread(fileName);
- imshow("imread", imgSrc);
-
-
- try {
- imwrite("e:\\qetang\\Studyopencv\\images\\ox.png", imSrc);
- }
- catch (cv::Exception& ex) {
- fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
- return 1;
- }
- fprintf(stdout, "Saved PNG file with alpha data.\n");
-
-
- waitKey(0);
-
-
- return 0;
- }
- cv::String fileName = "e:\\qetang\\studyopencv\\images\\ox.jpg";
- Mat imgSrc = imread(fileName);
-
-
- namedWindow("view", WINDOW_AUTOSIZE);
- HWND hWnd = (HWND)cvGetWindowHandle("view");
- HWND hParent = ::GetParent(hWnd);
- ::SetParent(hWnd, GetDlgItem(IDC_STATIC_PIC)->m_hWnd);
- ::ShowWindow(hParent, SW_HIDE);//将控件句柄设置为窗口的父句柄
-
-
- CRect rect;
- GetDlgItem(IDC_STATIC_PIC)->GetClientRect(&rect);
- if (!imgSrc.empty())
- {
- Mat imgDst;
- cv::resize(imgSrc, imgDst, cv::Size(rect.Width(), rect.Height()));//将图片调整为控件大小显示
- imshow("view", imgDst);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。