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



    • 第一段:
      import sensor, image, time
      from juge_shapes import juge
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...  图像像素大小QQVGA是160✖120
      sensor.skip_frames(30)
      sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
      sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
      sensor.set_auto_exposure(True)
      clock = time.clock()
      
      #black = (25, 95, 77, 22, -16, 63)  # red
      #black = (29, 2, -35, 30, 46, -27)
      black = (34, 0, -41, 25, 60, -37)
      
      def find_max(blobs):    #寻找最大色块函数定义
          max_pixels=0         #通过像素比较
          for blob in blobs:     #blob[0,1,2,3,4]=x,y,w,h,pixels (int)
               if blob[4]>max_pixels:
                   max_blob=blob
                   max_pixels=blob[4]
          return max_blob
      i_r = 0
      i_s = 0
      i_c = 0
      lists = []
      
      while(True):
              img = sensor.snapshot()
              shape = juge(img)
              print(shape)
      
      
      
      第二段:
      
      
      import sensor, image, time
      
      
      #black = (25, 95, 77, 22, -16, 63)  # red
      #black = (29, 2, -35, 30, 46, -27)
      black = (34, 0, -41, 25, 60, -37)
      
      i_r = 0
      i_s = 0
      i_c = 0
      lists = []
      
      
      def find_max(blobs):    #寻找最大色块函数定义
          max_pixels=0         #通过像素比较
          for blob in blobs:     #blob[0,1,2,3,4]=x,y,w,h,pixels (int)
               if blob[4]>max_pixels:
                   max_blob=blob
                   max_pixels=blob[4]
          return max_blob
      
      
      def juge(img):
              circles = img.find_circles(threshold = 4500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 5, r_max = 100, r_step = 2)
              if circles:
                  for c in circles:
                      img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
                      lists.append("circles")   #print("find circles")
      
              else:
                  rects = img.find_rects(threshold = 20000)
                  if rects:
                      for r in rects:
                          img.draw_rectangle(r.rect(), color = (255, 0, 0))
                          for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
                          lists.append("rects")   #print("find rects")
      
                  else:
                      blobs = img.find_blobs([black],area_threshold=50, pixels_threshold=50)
                      if blobs:
                          max_blob=find_max(blobs)
                          img.draw_rectangle(max_blob.rect())
                          img.draw_cross(max_blob.cx(),max_blob.cy())
                          k = max_blob.pixels() / max_blob.area()
                          if(k <= 0.6): lists.append("sanjiao")   #  print("find sanjiao")
                          #continue
              num_r = lists.count("rects")
              num_c = lists.count("circles")
              num_s = lists.count("sanjiao")
              if(num_r > num_s and num_r > num_c):
                  i_r+=1
                  print(num_r, num_s ,num_c)
                  if(i_r >=5):
                     # print("find rects")
                      i_r = 0
                      lists = []
                      return 1
      
              if(num_s > num_c and num_s > num_r):
                  i_s+=1
                  print(num_r,num_s,num_c)
                  if(i_s >=5):
                      #print("find sanjiao")
                      i_s = 0
                      lists = []
                      return 2
      
              if(num_c > num_s and num_c > num_r):
                  i_c+=1
                  print(num_r,num_s,num_c)
                  if(i_c >=5):
                      #print("find circles")
                      i_c = 0
                      lists = []
                      return 3
      
      
      
      


    • https://singtown.com/learn/50029/

      你的代码瞎写的。逻辑不对。