您的位置:首页 > 运维架构

opencv 笔记 00Begin

2013-04-08 22:59 183 查看


Load and Display an Image

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image );                   // Show our image inside it.


You’ll almost always end up using the:

core section, as here are defined the basic building blocks of the library
highgui module, as this contains the functions for input and output operations

imread function which loads the image name
specified by the first argument (argv[1]). The second argument specifies the format in what we want the image. This may be:

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

namedWindow ,For
this you need to specify its name and how it should handle the change of the image it contains from a size point of view. It may be:

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).

imshow function.
Specify the OpenCV window name to update and the image to use during this operation:


读取、修改、保存图像

Mat image;
image = imread( imageName, CV_LOAD_IMAGE_COLOR);
Mat gray_image;
cvtColor( image, gray_image, CV_BGR2GRAY );
imwrite( "../../images/Gray_Image.jpg", gray_image );


cvtColor 的参数为:

源图像 (image) 。
目标图像 (gray_image),用于保存转换图像。
附加参数,用于指定转换的类型

 imwrite该函数,将图像写入到指定的文件夹下,程序执行时需保证该文件夹存在
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenCV Begin