logo

我在多文件编程时遇到了问题,求解答

2019-07-31 09:32
P
Lzy

我在多文件编程时,想在find_circle_uart.py中调用Uart_Protocol.py时,遇到问题AttributeError:' module' object has no attribute ' Find Circular',应该怎么解决?

问题截图:

0f871bc9-4165-4a86-988f-f94ff2b68199.png

代码如下:

Uart_Protocol.py:

import sensor, image, time

def ExceptionVar(var):
    data = []
    data.append(0)
    data.append(0)

    if var == -1:
        data[0] = 0
        data[1] = 0
    else:
        data[0] = var & 0xFF
        data[1] = var >> 8
    return data


Frame_Cnt = 0
fCnt_tmp = [0,0]

# FormType : 所识别的形状 Ps: 0: Cricle      -> 圆心坐标 -> 半径
#                           1: Rectangle   -> 中心坐标 ->
#                           2: Lines       -> 端点坐标(靠近(0,0)) -> 角度
#                           3: LineSegment -> 端点坐标 -> 角度angle
# FormType_X,FormType_Y : 坐标
# FormType_Other : 其他
def UART_Send(FormType, FormType_X, FormType_Y, FormType_Other):
    global Frame_Cnt
    global fCnt_tmp
    Frame_Head = [170,170]
    Frame_End = [85,85]
    fFormType_tmp = [FormType]
    Frame_Cnt += 1

    if Frame_Cnt > 65534 :
        FrameCnt = 0

    fHead = bytes(Frame_Head)

    fCnt_tmp[0] = Frame_Cnt & 0xFF
    fCnt_tmp[1] = Frame_Cnt >> 8
    fCnt = bytes(fCnt_tmp)

    fFormType = bytes(fFormType_tmp)

    fFormType_X = bytes(ExceptionVar(FormType_X))
    fFormType_Y = bytes(ExceptionVar(FormType_Y))
    fFormType_Other = bytes(ExceptionVar(FormType_Other))

    fEnd = bytes(Frame_End)

    FrameBuffe = fHead + fCnt + fFormType + fFormType_X + fFormType_Y + fFormType_Other + fEnd

    return FrameBuffe

find_circle_uart.py:

# 识别圆形

# OpenMV识别图像中的圆形,并将圆形的坐标,半径通过串口

# 发送给MSP432.

# 串口发送的数据结构参考中科浩电的巡线例程



import sensor, image, time, pyb
import math
import Uart_Protocol

from pyb import UART
from pyb import LED

Led1 = pyb.LED(3) # 蓝灯
                  # Ps:pyb.LED(1):Red; pyb.LED(1):Green; pyb.LED(4):IR

# 指示灯
def LED_flicker():
    Led1.on()
    time.sleep(150)
    Led1.off()
    time.sleep(150)


sensor.reset()

sensor.set_pixformat(sensor.RGB565) # grayscale is faster

sensor.set_framesize(sensor.QQVGA)

sensor.skip_frames(time = 2000)

clock = time.clock()
uart = UART(3, 115200)                         # i使用给定波特率初始化
# uart.init(115200, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化


while(True):

    clock.tick()

    #lens_corr(1.8)畸变矫正
    img = sensor.snapshot().lens_corr(1.8)

    (X,Y,R) = Uart_Protocol.Find_Circular(img)

    print(X,Y,R)

    uart.write(Uart_Protocol.UART_Send_Circular(X,Y,R))

    print("FPS %f" % clock.fps())