资源简介

本资料是电赛可见光室内定位装置的整理资料,包括了各个模块的程序设计,采用图像处理算法,定位可以达到3cm的精度并附有最终测试视频。

资源截图

代码片段和文件信息

import sensor image time
from pyb import UART

uart = UART(3 9600)    #设置为串口3、波特率为9600发送数据
thresholds = (235 255) #设置监测色块阈值

sensor.reset()  #摄像头初始化
sensor.set_pixformat(sensor.GRAYSCALE)  #设置为灰度模式
sensor.set_framesize(sensor.QQVGA)      #画幅为QQVGA即分辨率为160*120
sensor.skip_frames(time = 2000)         #跳过起始画面,获取稳定图像
sensor.set_auto_gain(False) #在色块检测模式下关闭自动补光
sensor.set_auto_whitebal(False) #关闭白平衡
clock = time.clock()

xPositionNow = 0    # 初始化各坐标值
yPositionNow = 0
xPositionLast = 0
yPositionLast = 0
imageSize = 128

while(True):
    clock.tick()
    img = sensor.snapshot() #获取当期所采集到的图像快照
    # 设置色块阈值,具体数值情况可以通过OpenMVIDE中的阈值调整功能来得出
    # 工具 → Mechine Vision → Threshold Editor
    # area_threshold面积阈值设置为100 ,如果色块被面积小于100,则会被过滤掉
    # pixels_threshold 像素个数阈值,如果色块像素数量小于这个值,会被过滤掉
    # merge 设置为True,合并所有重叠的寻找到的blob为一个色块
    for blob in img.find_blobs([thresholds] pixels_threshold=100 area_threshold=100 merge=True):
        # 绘制相应的图形,方便我们测试的时候使用
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx() blob.cy())
        x = blob.cx() - (imageSize/2)
        y = (imageSize/2) - blob.cy()
        xPositionLast = xPositionNow
        yPositionLast = yPositionNow
        #在调试的时候为了使得像素点和坐标单位cm匹配所设置的数值
        xPositionNow = x * 0.6
        yPositionNow = y * 0.6-10
        # 测试时打印出当前坐标
        print(xPositionNow yPositionNow end = ‘‘)
        # 通过串口将坐标数据发送给单片机处理,实际上发送的就是一段文本
        uart.write(‘X:‘ + str(xPositionNow) + ‘Y:‘ +  str((-1)*yPositionNow) + ‘‘)
        # 判断当前所在区域(A\B\C\D)
        if abs(xPositionNow) < 20 and abs(yPositionNow) < 20:
            uart.write(‘A\n‘)
            print(‘A‘)
        elif yPositionNow < -20 and yPositionNow < xPositionNow and (-1)*yPositionNow > xPositionNow:
            uart.write(‘B\n‘)
            print(‘B‘)
        elif xPositionNow > 20 and (-1)*yPositionNow < xPositionNow and yPositionNow < xPositionNow:
            uart.write(‘C\n‘)
            print(‘C‘)
        elif yPositionNow > 20 and xPositionNow < yPositionNow and (-1)*xPositionNow < yPositionNow:
            uart.write(‘D\n‘)
            print(‘D‘)
        else:
            uart.write(‘E\n‘)
            print(‘E‘)
        # 0.5s更新一下坐标数据
        time.sleep(500)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-02-23 19:55  Design\
     目录           0  2018-06-07 19:23  Design\OPENMV\
     文件        2877  2018-05-01 22:07  Design\OPENMV\Location.py
     文件        2876  2018-06-06 22:16  Design\OPENMV\Location_0.py
     目录           0  2018-06-07 19:23  Design\STC_BH1750_3GND_AVERAGE\
     文件        5115  2002-04-16 22:32  Design\STC_BH1750_3GND_AVERAGE\STARTUP.A51
     文件       11668  2018-04-13 14:19  Design\STC_BH1750_3GND_AVERAGE\STARTUP.LST
     文件         749  2018-04-13 14:19  Design\STC_BH1750_3GND_AVERAGE\STARTUP.OBJ
     文件       31815  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750
     文件       41457  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.M51
     文件         998  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.build_log.htm
     文件        7466  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.hex
     文件          55  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.lnp
     文件         233  2011-06-18 22:40  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.plg
     文件       85638  2018-04-30 09:36  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.uvgui.CrowBoy
     文件        6085  2018-04-16 20:29  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.uvopt
     文件       14025  2018-04-16 20:29  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750.uvproj
     文件        1079  2011-06-18 22:40  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750_Opt.Bak
     文件        2040  2011-05-20 22:52  Design\STC_BH1750_3GND_AVERAGE\STC51_BH1750_Uv2.Bak
     文件       34365  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC_BH1750.LST
     文件       37035  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC_BH1750.OBJ
     文件          68  2018-04-27 18:14  Design\STC_BH1750_3GND_AVERAGE\STC_BH1750.__i
     文件       21377  2018-04-27 20:28  Design\STC_BH1750_3GND_AVERAGE\STC_BH1750.c
     文件           0  2018-04-13 11:50  Design\STC_BH1750_3GND_AVERAGE\STC_BH1750.txt
     目录           0  2018-06-07 19:23  Design\STM32_PWM输出\
     目录           0  2018-06-07 19:23  Design\STM32_PWM输出\CORE\
     文件       17273  2010-06-07 10:25  Design\STM32_PWM输出\CORE\core_cm3.c
     文件       85714  2011-02-09 14:59  Design\STM32_PWM输出\CORE\core_cm3.h
     文件       15503  2011-03-10 10:52  Design\STM32_PWM输出\CORE\startup_stm32f10x_hd.s
     目录           0  2018-06-07 19:23  Design\STM32_PWM输出\HARDWARE\
     目录           0  2018-06-07 19:23  Design\STM32_PWM输出\HARDWARE\KEY\
............此处省略196个文件信息

评论

共有 条评论