[学习OpenCV攻略][011][显示图片]

学习资料:

http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/tutorials.html

 

包含头文件

core.hpp:包含了基本的定义和库

highgui.hpp:包含了基本的输入输出操作

1
2
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

 

创建一个矩阵对象来存储和载入图像数据

1
Mat image;

 imread函数的第一个参数时载入图像的文件名,第二个参数时图像的格式。格式可以为:

CV_LOAD_IMAGE_UNCHANGED (<0) loads the image as is (including the alpha channel if present)

CV_LOAD_IMAGE_GRAYSCALE ( 0) loads the image as an intensity one

CV_LOAD_IMAGE_COLOR (>0) loads the image in the RGB format

1
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

 

创建窗口

CV_WINDOW_AUTOSIZE is the only supported one if you do not use the Qt backend. In this case the window size will take up the size of the image it shows. No resize permitted!

CV_WINDOW_NORMAL on Qt you may use this to allow window resize. The image will resize itself according to the current window size. By using the | operator you also need to specify if you would like the image to keep its aspect ratio (CV_WINDOW_KEEPRATIO) or not (CV_WINDOW_FREERATIO).

1
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.

 

显示图片

1
imshow( "Display window", image );   // Show our image inside it.

  

等待显示

1
waitKey(0);   // Wait for a keystroke in the window

  

编译运行

1
./DisplayImage HappyFish.jpg

 

posted @   盛夏夜  阅读(217)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示