zoukankan      html  css  js  c++  java
  • ptyhon_opencv 图像的基本操作

    1、cv2.imread()  to read an image
         cv2.IMREAD_COLOR:  load a color image
         cv2.IMREAD_GRAYSCALE: loads image in grayscale mode
         cv2.IMREAD_UNCHANGED: Loads image as such including alpha channel
      
    下面是读一幅图像和显示一幅图像,cv.waitKey() is a keyboard function. Its argument is the time in milliseconds, 里面的参数也可能是一个具体的字母。 cv.destroyAllWindows() simply destroys all the windows.
    cv.destroyWindow() where you pass the exact window name as the argument.
     
    #encoding=utf-8
    import cv2 as cv
    import numpy as np
    
    #Load an color image in grayscale
    img=cv.imread('C:UsersAdministratorDesktoplena.jpg',0)
    
    #imshow an image
    cv.imshow('img',img)
    cv.waitKey(0)#这里要注意字母大小写的问题
    cv.destoryAllWindows()

    2、下面是定义一个窗口的名字,并在窗口中显示图像,其中cv.WINDOW_AUTOSIZE()默认显示图像的大小,cv.WINDOW_NORMAL()可以根据图像的大小自动调节窗口的大小。

    import cv2 as cv
    import numpy as np
    
    img=cv.imread('C:UsersAdministratorDesktoplena.jpg',0)
    
    cv.namedWindow('image',cv.WINDOW_NORMAL)
    cv.imshow('image',img)
    cv.waitKey(0)
    cv.destroyAllWindows()

    3、Use the function cv.imwrite()   to save an image.  First argument is the file name,secong argument is the image you want to save.s

    cv.imwrite('C:UsersAdministratorDesktoplena.jpg',img)

     

  • 相关阅读:
    类和对象
    循环结构(二)
    循环结构(一)
    Java数据类型
    对Java的初识
    函数的作用域、作用域链以及return关键字
    var、fucntion关键字优先级问题
    JavaScript中定义函数的几种方式
    JavaScript变量名与函数名的命名规范
    使用JavaScript分别实现4种样式的九九乘法表(1X1分别在左上、左下、右上、右下)
  • 原文地址:https://www.cnblogs.com/qducn/p/6278263.html
Copyright © 2011-2022 走看看