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)

     

  • 相关阅读:
    call()与apply()的作用与区别
    Tomcat8/9的catalina.out中文乱码问题解决
    怎样查看Jenkins的版本
    每日日报2020.8.18
    528. Random Pick with Weight
    875. Koko Eating Bananas
    721. Accounts Merge
    515. Find Largest Value in Each Tree Row
    286. Walls and Gates (Solution 1)
    408. Valid Word Abbreviation
  • 原文地址:https://www.cnblogs.com/qducn/p/6278263.html
Copyright © 2011-2022 走看看