python OpenCV-Python 基础教程

e'feefe1.读取图片

import cv2 as cv

#读取图片
img = cv.imread('D:/MyHappy/mycv2/tangmu.webp')
#灰度转换
gray_img = cv.cvtColor(img,cv.COLOR_BAYER_BG2BGR)
#显示灰度
cv.imshow("grat",gray_img)
#保存灰度图片
cv.imwrite('gray_tangmu.webp',gray_img)
#显示图片
cv.imshow("read_img",img)
#等待
cv.waitKey(0)
#释放缓存
cv.destroyAllWindows()

2.灰度转换

import cv2 as cv
import numpy as np


def index1():
    img = cv.imread("D:/MyHappy/mycv2/tangmu.webp")
    gray_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
    cv.imshow("gray",gray_img)
    cv.imshow("img1",img)
    cv.waitKey(0)
    cv.destroyAllWindows()

if __name__ == '__main__':
    index1()

3.尺寸转换

import cv2 as cv
import numpy as np

def index1():
    img = cv.imread("D:/MyHappy/mycv2/tangmu.webp")
    #修改尺寸
    resize_img = cv.resize(img,dsize=(

你可能感兴趣的:(opencv,python,计算机视觉)