python調(diào)用攝像頭顯示圖像的實例
更新時間:2018年08月03日 09:18:31 作者:ShellCollector
今天小編就為大家分享一篇python調(diào)用攝像頭顯示圖像的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
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)用攝像頭顯示圖像的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- python通過opencv調(diào)用攝像頭操作實例分析
- python實現(xiàn)調(diào)用攝像頭并拍照發(fā)郵箱
- Python+OpenCV圖像處理——打印圖片屬性、設(shè)置存儲路徑、調(diào)用攝像頭
- python調(diào)用攝像頭的示例代碼
- python使用opencv在Windows下調(diào)用攝像頭實現(xiàn)解析
- python+openCV調(diào)用攝像頭拍攝和處理圖片的實現(xiàn)
- Python OpenCV調(diào)用攝像頭檢測人臉并截圖
- Python OpenCV 調(diào)用攝像頭并截圖保存功能的實現(xiàn)代碼
- python調(diào)用攝像頭拍攝數(shù)據(jù)集
- Python基于opencv調(diào)用攝像頭獲取個人圖片的實現(xiàn)方法
- 利用python調(diào)用攝像頭的實例分析
相關(guān)文章
解決tensorflow/keras時出現(xiàn)數(shù)組維度不匹配問題
這篇文章主要介紹了解決tensorflow/keras時出現(xiàn)數(shù)組維度不匹配問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06
Python內(nèi)置數(shù)據(jù)結(jié)構(gòu)列表與元組示例詳解
這篇文章主要給大家介紹了關(guān)于Python內(nèi)置數(shù)據(jù)結(jié)構(gòu)列表與元組的相關(guān)資料,列表是順序存儲的數(shù)據(jù)結(jié)構(gòu),類似于數(shù)據(jù)結(jié)構(gòu)中的順序表,在存儲上是相連的一大塊內(nèi)存空間,在物理和邏輯上都是連續(xù)的,需要的朋友可以參考下2021-08-08
Python實現(xiàn)批量下載excel表中超鏈接圖片
這篇文章主要為大家詳細(xì)介紹了如何使用Python實現(xiàn)批量下載excel表中超鏈接圖片,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2024-11-11

