本文整理汇总了Python中histogram.Histogram.calcHistogram方法的典型用法代码示例。如果您正苦于以下问题:Python Histogram.calcHistogram方法的具体用法?Python Histogram.calcHistogram怎么用?Python Histogram.calcHistogram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类histogram.Histogram
的用法示例。
在下文中一共展示了Histogram.calcHistogram方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vision
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import calcHistogram [as 别名]
class Vision():
#rawSize = (768,576)
rawSize = (640, 480)
# Whether to 'crash' when something non-critical like the GUI fails
debug = True
def __init__(self, world, filename=None, simulator=None, once=False, headless=False):
logging.info('Initialising vision')
if simulator:
self.capture = SimCapture(simulator)
else:
self.capture = Capture(self.rawSize, filename, once)
self.headless = headless
self.threshold = threshold.AltRaw()
self.pre = Preprocessor(self.rawSize, self.threshold, simulator)
self.featureEx = FeatureExtraction(self.pre.cropSize)
self.interpreter = Interpreter()
self.world = world
self.gui = GUI(world, self.pre.cropSize, self.threshold)
self.histogram = Histogram(self.pre.cropSize)
self.times=[]
self.N=0
#debug.thresholdValues(self.threshold.Tblue, self.gui)
logging.debug('Vision initialised')
def formatTime(self, t):
return time.strftime('%H:%M:%S', time.localtime(t)) \
+ ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0
def processFrame(self):
startTime = time.time()
logging.debug("Frame %d at %s", self.N,
self.formatTime(startTime) )
self.N += 1
logging.debug("Capturing a frame")
frame = self.capture.getFrame()
logging.debug("Entering preprocessing")
standard = self.pre.get_standard_form(frame)
bgsub_vals, bgsub_mask = self.pre.bgsub(standard)
logging.debug("Entering feature extraction")
hist_props_bgsub = self.histogram.calcHistogram(standard)
hist_props_abs = self.histogram.calcHistogram(bgsub_vals)
self.threshold.updateBGSubThresholds(hist_props_bgsub)
#self.threshold.updateAbsThresholds(hist_props_abs)
ents = self.featureEx.features(bgsub_vals, self.threshold)
logging.debug("Detected entities:", ents)
logging.debug("Entering interpreter")
self.interpreter.interpret(ents)
logging.debug("Entering World")
self.world.update(startTime, ents)
logging.debug("Updating GUI")
if not self.headless:
try:
bgsub = self.pre.remove_background(standard)
self.gui.updateWindow('raw', frame)
self.gui.updateWindow('mask', bgsub_mask)
self.gui.updateWindow('foreground', bgsub_vals)
self.gui.updateWindow('bgsub', bgsub)
self.gui.updateWindow('standard', standard)
canny = cv.CreateImage(self.pre.cropSize, 8,1)
# adaptive = cv.CreateImage(self.pre.cropSize, 32,3)
# tmp = cv.CreateImage(self.pre.cropSize, 8,3)
# cv.Convert(standard, adaptive)
cv.CvtColor(bgsub, canny, cv.CV_BGR2GRAY)
cv.Threshold(canny, canny, 150, 255, cv.CV_THRESH_OTSU)
# cv.Threshold(canny, canny, 100, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C)
# cv.Sobel(adaptive, adaptive, 1,1,1)
# cv.Convert(adaptive, tmp)
# cv.ConvertScale(tmp, tmp, 10)
# cv.CvtColor(tmp, canny, cv.CV_BGR2GRAY)
# cv.Threshold(canny,canny, 50, 255, cv.CV_THRESH_BINARY)
#cv.Canny(canny,canny, 100, 180,3)
cv.CvtColor(canny, bgsub, cv.CV_GRAY2BGR)
new = self.featureEx.detectCircles(bgsub)
self.gui.updateWindow('adaptive', canny)
self.gui.updateWindow('new', new)
self.gui.draw(ents, startTime)
except Exception, e:
logging.error("GUI failed: %s", e)
if self.debug:
raise
endTime = time.time()
self.times.append( (endTime - startTime) )