python調(diào)用攝像頭顯示圖像的實(shí)例
更新時(shí)間:2018年08月03日 09:18:31 作者:ShellCollector
今天小編就為大家分享一篇python調(diào)用攝像頭顯示圖像的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
如下所示:
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通過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)文章
解決tensorflow/keras時(shí)出現(xiàn)數(shù)組維度不匹配問題
這篇文章主要介紹了解決tensorflow/keras時(shí)出現(xiàn)數(shù)組維度不匹配問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-06-06
Python OpenCV簡(jiǎn)單的繪圖函數(shù)使用教程
本文主要為大家介紹了OpenCV中一些簡(jiǎn)單的繪圖函數(shù)的使用教程,文中的示例代碼講解詳細(xì),對(duì)我們了解OpenCV有一定的幫助,感興趣的可以學(xué)習(xí)一下2022-01-01
Python內(nèi)置數(shù)據(jù)結(jié)構(gòu)列表與元組示例詳解
這篇文章主要給大家介紹了關(guān)于Python內(nèi)置數(shù)據(jù)結(jié)構(gòu)列表與元組的相關(guān)資料,列表是順序存儲(chǔ)的數(shù)據(jù)結(jié)構(gòu),類似于數(shù)據(jù)結(jié)構(gòu)中的順序表,在存儲(chǔ)上是相連的一大塊內(nèi)存空間,在物理和邏輯上都是連續(xù)的,需要的朋友可以參考下2021-08-08
python測(cè)試驅(qū)動(dòng)開發(fā)實(shí)例
這篇文章主要介紹了python測(cè)試驅(qū)動(dòng)開發(fā)實(shí)例,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-10-10
Python實(shí)現(xiàn)批量下載excel表中超鏈接圖片
這篇文章主要為大家詳細(xì)介紹了如何使用Python實(shí)現(xiàn)批量下載excel表中超鏈接圖片,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2024-11-11
python3中eval函數(shù)用法使用簡(jiǎn)介
這篇文章主要介紹了python3中eval函數(shù)用法使用簡(jiǎn)介,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python模擬登錄網(wǎng)易云音樂并自動(dòng)簽到
時(shí)隔三周沒有和大家見過面了,最近在研究python模擬登陸專題,話不多說,讓我們愉快地開始實(shí)現(xiàn)模擬登陸實(shí)現(xiàn)網(wǎng)易云自動(dòng)簽到,需要的朋友可以參考下2021-06-06

