1. 程式人生 > >第三條python-opecv圖片混合及亮度調節

第三條python-opecv圖片混合及亮度調節

import cv2 as cv
import numpy as np
def add_demo(m1,m2):
    dst=cv.add(m1,m2)            #量圖片加在一起
    cv.imshow("add_demo",dst)

def subtract_demo(m1,m2):
    dst=cv.subtract(m1,m2)            #量圖片減在一起
    cv.imshow("add_demo",dst)
def divide_demo(m1,m2):
    dst=cv.divide(m1,m2)            #量圖片乘在一起
    cv.imshow("add_demo",dst)

def multiply_demo(m1,m2):
    dst=cv.multiply(m1,m2)            #量圖片除在一起
    cv.imshow("add_demo",dst)

def logic_demo(m1, m2):                  #與或操非作
    dst = cv.bitwise_and(m1, m2)
    dst2 = cv.bitwise_or(m1, m2)
    dst3 = cv.bitwise_not(image)
    cv.imshow("add_demo", dst)
    cv.imshow("add_demo", dst2)
    cv.imshow("add_demo", dst3)


def contrast_brightness_demo(image, c, b):         #亮度增強
    h, w, ch = image.shape
    blank = np.zeros([h, w, ch], image.dtype)
    dst = cv.addWeighted(image, c, blank, 1-c, b)         #影象混合dst = α · img1 + β · img2 + γ
    cv.imshow("con-bri-demo", dst)

def others(m1, m2):
    M1, dev1 = cv.meanStdDev(m1)
    M2, dev2 = cv.meanStdDev(m2)
    print(M1)    #返回均值
    print(M2)

    print(dev1)       #返回方差
    print(dev2)
print("--------- Python OpenCV Tutorial ---------")
src1 = cv.imread("C:/Users/weiqiangwen/Desktop/sest/data/LinuxLogo.jpg")
src2 = cv.imread("C:/Users/weiqiangwen/Desktop/sest/data/WindowsLogo.jpg")
print(src1.shape)
print(src2.shape)

# cv.namedWindow("image1", cv.WINDOW_AUTOSIZE)
# cv.imshow("image1", src1)
cv.imshow("image2", src2)
# add_demo(src1,src2)
# subtract_demo(src1,src2)
# divide_demo(src1,src2)
# multiply_demo(src1,src2)
contrast_brightness_demo(src2,1.2,10)
cv.waitKey(0)

cv.destroyAllWindows()