导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. fd2z
    • 举报资料
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    fd2z

    @fd2z

    0
    声望
    22
    楼层
    1376
    资料浏览
    0
    粉丝
    1
    关注
    注册时间 最后登录
    位置 China 年龄 25

    fd2z 关注

    fd2z 发布的帖子

    • RE: 程序里二次改变白平衡和自动增益有什么要注意的吗?

      ..........求助

      发布在 OpenMV Cam
      fd2z
    • 有木有什么好方法分辨出红绿蓝白黑五种颜色

      黑白色块分辨时,如果只有黑或只有白时色块识别并没有工作是为何呢
      我红绿蓝用的是彩图色块识别,黑白用的是灰度
      黑白时总是只能识别其中一种颜色

      import sensor,time
      import image,math
      from pyb import LED
      
      
      
      kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
      kernel = [-1, -1, -1,\
                -1, +8, -1,\
                -1, -1, -1]
      redthresholds = (29, 99, 19, 127, -128, 127)# grayscale thresholds设置阈值
      greenthresholds = (30, 100, -64, -8, -32, 32)
      bluethresholds = (19, 72, -128, 127, -128, -8)
      graythresholds = [(65, 128)]
      whitethresholds = (185, 255)
      blackthresholds = (0,20)
      roi=(60,40,40,40)
      red_color_code = 1
      blue_color_code = 2
      
      green_color_code = 3
      sensor.reset() # 初始化 sensor.
      sensor.set_pixformat(sensor.RGB565) # or sensor.RGB565
      sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
      sensor.skip_frames(10) # 让新的设置生效
      sensor.set_windowing(roi)
      clock = time.clock() # 追踪FPS
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          image = sensor.snapshot() # Take a picture and return the image.
          blobs = image.find_blobs([redthresholds, greenthresholds, bluethresholds], area_threshold=100)
          if blobs:
              print(blobs)
              for blob in blobs:
                  x = blob[0]
                  y = blob[1] #
                  width = blob[2] # 色块矩形的宽度
                  height = blob[3] # 色块矩形的高度
                  center_x = blob[5] # 色块中心点x值
                  center_y = blob[6] # 色块中心点y值
                  color_code = blob[8]
      
                  if color_code == red_color_code:
                      image.draw_rectangle(blob.rect())
                      #image.draw_rectangle(0, 0, 20, 20,color=greenthresholds,thickness=1,fill=False)
                      image.draw_cross(center_x, center_y)
                      output_str="[%d,%d]" % (blob.cx(),blob.cy()) #方式1
                      print(output_str)
                  elif color_code == green_color_code:
                      image.draw_rectangle(blob.rect())
                      image.draw_cross(center_x, center_y)
                      output_str="[%d,%d]" % (blob.cx(),blob.cy()) #方式1
                      print(output_str)
                  elif color_code == blue_color_code:
                      image.draw_rectangle(blob.rect())
                      image.draw_cross(center_x, center_y)
                      output_str="[%d,%d]" % (blob.cx(),blob.cy()) #方式1
                      print(output_str)
      
          else :
              img = sensor.snapshot()
      
              img.to_grayscale()
      
              img.binary(graythresholds)
      
              blob = img.find_blobs([whitethresholds], pixels_threshold=10, area_threshold=10, merge=True)
      
              if blob:
      
                  print('4')
              else :
                  print('5')
      
      
      发布在 OpenMV Cam
      fd2z
    • RE: 程序里二次改变白平衡和自动增益有什么要注意的吗?

      @kidswong999 🙏

      发布在 OpenMV Cam
      fd2z
    • RE: 程序里二次改变白平衡和自动增益有什么要注意的吗?

      @kidswong999 麻烦您解释详细一些,我没听太懂,谢谢qwq

      发布在 OpenMV Cam
      fd2z
    • RE: 请问如何在一片白背景里找到一个较白物块

      有办法吗。。。。

      发布在 OpenMV Cam
      fd2z
    • RE: 程序里二次改变白平衡和自动增益有什么要注意的吗?

      但是打开白平衡和自动增益扫十字效果(我的用法和色块识别类似)特别不好

      
      
      THRESHOLD = [(0,100)]
      
      BINARY_VISIBLE = True
      
      import sensor, image, time, math, utime
      from pyb import UART
      from pyb import LED
      import json
      roi=(0,60,160,60)
      roi_1 = [(20, 0, 120, 20),         #  北
                  (20, 100, 120, 20),     # 南
                  (0, 0, 20, 120),        #  西
                  (140, 0, 20, 120),      #  东
                  (60,40,40,40)]          #   中
      
      #LED(1).on()
      #LED(2).on()
      #LED(3).on()
      sensor.reset()
      sensor.set_vflip(False)
      sensor.set_hmirror(False)
      sensor.set_pixformat(sensor.GRAYSCALE)
      
      sensor.set_framesize(sensor.QQVGA)
      sensor.set_auto_whitebal(False) # turn this off.
      sensor.set_auto_gain(False)
      sensor.skip_frames(time = 2000)
      
      clock = time.clock()
      buf =[0 for i in range(5)]
      low_threshold = (0, 40                         )
      uart = UART(3, 115200)
      while(True):
          m = -1
          isten = 0
          #img = sensor.snapshot()
          sensor.set_auto_whitebal(False) # turn this off.
          sensor.set_auto_gain(False)
          utime.sleep_us(90)
          img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)
          img.binary([low_threshold],invert = 1)
          for r in roi_1:
              m += 1
              blobs = img.find_blobs(THRESHOLD, roi=r[0:4],pixels_threshold=100, area_threshold=100, merge=True)
              #img.draw_rectangle(r[0:4], color=(255,0,0))
              if blobs:
                  most_pixels = 0
                  largest_blob = 0
                  for i in range(len(blobs)):
                  #目标区域找到的颜色块(线段块)可能不止一个,找到最大的一个,作为本区域内的目标直线
                      if blobs[i].pixels() > most_pixels:
                         most_pixels = blobs[i].pixels()
                          #merged_blobs[i][4]是这个颜色块的像素总数,如果此颜色块像素总数大于
                         largest_blob = i
                  # Draw a rect around the blob.
                  img.draw_rectangle(blobs[largest_blob].rect())
                  #将此区域的像素数最大的颜色块画矩形和十字形标记出来
                  img.draw_cross(blobs[largest_blob].cx(),
                                 blobs[largest_blob].cy())
                  buf[m] = 1
              else:
                  buf[m] = 0
      
      
          utime.sleep_us(90)
          sensor.set_auto_whitebal(True) # turn this off.    
          sensor.set_auto_gain(True)
          utime.sleep_us(90)
          clock.tick()
          img = sensor.snapshot().binary(THRESHOLD) if BINARY_VISIBLE else sensor.snapshot()
          line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD],roi=(0,60,160,60))
      
          if (line):
                rho_err = abs(line.rho())-img.width()//2+256
                img.draw_line(line.line(), color = 127)
      
          print("theta %f, rho = %f " % (line.theta(), line.rho()) if (line) else "N/A")
          output_str="%d" %rho_err
          print(output_str)
      
          if buf[0]==1 and buf[1] ==1 and buf[2] ==1 and buf[3] ==1 and buf[4] ==1:
                 isten = 1
          print(isten)
          out_str="[%d" %isten
          uart.write(out_str )
      
      发布在 OpenMV Cam
      fd2z
    • 程序里二次改变白平衡和自动增益有什么要注意的吗?

      我的颜色识别和二值化巡线算法的白平衡和自动增益设置是相反的
      这两算法单独时都能用但是放在一起总是不能完美使用
      我就是在while(true)里两次设置白平衡和自动增益
      但是画面会屏闪,前一帧的画面很正常,下一帧的画面就。。。不正常

      发布在 OpenMV Cam
      fd2z
    • RE: 如何巡线又清楚的识别出十字路口

      巡线没有问题但是扫十字的结果很偶然
      很少成功

      发布在 OpenMV Cam
      fd2z
    • 如何巡线又清楚的识别出十字路口
      
      
      THRESHOLD = [(0,100)]
      
      BINARY_VISIBLE = True
      
      import sensor, image, time, math, utime
      from pyb import UART
      from pyb import LED
      import json
      roi=(0,60,160,60)
      roi_1 = [(20, 0, 120, 20),         #  北
                  (20, 100, 120, 20),     # 南
                  (0, 0, 20, 120),        #  西
                  (140, 0, 20, 120),      #  东
                  (60,40,40,40)]          #   中
      
      #LED(1).on()
      #LED(2).on()
      #LED(3).on()
      sensor.reset()
      sensor.set_vflip(False)
      sensor.set_hmirror(False)
      sensor.set_pixformat(sensor.GRAYSCALE)
      
      sensor.set_framesize(sensor.QQVGA)
      sensor.set_auto_whitebal(False) # turn this off.
      sensor.set_auto_gain(False)
      sensor.skip_frames(time = 2000)
      
      clock = time.clock()
      buf =[0 for i in range(5)]
      low_threshold = (0, 40                         )
      uart = UART(3, 115200)
      while(True):
          m = -1
          isten = 0
          #img = sensor.snapshot()
          sensor.set_auto_whitebal(False) # turn this off.
          sensor.set_auto_gain(False)
          utime.sleep_us(90)
          img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)
          img.binary([low_threshold],invert = 1)
          for r in roi_1:
              m += 1
              blobs = img.find_blobs(THRESHOLD, roi=r[0:4],pixels_threshold=100, area_threshold=100, merge=True)
              #img.draw_rectangle(r[0:4], color=(255,0,0))
              if blobs:
                  most_pixels = 0
                  largest_blob = 0
                  for i in range(len(blobs)):
                  #目标区域找到的颜色块(线段块)可能不止一个,找到最大的一个,作为本区域内的目标直线
                      if blobs[i].pixels() > most_pixels:
                         most_pixels = blobs[i].pixels()
                          #merged_blobs[i][4]是这个颜色块的像素总数,如果此颜色块像素总数大于
                         largest_blob = i
                  # Draw a rect around the blob.
                  img.draw_rectangle(blobs[largest_blob].rect())
                  #将此区域的像素数最大的颜色块画矩形和十字形标记出来
                  img.draw_cross(blobs[largest_blob].cx(),
                                 blobs[largest_blob].cy())
                  buf[m] = 1
              else:
                  buf[m] = 0
      
      
          utime.sleep_us(90)
          sensor.set_auto_whitebal(True) # turn this off.    
          sensor.set_auto_gain(True)
          utime.sleep_us(90)
          clock.tick()
          img = sensor.snapshot().binary(THRESHOLD) if BINARY_VISIBLE else sensor.snapshot()
          line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD],roi=(0,60,160,60))
      
          if (line):
                rho_err = abs(line.rho())-img.width()//2+256
                img.draw_line(line.line(), color = 127)
      
          print("theta %f, rho = %f " % (line.theta(), line.rho()) if (line) else "N/A")
          output_str="%d" %rho_err
          print(output_str)
      
          if buf[0]==1 and buf[1] ==1 and buf[2] ==1 and buf[3] ==1 and buf[4] ==1:
                 isten = 1
          print(isten)
          out_str="[%d" %isten
          uart.write(out_str )
      

      这是我的代码

      发布在 OpenMV Cam
      fd2z
    • RE: 如何识别异形交叉路口

      但是误差还是很大
      我加了偏振镜来减弱反光影响

      发布在 OpenMV Cam
      fd2z