程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python practice_ Opencv and PIL image transformation test

編輯:Python

Practicing picture recognition is useful pil The module reads the picture , Save the code yourself .
Use the original size of the grayscale image when practicing 124k, Use PIL Save only 50k, Use opencv There is 127k.
Change the color picture to have the original picture 150k, Use PIL Save only 140k, Use opencv There is 270k.

import cv2
import numpy as np
from PIL import Image

# Use opencv Open the picture
img_cv = cv2.imread(‘./image/ceshi.jpeg’)
#opencv transformation PIL
img_pil = Image.fromarray(cv2.cvtColor(img_cv,cv2.COLOR_BGR2RGB))
# preservation
img_pil.save(‘./image/ceshi_img.jpeg’)
# View type
print(type(img_pil)) #<class ‘PIL.Image.Image’>

# Use PIL Open the picture
img_pil = Image.open(‘./image/ceshi.jpeg’)
#PIL transformation opencv
img_cv = cv2.cvtColor(np.asarray(img_pil),cv2.COLOR_RGB2BGR)
# preservation
cv2.imwrite(‘./image/ceshi_cv.jpeg’,img_cv)
# View type
print(type(img_cv)) #<class ‘numpy.ndarray’>


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved