• 免费好用的星瞳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,python没学过语法有点看不懂,那个大佬能帮我把下面两段代码合在一起吗,现在急用,非常感谢



    • 代码1:

      import sensor, image, time
      from pyb import UART
      from pyb import LED
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.set_windowing((200, 200))
      sensor.set_hmirror(True)
      sensor.set_vflip(True)
      sensor.skip_frames(30)
      sensor.set_auto_gain(False, gain_db=13)
      sensor.set_auto_whitebal(False)
      uart = UART(3, 115200, timeout_char=1000)
      uart.init(115200, bits=8, parity=None, stop=1)
      clock = time.clock()
      led_R = LED(1)
      led_G = LED(2)
      threshold = (97, 100, -5, 8, -5, 8)
      while(True):
      	clock.tick()
      	img = sensor.snapshot()
      	img.binary([threshold])
      	circles = img.find_circles(threshold = 5000, x_margin = 10, y_margin = 10, r_margin = 10,
      		r_min = 3, r_max = 50, r_step = 1)
      	img = sensor.snapshot()
      	for c in circles:
      		area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
      		print(c)
      		statistics = img.get_statistics(roi=area)
      		rgb_c_l = img.get_pixel(c.x()-c.r()-8, c.y())
      		rgb_c_r = img.get_pixel(c.x()+c.r()+8, c.y())
      		rgb_c_u = img.get_pixel(c.x(), c.y()-c.r()-8)
      		rgb_c_d = img.get_pixel(c.x(), c.y()+c.r()+8)
      		if rgb_c_l==None or rgb_c_r==None or rgb_c_u==None or rgb_c_d==None:
      			continue
      		rgb_c = [0, 0, 0]
      		rgb_c[0] = (rgb_c_l[0] + rgb_c_r[0] + rgb_c_u[0] + rgb_c_d[0]) // 4
      		rgb_c[1] = (rgb_c_l[1] + rgb_c_r[1] + rgb_c_u[1] + rgb_c_d[1]) // 4
      		rgb_c[2] = (rgb_c_l[2] + rgb_c_r[2] + rgb_c_u[2] + AAAAAAAAAAAAAA[2]) // 4
      		print(rgb_c)
      		if 220<=rgb_c[0] and rgb_c[1]+50<rgb_c[0] and rgb_c[2]+50<rgb_c[0]:
      			img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
      			print('traffic light is red')
      			uart.write('traffic light is red')
      			led_R.on()
      		elif rgb_c[0]+80<rgb_c[1] and 220<=rgb_c[1] and rgb_c[2]+50<rgb_c[1]:
      			img.draw_circle(c.x(), c.y(), c.r(), color = (0, 255, 0))
      			print('traffic light is green')
      			uart.write('traffic light is green')
      			led_G.on()
      		elif 220<=rgb_c[0] and rgb_c[1]+80<=rgb_c[0] and rgb_c[2]+150<rgb_c[0]:
      			img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 0))
      			print('traffic light is yellow')
      			uart.write('traffic light is yellow')
      		else:
      			led_R.off()
      			led_G.off()
      

      代码二

      import sensor, image
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA) # can be QVGA on M7...
      sensor.skip_frames(30)
      sensor.set_auto_gain(False) # must turn this off to prevent image washout...
      while(True):
          img = sensor.snapshot()
          img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
          for code in img.find_qrcodes():
              print(code)
      
      

      结果: