OpenCV&图像处理_1:矩阵,以及图像读写操作
2014-10-26 14:55
1726 查看
[Attention]:阅读本文前请先阅读我OpenCV&图像处理_0这篇帖子。
一:矩阵,图像的容器
How we get and store the pixels values may vary according to our needs, but in the end all images inside a computer
world may be reduced to numerical matrices and other information describing the matrix itself.
计算机里存储的图像最终只是数字矩阵以及一些描述矩阵本身的信息。
二:OpenCV里图像的加载、修改、存储及显示
下面是我对OpenCV里源代码对图像加载、修改、存储和显示的一些个人解读:
cvtColor()函数怎么将一副彩色图像转化为灰度图?
答案如上图公式所示。
一:矩阵,图像的容器
How we get and store the pixels values may vary according to our needs, but in the end all images inside a computer
world may be reduced to numerical matrices and other information describing the matrix itself.
计算机里存储的图像最终只是数字矩阵以及一些描述矩阵本身的信息。
二:OpenCV里图像的加载、修改、存储及显示
下面是我对OpenCV里源代码对图像加载、修改、存储和显示的一些个人解读:
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <cv.h> #include <iostream> /*core section, as here are defined the basic building blocks of the library. cocre section, 定义了OpenCV函数库的基本块,包含有大量的算法和数据结构 highgui module, as this contains the functions for input and output operations. highgui module, 包含输入输出操作*/ using namespace cv; using namespace std; int main( int argc,char** argv){ Mat image; image = imread( "E:/VS2010Projects/image/lena_RGB.jpg" , CV_LOAD_IMAGE_UNCHANGED); /*CV_LOAD_IMAGE_UNCHANGED (<0) loads the image as is (including the alpha channel if present) 加载原图,如果有alpha通道也加载alpha通道 CV_LOAD_IMAGE_GRAYSCALE ( 0) loads the image as an intensity one 加载灰度图,RGB可以转化为灰度图 CV_LOAD_IMAGE_COLOR (>0) loads the image in the RGB format 加载彩色图,灰度图不可以转化为彩色图*/ if(! image.data ){ // Check for invalid input cout << "Could not open or find the image" << std::endl ; return -1; } Mat Gray_image1; cvtColor( image, Gray_image1, CV_BGR2GRAY ); Mat Gray_image2; cvtColor( image, Gray_image1, CV_RGB2GRAY ); namedWindow( "Display window", WINDOW_AUTOSIZE ); /*CV_WINDOW_AUTOSIZE图像多大就显示窗口多大 CV_WINDOW_NORMAL可以调整窗口大小*/ imwrite( "E:/VS2010Projects/image/lena_BGR2Gray.jpg" ,Gray_image1); imwrite( "E:/VS2010Projects/image/lena_RGB2Gray.jpg" ,Gray_image1); imshow( "Display window", image); waitKey(0); return 0; }个人认为这些会用就好了,其中的关键在于:
cvtColor()函数怎么将一副彩色图像转化为灰度图?
答案如上图公式所示。
相关文章推荐
- OpenCV 1.x & 2.x 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简单介绍(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV&图像处理_3:以腐蚀[eroding]和膨胀[dilating]为基础的形态学操作和图像金字塔[image pyramids]
- Qt&OpenCV——Q图像处理基本操作
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- 图像处理之 opencv 学习---矩阵的操作
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简单介绍(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV数字图像处理十:读写txt文件,在图像训练和测试的时候经常用到
- OpenCV学习笔记(四)—矩阵和图像操作