使用 python, OpenCV 建立
目錄
image = cv2.imread('影像名稱.jpg/jpeg/png/tiff...')
image_size = image.shape
image_size = cv2.GetSize(image)
reimage = cv2.resize(image, (64,64), interpolation=cv2.INTER_CUBIC)
# cv2.resize(原影像, 調整後的(W, H), 模式)
interpolation模式:
- cv2.INTER_NEAREST: 採用鄰近插植
- cv2.INTER_LINEAR: 雙線性插植(如果未設定,通常系統會默認為此模式)
- cv2.INTER_AREA: 使用像素區域關係進行重採樣
- cv2.INTER_CUBIC: 4*4像素鄰域的雙/三次插值
- cv2.INTER_LANCZOS4: 8*8像素鄰域的Lanczos 插值
# 創建一個新的窗口用於顯示圖像
cv2.nameWindow('名稱')
# 在窗口中顯示圖像
cv2.imshow('名稱', image)
cv2.waitKey(0)
v2.imwrite('路徑', image, 格式)
img = image.copy()
(B, G, R) = cv2.split(image)
zeros = np.zeros(image.shape[:2], dtype="uint8")
cv2.namedWindow('B')
cv2.imshow('B', cv2.merge([B, zeros, zeros]))
cv2.namedWindow('G')
cv2.imshow('G', cv2.merge([zeros, G, zeros]))
cv2.namedWindow('R')
cv2.imshow('R', cv2.merge([zeros, zeros, R]))
cv2.waitKey(0)
# 橫向翻轉
horizontal = cv2.flip(image, 1)
# 縱向翻轉
vertical = cv2.flip(image, 0)
# 橫向縱向翻轉
hv_both = cv2.flip(image, -1)
org_img = cv2.imread('./Dataset_opencvdl/Q1_Image/Uncle_Roger.jpg')
flip_img = cv2.flip(org_img, 1)
def on_trackbar(val):
alpha = val / 255
beta = (1.0 - alpha)
dst = cv2.addWeighted(org_img, alpha, flip_img, beta, 0.0)
cv2.imshow('BLENDING', dst)
cv2.namedWindow('BLENDING')
cv2.createTrackbar('BLEND', 'BLENDING', 0, 255, on_trackbar)
cv2.waitKey(0)
cv2.destroyAllWindows()
OpenCV官網Two Images。
OpenCV官網Trackbar。
# (3, 3)為filter
guassian = cv2.GaussianBlur(image, (3, 3), 0)
# 7為K值
median = cv2.medianBlur(image, 7)
bilateral = cv2.bilateralFilter(image, 9, 90, 90)
可參考此網址。
OpenCV官網Smoothing Image。
image = cv2.imread('./Dataset_opencvdl/Q3_Image/Chihiro.jpg')
gray_img = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# 3*3 Gaussian Filter
x, y = np.mgrid[-1:2, -1:2]
gaussian_kernel = np.exp(-(x ** 2 + y ** 2))
# Normalization
gaussian_kernel = gaussian_kernel / gaussian_kernel.sum()
grad = signal.convolve2d(gray_img, gaussian_kernel, boundary='symm', mode='same') # convolution
plt.imshow(grad, cmap=plt.get_cmap('gray'))
plt.axis('off')
plt.show()
參考網址。
image = cv2.imread('./Dataset_opencvdl/Q3_Image/Chihiro.jpg')
gray_img = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
gray_img = np.array(gray_img)
img_X = np.zeros(gray_img.shape)
# Filter
filters.sobel(gray_img, 1, img_X)
# Normalization
img_X *= (img_X - np.min(img_X)) / (np.max(img_X) - np.min(img_X))
plt.imshow(img_X, cmap='gray')
plt.axis('off')
plt.show()
image = cv2.imread('./Dataset_opencvdl/Q3_Image/Chihiro.jpg')
gray_img = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
gray_img = np.array(gray_img)
img_Y = np.zeros(gray_img.shape)
# Filter
filters.sobel(gray_img, 0, img_Y)
# Normalization
img_Y *= (img_Y - np.min(img_Y)) / (np.max(img_Y) - np.min(img_Y))
plt.imshow(img_Y, cmap='gray')
plt.axis('off')
plt.show()
image = cv2.imread('./Dataset_opencvdl/Q3_Image/Chihiro.jpg')
gray_img = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
gray_img = np.array(gray_img)
img_X = np.zeros(gray_img.shape)
filters.sobel(gray_img, 1, img_X)
img_Y = np.zeros(gray_img.shape)
filters.sobel(gray_img, 0, img_Y)
# Filter
mag = np.hypot(img_X, img_Y)
# Normalization
mag *= 255.0 / np.max(mag)
plt.imshow(mag, cmap='gray')
plt.axis('off')
plt.show()
image = cv2.imread('./Dataset_opencvdl/Q4_Image/Parrot.png') # image.shape=(600, 900, 3)
center = ((image.shape[1] // 2 + float(Tx)), (image.shape[0] // 2 - float(Ty)))
rot_mat = cv2.getRotationMatrix2D(center, float(rotation), float(scaling))
rot_dst = cv2.warpAffine(image, rot_mat, (image.shape[1], image.shape[0]))
cv2.namedWindow('Image RST')
cv2.imshow('Image RST', rot_dst)
參考網址。
Git 基礎知識 Git 版本控制之工作流程 Local 本地端 working directory 目錄工作區 staging area 面積暫存區 localrepo 版本儲存區 Romate 雲端 remoterepo 雲端儲存區(目前使用的是GitHub)
Apr 11, 2022Description This is a practice project that using Python with TensorFlow. Requirements Python==3.7.0 opencv-contrib-python==3.4.2.17 matplotlib==3.1.1 numpy==1.18.5
Mar 15, 2022Introduction to Image Processing, Computer Vision and Deep Learning 目錄 [TOC] 1. Find Contour 1) Draw Contour Follow the steps:
Jan 11, 2021Description This is a practice project that using Python with OpenCV. Requirements Python==3.7.0 opencv-contrib-python==3.4.2.17 matplotlib==3.1.1 numpy==1.18.5 PyQt5==5.15.1
Jan 7, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up