找到原因了,是内存溢出了
sunnyjack236
@sunnyjack236
sunnyjack236 发布的帖子
-
RE: 循环读串口,但是运行一段时间,好像openMV就会断开连接,这是什么原因?
就好像烧录进openMV板子里的程序没有在一直运行一样,openMV板子如果没有在运行会有什么现象吗?
-
循环读串口,但是运行一段时间,好像openMV就会断开连接,这是什么原因?
Single Color RGB565 Blob Tracking Example
This example shows off single color RGB565 tracking using the OpenMV Cam.
import sensor, image, time, pyb
from pyb import UART#4种灯
red_led = pyb.LED(1)
green_led = pyb.LED(2)
blue_led = pyb.LED(3)
infrared_led = pyb.LED(4)#串口设置
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1, timeout_char=1000 ,read_buf_len=64)Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
The below thresholds track in general red/green/blue things. You may wish to tune them...
thresholds = [(6, 100, -64, -8, -32, 32), # day_generic_green_thresholds
(6, 100, -64, -8, -32, 32), # night_generic_green_thresholds
(0, 30, 0, 64, -128, 0)] # generic_blue_thresholdssensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 200)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
camera resolution. "merge=True" merges all overlapping blobs in the image.
day_flag = True
Uart_Rcv0 = 70
Uart_Rcv1 = 0
Igrcnt = 0while(True):
UartRcv1 = uart.readchar()
if(UartRcv1 == 70 or UartRcv1 == 69):
Uart_Rcv0 = UartRcv1
elif(UartRcv1 == 72 or UartRcv1 == 71):
Uart_Rcv1 = UartRcv1
print("Uart_Rcv0=",Uart_Rcv0)
if(Uart_Rcv0 == 70):
print("from_night_to_day")
uart.write('F')
day_flag = True
time.sleep(50)
elif(Uart_Rcv0 == 69):
print("from_day_to_night")
infrared_led.on()
uart.write('E')
day_flag = False
time.sleep(50)
if((Uart_Rcv0 == 69 or Uart_Rcv0 == 70) and Uart_Rcv1 == 72): #下位机会一直给openMV串口发送70,只有触发条件满足时才会发72,
clock.tick()
blue_led.on()
img = sensor.snapshot()
if(day_flag):
for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=3000, merge=True, margin=1):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print("blob.area()=",blob.area())
if (blob.area() >= 5000):
uart.write('A')
Igrcnt = 0
Uart_Rcv1 = 0
else:
for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=3000, margin=1):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print("blob.area()=",blob.area())
if (blob.area() >= 5000):
uart.write('A')
Igrcnt = 0
Uart_Rcv1 = 0Igrcnt += 1 if(Igrcnt >= 4): Igrcnt = 0 uart.write('B') Uart_Rcv1 = 0 blue_led.off() #print(clock.fps())
-
RE: sensor.snapshot() 若是拍照不成功,或者摄像头出故障,返回什么值?
@kidswong999 有个项目,需要对摄像头在使用时自检,如果不能正常拍照了,需要及时通知维修,避免用户使用时体验不佳;
-
sensor.snapshot() 若是拍照不成功,或者摄像头出故障,返回什么值?
# 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 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. 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() print("You're on camera!") img = sensor.snapshot() print("img=",img) #拍照成功返回img= {"w":320, "h":240, "type"="rgb565", #"size":153600},如果拍照不成功,或摄像头出故障,返回什么值,当摄像头出问题了我们怎么能知道? sensor.snapshot().save("example.jpg") # or "example.bmp" (or others) pyb.LED(BLUE_LED_PIN).off() #print("Done! Reset the camera to see the saved image.")
-
232转USB串口通信
#openMV:教程上的例子,想从串口输出‘A’,串口p4、P5,波特率都对,结果应该输出41,实际从串口调试工具收到的结果输出是5F,不太明白? import time from pyb import UART uart = UART(3, 19200) output_str = 'A' while (True): uart.write(output_str) #想从串口输出‘A’,结果应该是41,结果输出5F,不太明白 time.sleep(1000)!