需要说明的是在OpenCV3中已经将imread()和imwrite()函数转移到imgcodecs模块中,因此读写图像时,需要包含imgcodecs.hpp头文件,但是highgui.hpp头文件中已经包含了该头文件,因此不用再显式包含了。

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // OpenCV includes
  6. #include <opencv2/core/core.hpp>
  7. #include <opencv2/highgui/highgui.hpp>
  8. using namespace cv;
  9.  
  10. int main(int argc, const char** argv)
  11. {
  12. // Read images
  13. Mat color = imread("../images/eating.jpg");
  14. Mat gray = imread("../images/eating.jpg", );
  15.  
  16. // Write images
  17. imwrite("gray.jpg", gray);
  18.  
  19. // Get same pixel with opencv function
  20. int myRow = color.cols - ;
  21. int myCol = color.rows - ;
  22. Vec3b pixel = color.at<Vec3b>(myRow, myCol);
  23. cout << "Pixel Value (B, G, R): ("
  24. << (int)pixel[] << ", "
  25. << (int)pixel[] << ", "
  26. << (int)pixel[] << ")" << endl;
  27.  
  28. // Show images
  29. imshow("Color Image", color);
  30. imshow("Gray Image", gray);
  31.  
  32. // Wait for any key
  33. waitKey();
  34. return ;
  35. }

显示的图片效果如下:

OpenCV3读取、写入和保存图像的更多相关文章

  1. opencv3读取视频并保存为图片

    #include <iostream> #include <vector> #include <opencv2/opencv.hpp> using namespac ...

  2. Vtk读取并显示保存图像

    (1):Vtk读取并显示图像:三种方法 转载:未知出处 转载:用VTK显示平面图片:http://blog.csdn.net/tonylk/article/details/464881 用到vtkJP ...

  3. OpenCV 读取、修改、保存图像

    代码如下: #include <cv.h> #include <highgui.h> using namespace cv; int main( int argc, char* ...

  4. C#中创建、打开、读取、写入、保存Excel的一般性代码

    ---转载:http://hi.baidu.com/zhaocbo/item/e840bcf941932d15fe358228 1. Excel对象微软的Excel对象模型包括了128个不同的对象,从 ...

  5. python使用h5py读取mat文件数据,并保存图像

    1 安装h5py sudo apt-get install libhdf5-dev sudo pip install h5py 假设你已经安装好python和numpy模块 2 读取mat文件数据 i ...

  6. matlab数字图像处理-冈萨雷斯-读取,显示,保存图像

    图像读取:imread(filename) 显示图像‘ 显示多幅图像 保存图像 b 计算压缩比

  7. opencv-python教程学习系列2-读取/显示/保存图像

    前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍图像的读取.显示以及保存,坚持学习,共同进步. 系列教程参照OpenCV-Python中文教程: ...

  8. Java--多线程读取网络图片并保存在本地

    本例用到了多线程.时间函数.网络流.文件读写.正则表达式(在读取html内容response时,最好不要用正则表达式来抓捕html文本内容里的特征,因为服务器返回的多个页面的文本内容不一定使用相同的模 ...

  9. opencv载入,显示及保存图像

    1.声明一个表示图像的变量,在OpenCV2中,这个变量是cv::Mat类型,该类是用于保存图像以及其他矩阵数据的数据结构.默认情况下它们的尺寸为0. cv::Mat  image;       // ...

随机推荐

  1. Error creating bean with name &#39;menuController&#39;: Injection of autowired dependency……

    出现了一大串错误 Error creating bean with name 'userController': Injection of autowired dependencies failed. ...

  2. mysql备份工具 :mysqldump mydumper Xtrabackup 原理

    备份是数据安全的最后一道防线,对于任何数据丢失的场景,备份虽然不一定能恢复百分之百的数据(取决于备份周期),但至少能将损失降到最低.衡量备份恢复有两个重要的指标:恢复点目标(RPO)和恢复时间目标(R ...

  3. [Effective C++ --029]为“异常安全”而努力是值得的

    假设有个class用来表现夹带背景图案的GUI菜单单,这个class用于多线程环境,所以它有个互斥器(mutex)作为并发控制用: class PrettyMenu{ public: ... void ...

  4. 第2章 数字之魅——斐波那契(Fibonacci)数列

    斐波那契(Fibonacci)数列 问题描述 递归算法: package chapter2shuzizhimei.fibonacci; /** * Fibonacci数列递归求解 * @author ...

  5. PHP 正则表达式语法

    则表达式简介 在某些应用中,往往有时候需要根据一定的规则来匹配(查找)确认一些字符串,如要求用户输入的 QQ 号码为数字且至少 5 位.用于描述这些规则的工具就是正则表达式. 最简单的匹配 最简单的匹 ...

  6. Step-by-Step XML Free Spring MVC 3 Configuration--reference

    The release of Spring 2.5 reduce the burden of XML by introduction annotation based configuration, b ...

  7. c语言指针难点

    先来一个例子 例: #include "stdio.h" int main() { ] = {,,,,}; printf("a是一个地址%d\n",a); pr ...

  8. cocos2d-x混合BlendFunc的使用

    1.什么是混合模式 “混合”是指两种颜色的叠加方式.在新图片将要渲染画到屏幕上的时候,将用在新图片中的红.绿.蓝和透明度信息,与屏幕上已经存在的图片颜色信息相融合. 说的具体一点,就是把某一像素位置上 ...

  9. Android(java)学习笔记113:Android编写代码调用Vibrator震动功能(Bug:按下按钮button始终没有震动)

    1.之前我编写的代码是如下: package com.himi.vibrate; import android.app.Activity; import android.app.Service; im ...

  10. mysql root给其它用户授权问题

    今天登录mysql,给其它用户授权遇到问题 mysql> grant all privileges on testdb.* to 'dbuser'@'10.4.14.14' identified ...