当前位置:   article > 正文

opencv学习笔记-图像载入、显示、保存_opencv窗口的父句柄是什么

opencv窗口的父句柄是什么
图像载入、显示、保存


头文件
#include <opencv.hpp>

缺省:
#define HAVE_OPENCV_CALIB3D
#define HAVE_OPENCV_CORE
#define HAVE_OPENCV_DNN
#define HAVE_OPENCV_FEATURES2D
#define HAVE_OPENCV_FLANN
#define HAVE_OPENCV_HIGHGUI
#define HAVE_OPENCV_IMGCODECS
#define HAVE_OPENCV_IMGPROC
#define HAVE_OPENCV_ML
#define HAVE_OPENCV_OBJDETECT
#define HAVE_OPENCV_PHOTO
#define HAVE_OPENCV_SHAPE
#define HAVE_OPENCV_STITCHING
#define HAVE_OPENCV_SUPERRES
#define HAVE_OPENCV_VIDEO
#define HAVE_OPENCV_VIDEOIO
#define HAVE_OPENCV_VIDEOSTAB


命名空间:
using namespace cv;

图像载入到Mat类:

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                //显示的图像

);


void cv::namedWindow (const String &winname, int flags=WINDOW_AUTOSIZE);

flags:
WINDOW_NORMAL 
WINDOW_AUTOSIZE 
WINDOW_OPENGL 
WINDOW_FULLSCREEN 
WINDOW_FREERATIO 
WINDOW_KEEPRATIO 
WINDOW_GUI_EXPANDED 
WINDOW_GUI_NORMAL 


窗口上可以添加,Button,TrackBar,Mouse event


bool cv::imwrite (const String &filename, InputArray img, const std::vector< int > &params=std::vector< int >());


扩展名存成某种格式图像,格式参数:


IMWRITE_JPEG_QUALITY 0-100
IMWRITE_PNG_COMPRESSION 0-9


  1. #include <opencv.hpp>
  2. using namespace cv;
  3. int main()
  4. {
  5. String fileName = "e:\\qetang\\Studyopencv\\images\\ox.jpg";
  6. Mat imgSrc = imread(fileName);
  7. imshow("imread", imgSrc);
  8. try {
  9. imwrite("e:\\qetang\\Studyopencv\\images\\ox.png", imSrc);
  10. }
  11. catch (cv::Exception& ex) {
  12. fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
  13. return 1;
  14. }
  15. fprintf(stdout, "Saved PNG file with alpha data.\n");
  16. waitKey(0);
  17. return 0;
  18. }




MFC下显示图像


  1. cv::String fileName = "e:\\qetang\\studyopencv\\images\\ox.jpg";
  2. Mat imgSrc = imread(fileName);
  3. namedWindow("view", WINDOW_AUTOSIZE);
  4. HWND hWnd = (HWND)cvGetWindowHandle("view");
  5. HWND hParent = ::GetParent(hWnd);
  6. ::SetParent(hWnd, GetDlgItem(IDC_STATIC_PIC)->m_hWnd);
  7. ::ShowWindow(hParent, SW_HIDE);//将控件句柄设置为窗口的父句柄
  8. CRect rect;
  9. GetDlgItem(IDC_STATIC_PIC)->GetClientRect(&rect);
  10. if (!imgSrc.empty())
  11. {
  12. Mat imgDst;
  13. cv::resize(imgSrc, imgDst, cv::Size(rect.Width(), rect.Height()));//将图片调整为控件大小显示
  14. imshow("view", imgDst);
  15. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/100584
推荐阅读
相关标签
  

闽ICP备14008679号