『python』OpenCV3電腦視覺庫第二彈_簡單的圖片處理

來源:互聯網
上載者:User

標籤:nump   utf-8   pytho   key   轉化   比較   odi   顯示   圖片   

注意,本庫基於python2.7,所以文法細節和之前有所不同

cv2和numpy深度契合,其圖片讀入後就是numpy.array,只不過dtype比較不常用而已,支援全部數組方法(廢話...

 

cv2.cvtColor(img,cv2.COLOR_BAYER_BG2BGR)

img.item(0,0)

img.itemset((0,0),0)

cv2.imshow(‘my image‘,img) 

cv2.waitKey()

cv2.destroyAllWindows()

 1 # coding=utf-8 2 import cv2 3 import numpy as np 4  5 # array數組產生 6 img = np.zeros((3,3),dtype=np.uint8) 7 print img.shape 8  9 # array數組轉化為BGR模式10 # 我也不懂為什麼不用RGB而用BGB這麼蹩腳的用法11 img = cv2.cvtColor(img,cv2.COLOR_BAYER_BG2BGR)12 print img.shape13 14 # 讀取圖片,左上像素點改寫為藍色,儲存15 img = cv2.imread(‘beauti.jpeg‘)16 img[0][0] = [255,0,0]17 cv2.imwrite(‘MyPic.png‘,img)18 19 # 丟失顏色資訊,左上像素點改寫為黑色,儲存20 img = cv2.imread(‘beauti.jpeg‘,cv2.IMREAD_GRAYSCALE)21 print img.shape22 img[0][0] = 023 cv2.imwrite(‘MyPic-gray.png‘,img)24 25 # 使用array.item和array.itemset優雅的重寫上面代碼26 img = cv2.imread(‘beauti.jpeg‘,cv2.IMREAD_GRAYSCALE)27 print img.shape28 #img[0][0] = 029 print img.item(0,0)30 img.itemset((0,0),0)31 cv2.imwrite(‘MyPic-gray.png‘,img)32 33 # 去掉綠色通道34 img = cv2.imread(‘beauti.jpeg‘)35 img[:,:,1] = 036 cv2.imwrite(‘no_green.png‘,img)37 print img.shape,img.size,img.dtype38 39 img = cv2.imread(‘beauti.jpeg‘)40 # 顯示圖片,必須輸入兩個參數41 cv2.imshow(‘my image‘,img)42 # 視窗展示時間43 cv2.waitKey()44 # 釋放視窗45 cv2.destroyAllWindows()

 

『python』OpenCV3電腦視覺庫第二彈_簡單的圖片處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.