def main (): #Cargar Imagen img = cv2.imread("Home/Pictures/carro.jpg") #Cargar Imagen a escala de grises img = cv2.imread("Home/Pictures/carro.jpg", cv2.IMREAD_GRAYSCALE) #Guardar Imagen cv2.imwrite('carrow.png',img) #Mostrar la imagen, esperar tecla para cerrar y destruir ventanas cv2.imshow('image carro',img) cv2.waitKey(0) cv2.destroyAllWIndows() matploit() return
ret, mask = cv2.threshold(img2gray,220,255, cv2.THRESH_BINARY_INV) #cv2.imshow('mask', mask)#整張變黑白且黑白反轉 #再一次黑白反轉 mask_inv = cv2.bitwise_not(mask) #cv2.imshow('mask', mask_inv) #背景 img1_bg = cv2.bitwise_and(roi, roi, mask= mask_inv) #前景 img2_fg = cv2.bitwise_and(img2, img2, mask = mask) #黏一黏 dst = cv2.add(img1_bg, img2_fg) #黏完還給img1 img1[0:rows, 0:cols ] = dst cv2.imshow('res', img1) cv2.imshow('mask_inv', mask_inv) cv2.imshow('img1_bg', img1_bg) cv2.imshow('img2_fg', img2_fg) cv2.imshow('dst', dst) cv2.waitKey(0) cv2.destroyAllWIndows()