from PIL import Image
import os
import sys
target = Image.new('RGBA', (300, 300), (0, 0, 0, 0))
nike_image = Image.open("./0.png")
nike_image = nike_image.resize((300, 300))
hnu_image = Image.open("./water1.png")
hnu_image = hnu_image.resize((300, 300))
r,g,b = hnu_image.split()
import pdb
pdb.set_trace()
nike_image.convert("RGBA")
target.paste(nike_image, (0,0))
hnu_image.convert("RGBA")
target.paste(hnu_image,(0,0), mask=r*0.1)
target.save("f.png")
image_process.py
import numpy as np
import cv2
def generate_data():
image_data=[]
num_0 =np.array(
[[0,0,1,1,0,0],
[0,1,0,0,1,0],
[0,1,0,0,1,0],
[0,1,0,0,1,0],
[0,0,1,1,0,0],
[0,0,0,0,0,0]])
image_data.append(num_0)
num_1 = np.array(
[[0,0,0,1,0,0],
[0,0,1,1,0,0],
[0,0,0,1,0,0],
[0,0,0,1,0,0],
[0,0,1,1,1,0],
[0,0,0,0,0,0]])
image_data.append(num_1)
num_2 = np.array(
[[0,0,1,1,0,0],
[0,1,0,0,1,0],
[0,0,0,1,0,0],
[0,0,1,0,0,0],
[0,1,1,1,1,0],
[0,0,0,0,0,0]])
image_data.append(num_2)
num_3 = np.array(
[[0,0,1,1,0,0],
[0,0,0,0,1,0],
[0,0,1,1,0,0],
[0,0,0,0,1,0],
[0,0,1,1,0,0],
[0,0,0,0,0,0]])
image_data.append(num_3)
num_4 = np.array(
[
[0,0,0,0,1,0],
[0,0,0,1,1,0],
[0,0,1,0,1,0],
[0,1,1,1,1,1],
[0,0,0,0,1,0],
[0,0,0,0,0,0]])
image_data.append(num_4)
num_5 = np.array(
[
[0,1,1,1,0,0],
[0,1,0,0,0,0],
[0,1,1,1,0,0],
[0,0,0,0,1,0],
[0,1,1,1,0,0],
[0,0,0,0,0,0]])
image_data.append(num_5)
num_6 = np.array(
[[0,0,1,1,0,0],
[0,1,0,0,0,0],
[0,1,1,1,0,0],
[0,1,0,0,1,0],
[0,0,1,1,0,0],
[0,0,0,0,0,0]])
image_data.append(num_6)
num_7 = np.array(
[
[0,1,1,1,1,0],
[0,0,0,0,1,0],
[0,0,0,1,0,0],
[0,0,0,1,0,0],
[0,0,0,1,0,0],
[0,0,0,0,0,0]])
image_data.append(num_7)
num_8 = np.array(
[[0,0,1,1,0,0],
[0,1,0,0,1,0],
[0,0,1,1,0,0],
[0,1,0,0,1,0],
[0,0,1,1,0,0],
[0,0,0,0,0,0]])
image_data.append(num_8)
num_9 = np.array(
[[0,0,1,1,1,0],
[0,1,0,0,1,0],
[0,0,1,1,1,0],
[0,1,0,0,1,0],
[0,0,0,0,1,0],
[0,0,0,0,0,0]])
image_data.append(num_9)
return image_data
if __name__=="__main__":
image_data = generate_data()
print("数字0对应的图片是:")
print(image_data[0])
cv2.imwrite("0.png",image_data[0]*255)
print("-"*20)
import pdb
pdb.set_trace()
print("数字8对应的图片是:")
print(image_data[8])
print("-"*20)
week1_class_code.py
a=[1,2,3]
print("Hello friends,welcome week1's class .........",29*"-","%s"%(a))
import cv2
import numpy as np
img0 = np.array([[0,0,1],[0,1,0],[1,0,0]])
print(img0)
print(img0.shape)
print("img0 size = %s,%s"%(img0.shape[0],img0.shape[1]))
import matplotlib.pyplot as plt
plt.imshow(img0,cmap = 'gray' )
cap = cv2.VideoCapture("../How Computer Vision Works.mp4")
ret,frame = cap.read()
print(cap.isOpened())
plt.imshow(cv2.cvtColor(frame,cv2.COLOR_BGR2RGB))
cap.release()
img = cv2.imread("lena.jpg")
print(img.shape)
roi = img[100:200,300:400]
img_RGB = cv2.cvtColor(img_BGR, cv2.COLOR_BGR2RGB
cv2.cvtColor(img_BGR, cv2.COLOR_BGR2GRAY)
cv2.cvtColor(img_BGR, cv2.COLOR_BGR2HSV
plt.imshow(cv2.threshold(img,128,200,cv2.THRESH_BINARY))
plt.imshow(cv2.resize(img,(300,500)))
M = np.float32([[1,0,30],[0,1,30]])
plt.imshow(cv2.warpAffine(img,M,(500,300)))
pts1 = np.float32([[50,50],[200,50],[50,200]])
pts2 = np.float32([[10,100],[200,50],[100,250]])
M = cv2.getAffineTransform(pts1,pts2)
print(M)
theta=1
M = np.float32([[np.cos(theta),-np.sin(theta),500],[np.sin(theta),np.cos(theta),100]])
cols=800
rows=800
dst = cv2.warpAffine(img,M,(cols,rows))
plt.imshow(dst)
pts1 = np.float32([[56,65],[368,52],[28,387],[389,390]])
pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]])
M = cv2.getPerspectiveTransform(pts1,pts2)
dst = cv2.warpPerspective(img,M,(300,300))
lena_gaussian_blur = cv2.GaussianBlur(lena_RGB, (5, 5), 1, 0)
cv2.Canny(pil_img3,30,150)
kernel = np.ones((9,9),np.float32)/81
result = cv2.filter2D(img,-1,kernel)
import torch
import matplotlib
get_ipython().system(u'pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple')
from image_process import *
image_data = generate_data()
import matplotlib.pyplot as plt
i=0
print(image_data[i%10])
plt.imshow(image_data[i%10],cmap = 'gray')
i=i+1
plt.imshow(cv2.imread('lena.jpg'))
img = cv2.imread("lena.jpg")
wm = cv2.imread("water1.png")
wm = cv2.resize(wm,(300,300))
wm = 255-wm
img1 = cv2.resize(img,(300,300))
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
print(wm.shape)
plt.imshow(cv2.add(wm,img1))
plt.imshow(cv2.addWeighted(wm,1,img1,0.2,0))
week1_class_code_after_class.py
a=[1,2,3]
print("Hello friends,welcome week1's class .........",29*"-","%s"%(a))
import cv2
import numpy as np
img0 = np.array([[0,0,1],[0,1,0],[1,0,0]])
print(img0)
print(img0.shape)
print("img0 size = %s,%s"%(img0.shape[0],img0.shape[1]))
import matplotlib.pyplot as plt
plt.imshow(img0,cmap = 'gray' )
cap = cv2.VideoCapture("How Computer Vision Works.mp4")
print(cap.isOpened())
return_value=True
while return_value:
return_value,frame = cap.read()
print(cap.isOpened())
plt.imshow(frame,cmap = 'gray')
print(frame.shape)
cap.release()
img = cv2.imread("lena.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
print(img.shape)
roi = img[100:200,300:400]
plt.imshow(img)
img_gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray.shape
plt.imshow(img_gray,cmap='gray')
import cv2
img_BGR = cv2.imread('lena.jpg')
img_hsv=cv2.cvtColor(img_BGR,cv2.COLOR_BGR2HSV)
plt.imshow(img_hsv,cmap='')
import cv2
img = cv2.imread('lena.jpg')
plt.imshow(cv2.threshold(img,128,200,cv2.THRESH_BINARY))
img =cv2.resize(img,(50,30))
plt.imshow(img)
img.shape
img = cv2.imread('lena.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img =cv2.resize(img,(500,300))
plt.imshow(img)
img.shape
img_roi =img[100:300,0:200]
plt.imshow(img_roi)
import numpy as np
M = np.float32([[1,0,300],[0,1,200]])
print(img[0+50,0])
img_1=cv2.warpAffine(img,M,(1000,1000))
plt.imshow(img_1)
print(img_1[200+50,300])
theta=0.5
M = np.float32([[0.1,0,100],[0,2,100]])
cols=800
rows=800
dst = cv2.warpAffine(img,M,(cols,rows))
plt.imshow(dst)
pts1 = np.float32([[56,65],[368,52],[28,387],[389,390]])
pts2 = np.float32([[0,0],[100,0],[0,300],[300,300]])
M = cv2.getPerspectiveTransform(pts1,pts2)
print(M)
dst = cv2.warpPerspective(img,M,(300,300))
plt.imshow(dst)
img= cv2.GaussianBlur(img, (11, 11), 1, 0)
plt.imshow(img)
cv2.Canny(pil_img3,30,150)
kernel = np.ones((3,3),np.float32)/8
kernel=-kernel
kernel[0,:]=[-1,-1,-1]
kernel[1,:]=[0,0,0]
kernel[2,:]=[1,1,1]
print(kernel)
plt.imshow(img)
print(img.shape)
result = cv2.filter2D(img,-1,kernel)
result.shape
print(result[0,0])
plt.imshow(result*255)
result = cv2.filter2D(result,-1,kernel)
plt.imshow(result)
result.shape
import torch
import matplotlib
get_ipython().system(u'pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple')
from image_process import *
image_data = generate_data()
import matplotlib.pyplot as plt
i=0
print(image_data[i%10])
plt.imshow(image_data[i%10],cmap = 'gray')
i=i+1
plt.imshow(cv2.imread('lena.jpg'))
img = cv2.imread("lena.jpg")
img= cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
wm = cv2.imread("water1.png")
wm = cv2.resize(wm,(300,300))
wm = 255-wm
img1 = cv2.resize(img,(300,300))
print(wm.shape)
plt.imshow(cv2.add(wm,img1))
plt.imshow(cv2.addWeighted(wm,0.9,img1,0.5,0))
转载请注明原文地址:https://ipadbbs.8miu.com/read-3625.html