#TODO.3.2.合成图片 import cv2 import numpy as np original_image=cv2.imread('4.jpg') logal_image=cv2.imread('3.jpg') w1,h1,c1=original_image.shape w2,h2,c2=logal_image.shape print(w1,h1) print(w2, h2) # roi=original_image[(w1-w2)//2:(w1+w2)//2,(h1-h2)//2:(h1+h2)//2] roi=original_image[w1-w2:w1,h1-h2:h1] #灰度化 gray_logol=cv2.cvtColor(logal_image,cv2.COLOR_BGR2GRAY) #黑化 _,black_logol=cv2.threshold(gray_logol,170,255,cv2.THRESH_BINARY) imag_tsw=cv2.bitwise_and(roi,roi,mask=black_logol) #白化 _,white_logal=cv2.threshold(gray_logol,170,255,cv2.THRESH_BINARY_INV) imag_tsw1=cv2.bitwise_and(logal_image,logal_image,mask=white_logal) imag_tsw2=cv2.add(roi,imag_tsw) roii=cv2.add(imag_tsw,imag_tsw1) print(roii.shape) print(roi.shape) roi[:]=roii # cv2.imshow('roigg',roi) # cv2.imshow('img_tsw',imag_tsw) # cv2.imshow('white',imag_tsw1) cv2.imshow('roi',original_image) if cv2.waitKey(0)&0xFF==ord('q'): cv2.destroyAllWindows()