python調(diào)用攝像頭顯示圖像的實(shí)例
如下所示:
import cv2 import numpy as np bins = np.arange(256).reshape(256,1) def hist_curve(im): h = np.zeros((300,256,3)) if len(im.shape) == 2: color = [(255,255,255)] elif im.shape[2] == 3: color = [ (255,0,0),(0,255,0),(0,0,255) ] for ch, col in enumerate(color): hist_item = cv2.calcHist([im],[ch],None,[256],[0,256]) cv2.normalize(hist_item,hist_item,0,255,cv2.NORM_MINMAX) hist=np.int32(np.around(hist_item)) pts = np.int32(np.column_stack((bins,hist))) cv2.polylines(h,[pts],False,col) y=np.flipud(h) return y def hist_lines(im): h = np.zeros((300,256,3)) if len(im.shape)!=2: print "hist_lines applicable only for grayscale images" #print "so converting image to grayscale for representation" im = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) hist_item = cv2.calcHist([im],[0],None,[256],[0,256]) cv2.normalize(hist_item,hist_item,0,255,cv2.NORM_MINMAX) hist=np.int32(np.around(hist_item)) for x,y in enumerate(hist): cv2.line(h,(x,0),(x,y),(255,255,255)) y = np.flipud(h) return y if __name__ == '__main__': import sys if len(sys.argv)>1: im = cv2.imread(sys.argv[1]) else : im = cv2.imread('../cpp/lena.jpg') print "usage : python hist.py <image_file>" gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) print ''' Histogram plotting \n Keymap :\n a - show histogram for color image in curve mode \n b - show histogram in bin mode \n c - show equalized histogram (always in bin mode) \n d - show histogram for color image in curve mode \n e - show histogram for a normalized image in curve mode \n Esc - exit \n ''' cv2.imshow('image',im) while True: k = cv2.waitKey(0)&0xFF if k == ord('a'): curve = hist_curve(im) cv2.imshow('histogram',curve) cv2.imshow('image',im) print 'a' elif k == ord('b'): print 'b' lines = hist_lines(im) cv2.imshow('histogram',lines) cv2.imshow('image',gray) elif k == ord('c'): print 'c' equ = cv2.equalizeHist(gray) lines = hist_lines(equ) cv2.imshow('histogram',lines) cv2.imshow('image',equ) elif k == ord('d'): print 'd' curve = hist_curve(gray) cv2.imshow('histogram',curve) cv2.imshow('image',gray) elif k == ord('e'): print 'e' norm = cv2.normalize(gray,alpha = 0,beta = 255,norm_type = cv2.NORM_MINMAX) lines = hist_lines(norm) cv2.imshow('histogram',lines) cv2.imshow('image',norm) elif k == 27: print 'ESC' cv2.destroyAllWindows() break cv2.destroyAllWindows()
以上這篇python調(diào)用攝像頭顯示圖像的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- python通過(guò)opencv調(diào)用攝像頭操作實(shí)例分析
- python實(shí)現(xiàn)調(diào)用攝像頭并拍照發(fā)郵箱
- Python+OpenCV圖像處理——打印圖片屬性、設(shè)置存儲(chǔ)路徑、調(diào)用攝像頭
- python調(diào)用攝像頭的示例代碼
- python使用opencv在Windows下調(diào)用攝像頭實(shí)現(xiàn)解析
- python+openCV調(diào)用攝像頭拍攝和處理圖片的實(shí)現(xiàn)
- Python OpenCV調(diào)用攝像頭檢測(cè)人臉并截圖
- Python OpenCV 調(diào)用攝像頭并截圖保存功能的實(shí)現(xiàn)代碼
- python調(diào)用攝像頭拍攝數(shù)據(jù)集
- Python基于opencv調(diào)用攝像頭獲取個(gè)人圖片的實(shí)現(xiàn)方法
- 利用python調(diào)用攝像頭的實(shí)例分析
相關(guān)文章
如何解決django-celery啟動(dòng)后迅速關(guān)閉
在本篇文章里小編給大家整理的是關(guān)于django-celery啟動(dòng)后迅速關(guān)閉的解決方法,有需要的朋友們學(xué)習(xí)下。2019-10-10基于python制作簡(jiǎn)易版學(xué)生信息管理系統(tǒng)
這篇文章主要介紹了基于python制作簡(jiǎn)易版學(xué)生信息管理系統(tǒng),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有很好地幫助,需要的朋友可以參考下2021-04-04python smtplib模塊自動(dòng)收發(fā)郵件功能(一)
這篇文章主要為大家詳細(xì)介紹了python smtplib模塊自動(dòng)收發(fā)郵件功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05Python SQLite3數(shù)據(jù)庫(kù)日期與時(shí)間常見(jiàn)函數(shù)用法分析
這篇文章主要介紹了Python SQLite3數(shù)據(jù)庫(kù)日期與時(shí)間常見(jiàn)函數(shù)用法,結(jié)合實(shí)例形式分析了Python連接、查詢SQLite3數(shù)據(jù)以及數(shù)據(jù)庫(kù)日期與時(shí)間常見(jiàn)操作方法,需要的朋友可以參考下2017-08-08python web基礎(chǔ)之加載靜態(tài)文件實(shí)例
下面小編就為大家分享一篇python web基礎(chǔ)之加載靜態(tài)文件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03詳解Python安裝tesserocr遇到的各種問(wèn)題及解決辦法
這篇文章主要介紹了詳解Python安裝tesserocr遇到的各種問(wèn)題及解決辦法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03使用Python的Tornado框架實(shí)現(xiàn)一個(gè)簡(jiǎn)單的WebQQ機(jī)器人
這篇文章主要介紹了使用Python的Tornado框架實(shí)現(xiàn)一個(gè)簡(jiǎn)單的WebQQ機(jī)器人,Tornado的異步特性可以提高I/O性能,需要的朋友可以參考下2015-04-04Python loguru日志庫(kù)之高效輸出控制臺(tái)日志和日志記錄
這篇文章主要介紹了python loguru日志庫(kù)之高效輸出控制臺(tái)日志和日志記錄的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03