logo

AttributeError:'module'object has no attribute 'width'?怎么解决

2021-03-30 14:38
G
u3va_1615271136
# Snapshot Example
#
# Note: You will need an SD card to run this example.
#
# You can use your OpenMV Cam to save image files.

import sensor, image, pyb,time
from pyb import UART

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.

uart = UART(3, 19200,timeout_char=1000)

pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.

pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()

img = sensor.snapshot() # or "example.bmp" (or others)

pyb.LED(BLUE_LED_PIN).off()

uart = UART(3, 19200)
fr = True
while(fr):
    p_width=image.width()
    p_height=image.height()
    uart.write("12345")
    for x in range(p_width):
        for y in range(p_height):
            rgb=img.get_pixel(n,k)
            uart.write(rgb[0])
            uart.write(rgb[1])
            uart.write(rgb[2])
    uart.write("12345")
    fr = False
2021-03-30 18:19
I
网红小智智 星瞳科技

width是获取图像的宽度,你的图像是img,而不是image。

改为img.width()