python调用摄像头显示图像
来源:互联网 发布:sql orderby limit 编辑:程序博客网 时间:2024/06/04 00:23
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调用摄像头显示图像
- Opencv调用摄像头,显示摄像头图像
- 调用摄像头采集图像
- Unity3d,调用摄像头显示
- Opencv调用摄像头采集图像
- Javacv调用摄像头采集图像
- opencv-python调用摄像头
- OpenCV之显示摄像头图像
- 调用摄像头拍照并显示
- 【图像识别】 Python+Opencv调用摄像头实现人脸识别并保存视频
- Python+Opencv+Qt4编写Windows下摄像头图像采集显示程序
- Ubuntu中python调用SimpleITK来显示图像
- opencv-python调用笔记本摄像头
- OpenCV之获取摄像头,显示图像
- 基于UDP的摄像头图像显示软件设计
- 使用Qt+OpenCV+VideoInput 显示摄像头图像
- OpenCV 获取摄像头图像数据并显示
- 在LCD上显示USB摄像头图像
- RFID简介
- Ubuntu终端几个常用的快捷键
- Android,I'm coming 之 OkHttp(一)
- 基于双目视觉的移动机器人SLAM系统研究与设计
- Android中使用开源框架PagerSlidingTabStrip实现导航标题
- python调用摄像头显示图像
- 烂代码待解决
- Unix高级编程:malloc内存管理、缓冲机制、mmap内存映射到进程、系统调用文件操作
- 103. Binary Tree Zigzag Level Order Traversal
- 【时间管理】优秀是选择的结果
- hibernate 懒加载
- linux系统安装mysql数据库
- Win10专业版永久激活方法
- lightoj 1101 - A Secret Mission(MST上的树链剖分)