• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • openmv接受字符串时,为啥会报错



    • 0_1612751082291_屏幕截图 2021-02-08 102408.png

      import sensor, image, time, math
      from pyb import UART
      import json
      import ustruct
      uart = UART(1,115200)
      uart.init(115200, bits=8, parity=None, stop=1)
      thresholdss = (4, 15, 4, 28, 1, 19)
      thresholds = [(12, 50, 30, 79, 12, 127), # generic_red_thresholds
                    (4, 94, -87, -20, -28, 27), # generic_green_thresholds
                    (21, 54, -37, 51, -87, -13)] # generic_blue_thresholds
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      b=0
      red_cx = 1    #必须要定义,否则会有语法错误
      green_cx = 2
      blue_cx = 24
      def sending_data(cx,cy):
      	global uart;
      	data = ustruct.pack("<bbhhb",
      				   0x2C,
      				   0x12,
      				   int(cx),
      				   int(cy),
      				   0x5B)
      	uart.write(data);
      def find_max(circles):
      	max_size=0
      	for circle in circles:
      		if circle.magnitude() > max_size:
      			max_circle=circle
      			max_size = circle.magnitude()
      	return max_circle
      while(True):
          if uart.any ():
              a=uart.readline().decode()
              b=int(a)
              print(a)
          if(b==1):
              clock.tick()
              img = sensor.snapshot()
              for blob in img.find_blobs([thresholdss], merge=True, pixels_threshold=200, area_threshold=200, merge=True):
                  ratio = blob.w() / blob.h()
                  if (ratio >= 0.5) and (ratio <= 1.5):
                      img.draw_rectangle(blob.rect())
                      img.draw_cross(blob.cx(), blob.cy())
                      sending_data(blob.cx(), blob.cy());
                      
          if(b==0):    
              clock.tick()
              img = sensor.snapshot()
              for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=200, merge=True):
                              img.draw_rectangle(blob.rect())
                              img.draw_cross(blob.cx(), blob.cy())
                              red_cx = blob.cx()
              for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=200, merge=True):
                              img.draw_rectangle(blob.rect())
                              img.draw_cross(blob.cx(), blob.cy())
                              green_cx = blob.cx()
              for blob in img.find_blobs([thresholds[2]], pixels_threshold=200, area_threshold=200, merge=True):
                              img.draw_rectangle(blob.rect())
                              img.draw_cross(blob.cx(), blob.cy())
                              blue_cx = blob.cx()
              if red_cx > green_cx and green_cx > blue_cx :
                                          print("123")
                                          uart.write("a\r\n")
              elif  red_cx > blue_cx and blue_cx > green_cx :
                                          print("132")
                                          uart.write("b\r\n")
              elif  green_cx > blue_cx and blue_cx > red_cx :
                                          print("231")
                                          uart.write("c\r\n")
              elif  green_cx > red_cx and red_cx > blue_cx :
                                          print("213")
                                          uart.write("d\r\n")
              elif  blue_cx > green_cx and green_cx > red_cx :
                                          print("321")
                                          uart.write("e\r\n")
              elif  blue_cx > red_cx and red_cx > green_cx :
                                          print("312")
                                          uart.write("f\r\n")
      
      
      
      


    • 因为接收到的不是unicode字符串,你在第40行上看看读取的是啥。

      a = uart.readline()
      print(a)
      a = a.decode()