opencv 笔记 00Begin

来源:互联网 发布:害怕异性亲密关系 知乎 编辑:程序博客网 时间:2024/05/17 07:45

Load and Display an Image

Mat image;image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the filenamedWindow( "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该函数,将图像写入到指定的文件夹下,程序执行时需保证该文件夹存在


原创粉丝点击