本文整理汇总了Python中Camera.Camera.read方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.read方法的具体用法?Python Camera.read怎么用?Python Camera.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera.Camera
的用法示例。
在下文中一共展示了Camera.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import read [as 别名]
class Parameters:
def __init__(self,source=0):
# Selected base color
# fourth one is not used
self.hsv = (0,0,0,0)
self.hsv2 = (0,0,0,0)
self.hsv3 = (0,0,0,0)
# Thresholds
self.ht = 0
self.st = 180
self.vt = 200
self.ht_ = 0
self.st_ = 180
self.vt_ = 200
# Co-ords for the color selection square
# self.start = (0,0)
# self.end = (0,0)
self.center = (0,0)
# Boolean to check weather
# the colors are locked or not
self.locked = False
# Get the camera object
self.cam = Camera(source)
def findCenter(self):
# Read a frame
frame = self.cam.read()
# Calculate the co-ordinates for the center pixel
y = frame.shape[0]/2
x = frame.shape[1]/2
self.center = (x,y)
示例2: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import read [as 别名]
class Application:
def __init__(self,source=0):
self.START = None
self.END = None
self.CAM = Camera(source)
self.LOCKED = False
self.ROI_HIST = None
def findCenter(self):
# Read a frame
frame = self.CAM.read()
# Calculate the co-ordinates for the center pixel
y = frame.shape[0]/2
x = frame.shape[1]/2
# Calculate the points for the
# diagonal of the square
# which will be displayed in the center
self.START = ( x-25 , y-25 )
self.END = ( x+25 , y+25 )
def run(self):
self.findCenter()
while True:
# Read a frame from the camera
frame = self.CAM.read()
# b,g,r = cv2.split(frame)
# b = cv2.equalizeHist(b)
# g = cv2.equalizeHist(g)
# r = cv2.equalizeHist(r)
# frame = cv2.merge((b,g,r))
# frame = cv2.GaussianBlur(frame,(3,3),0)
# frame = cv2.medianBlur(frame,3)
# Convert to hsv format
# hsv = frame
hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
# hsv = cv2.split(frame)[2]
if not self.LOCKED:
# Get the reigon of interest
reigonOfInterest = hsv[ self.START[1]:self.END[1],self.START[0]:self.END[0],]
# Calculate histogram
self.ROI_HIST = cv2.calcHist([reigonOfInterest],[0,1], None, [180,255], [0,180,0, 255] )
# Normalize the histogram
cv2.normalize(self.ROI_HIST,self.ROI_HIST,0,255,cv2.NORM_MINMAX)
# Calculate back projection
dst = cv2.calcBackProject([hsv],[0,1],self.ROI_HIST,[0,180,0,255],10)
# Now convolute with circular disc
# threshold
# kernel = np.ones((5,5),np.uint8)
# ret,mask = cv2.threshold(dst,50,255,0)
# disc = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
# cv2.filter2D(dst,-1,disc,dst)
# dst = cv2.merge((dst,dst,dst))
# res = cv2.bitwise_and(frame,dst)
# disc = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
# cv2.filter2D(dst,-1,disc,dst)
# # dst = cv2.morphologyEx(dst,cv2.MORPH_OPEN,kernel)
# # dst = cv2.morphologyEx(dst,cv2.MORPH_OPEN,kernel)
# # dst = cv2.morphologyEx(dst,cv2.MORPH_OPEN,kernel)
# # dst = cv2.morphologyEx(dst,cv2.MORPH_CLOSE,kernel)
#.........这里部分代码省略.........
示例3: denoise
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import read [as 别名]
import numpy as np
import cv2
from Camera import Camera
def denoise(frame):
frame = cv2.medianBlur(frame,5)
frame = cv2.GaussianBlur(frame,(5,5),0)
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
return frame
camera = Camera(0)
ALPHA = 0.015
BG = denoise(cv2.cvtColor(camera.read(), cv2.COLOR_BGR2GRAY))
# c =1
while True:
frame = camera.read()
f = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
BG = f * ALPHA + BG * (1 - ALPHA)
mask = cv2.absdiff(f.astype(np.uint8), BG.astype(np.uint8))
ret, mask = cv2.threshold(mask.astype(np.uint8), 15, 255, cv2.THRESH_BINARY)