当前位置: 首页>>代码示例>>Python>>正文


Python Histogram.calcHistogram方法代码示例

本文整理汇总了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) )
开发者ID:eliask,项目名称:SDP2011-Robotniks,代码行数:97,代码来源:vision.py


注:本文中的histogram.Histogram.calcHistogram方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。