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


Python Sensor.close方法代码示例

本文整理汇总了Python中sensor.Sensor.close方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.close方法的具体用法?Python Sensor.close怎么用?Python Sensor.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sensor.Sensor的用法示例。


在下文中一共展示了Sensor.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import close [as 别名]
def main():
    global sensor
    sensor = Sensor()
    try:
        sensor.connect()
    except:
        print("Error connecting to sensor")
        raise
        return

    #cv.namedWindow("Threshold", cv.WINDOW_AUTOSIZE);
    cv.namedWindow("Contours", cv.WINDOW_AUTOSIZE);
    nfunc = np.vectorize(normalize)
    images = get_next_image()
    baseline_frame = images[-1]
    baseline = baseline_frame['image']
    width = baseline_frame['cols']
    height = baseline_frame['rows']
    while 1:
        images = get_next_image();
        frame = images[-1]
        pixels = np.array(frame['image'])
        pixels_zeroed = np.subtract(baseline, pixels);
        min = np.amin(pixels_zeroed)
        max = np.amax(pixels_zeroed)
        pixels_normalized = nfunc(pixels_zeroed, min, max)
        large = sp.ndimage.zoom(pixels_normalized, 10, order=1)
        large = large.astype(np.uint8);
        large = cv.medianBlur(large,7)
        #large = cv.GaussianBlur(large,(7,7),0)
        #stuff, blobs = cv.threshold(large,150,255,cv.THRESH_BINARY)
        stuff, blobs = cv.threshold(large,160,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
        contours, hierarchy = cv.findContours(blobs, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
        out = np.zeros((height*10,width*10,3), np.uint8)
        cv.drawContours(out,contours,-1,(255,255,0),3)

        regions_found = len(contours)

        contours = np.vstack(contours).squeeze()
        rect = cv.minAreaRect(contours)
        box = cv.cv.BoxPoints(rect)
        box = np.int0(box)
        cv.drawContours(out,[box],0,(0,255,255),2)

        #cv.imshow("Threshold", blobs);
        cv.imshow("Contours", out)
        cv.waitKey(1)

        x = rect[0][0]
        y = rect[0][1]
        angle = rect[2];

        if(regions_found < 10):
            send(x, y, angle)

        time.sleep(0.4)

    sensor.close()
    print "Done. Everything cleaned up."
开发者ID:G-ram,项目名称:portal,代码行数:61,代码来源:main.py


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