导航

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

    uye4 发布的帖子

    • 请问下识别颜色和形状时,画面会卡顿,是不是和自己写程序逻辑有关?

      🤓

      发布在 OpenMV Cam
      U
      uye4
    • 判断色块坐标是否在画面中心坐标一定范围内,报错?希望能看下我这逻辑代码是否可以?
      # Blob Detection Example
      #
      # This example shows off how to use the find_blobs function to find color
      # blobs in the image. This example in particular looks for dark green objects.
      
      import sensor, image, time, pyb,mjpeg
      from pyb import UART,Pin,Timer
      import utime
      import json
      uart=pyb.UART(3,115200,timeout_char=1000)
      uart.init(115200, bits=8, parity=None, stop=1)
      
      p_out = Pin('P7',Pin.OUT_PP)
      p_out.low()
      
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      blue_threshold_01 = (0, 100, -16, 127, -128, -31)
      
      #设置蓝色的阈值,括号里面的数值分别是L A B 的最大值和最小值(minL, maxL, minA,
      # maxA, minB, maxB),LAB的值在图像左侧三个坐标图中选取。如果是灰度图,则只需
      #设置(min, max)两个数字即可。
      
      # You may need to tweak the above settings for tracking green things...
      # Select an area in the Framebuffer to copy the color settings.
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QVGA) # use QVGA for quailtiy ,use QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False)
      #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
      clock = time.clock() # Tracks FPS.
      
      '''
        扩宽roi
      '''
      def expand_roi(roi):
          # set for QQVGA 160*120
          extra = 5
          win_size = (160, 120)
          (x, y, width, height) = roi
          new_roi = [x-extra, y-extra, width+2*extra, height+2*extra]
      
          if new_roi[0] < 0:
              new_roi[0] = 0
          if new_roi[1] < 0:
              new_roi[1] = 0
          if new_roi[2] > win_size[0]:
              new_roi[2] = win_size[0]
          if new_roi[3] > win_size[1]:
              new_roi[3] = win_size[1]
      
          return tuple(new_roi)
      
      
      
      
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
          #  pixels_threshold=100, area_threshold=100
          blobs = img.find_blobs([blue_threshold_01], area_threshold=150)
      
          if blobs:
          #如果找到了目标颜色
            # print(blobs)
             for blob in blobs:
             #迭代找到的目标颜色区域
                  is_circle = False
                  max_circle = None
                  max_radius = -1
      
                  new_roi = expand_roi(blob.rect())
      
                  for c in img.find_circles(threshold = 2000, x_margin = 20, y_margin = 20, r_margin = 10, roi=new_roi):
                      is_circle = True
                      # img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 255))
                      if c.r() > max_radius:
                          max_radius = c.r()
                          max_circle = c
                  if is_circle:
                      # 如果有对应颜色的圆形 标记外框
                      # Draw a rect around the blob.
                      img.draw_rectangle(new_roi) # rect
                      img.draw_rectangle(blob.rect()) # rect
                      #用矩形标记出目标颜色区域
                      img.draw_cross(blob[5], blob[6]) # cx, cy
                      img.draw_circle(max_circle.x(), max_circle.y(), max_circle.r(), color = (0, 0, 255))
                      img.draw_circle(max_circle.x(), max_circle.y(), max_circle.r() + 1, color = (0, 0, 255))
                      print(blob[5], blob[6])
                      z=100            
                      x_h=(blob[5]>>8)&0xff
                      x_l=blob[5]&0xff
                      y_h=(blob[6]>>8)&0xff
                      y_l=blob[6]&0xff
                      z_h=(z>>8)&0xff
                      z_l=z&0xff
                      data=bytearray([0x02,x_h,x_l,y_h,y_l,z_h,z_l,0x06,0x0D,0X0A])
                      print('you send:',data)
                      uart.write(data)
                  if (sensor.width/2 -10<=blob[5]<=sensor.width/2 +10) and (sensor.height/2 -10<=blob[6]<=sensor.height/2 +10):
                      z=50
                      x_h=(blob[5]>>8)&0xff
                      x_l=blob[5]&0xff
                      y_h=(blob[6]>>8)&0xff
                      y_l=blob[6]&0xff
                      z_h=(z>>8)&0xff
                      z_l=z&0xff
                      data1=bytearray([0x02,x_h,x_l,y_h,y_l,z_h,z_l,0x06,0x0D,0X0A])
                      print('you send:',data1)
                      uart.write(data1)
                      timesleep(1000)
                      timesleep(1000)
                      timesleep(1000)
                      z=0
                      x_h=(blob[5]>>8)&0xff
                      x_l=blob[5]&0xff
                      y_h=(blob[6]>>8)&0xff
                      y_l=blob[6]&0xff
                      z_h=(z>>8)&0xff
                      z_l=z&0xff
                      data2=bytearray([0x02,x_h,x_l,y_h,y_l,z_h,z_l,0x06,0x0D,0X0A])
                      print('you send:',data2)
                      uart.write(data2)
                      #p_out.high()
      
      
          print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
          # connected to your computer. The FPS should increase once disconnected.!
      

      0_15563372ng

      发布在 OpenMV Cam
      U
      uye4
    • 运行测试的例程,openmv重新上电后,sd卡里的视频0字节大小,打不开?

      import sensor, image, time, mjpeg, 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(10) # Let new settings take affect.
      clock = time.clock() # Tracks FPS.
      pyb.LED(RED_LED_PIN).on()
      sensor.skip_frames(30) # Give the user time to get ready.
      pyb.LED(RED_LED_PIN).off()
      pyb.LED(BLUE_LED_PIN).on()
      m = mjpeg.Mjpeg("test1.mjpeg")
      #mjpeg.Mjpeg(filename, width=Auto, height=Auto)创建一个mjpeg对象,
      #filename为保存mjpeg动图的文件路径
      print("You're on camera!")
      for i in range(200):
      clock.tick()

      m.add_frame(sensor.snapshot())

      #mjpeg.add_frame(image, quality=50)

      #quality为视频压缩质量。

      print(clock.fps())
      m.close(clock.fps())
      pyb.LED(BLUE_LED_PIN).off()
      print("Done! Reset the camera to see the saved recording.")
      测试的例程,重新上电还是一样0字节

      发布在 OpenMV Cam
      U
      uye4
    • RE: 用保存视频的例程,在sd卡里的视频怎么是0字节大小?

      @kidswong999 import sensor, image, time, mjpeg, 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(10) # Let new settings take affect.

      clock = time.clock() # Tracks FPS.

      pyb.LED(RED_LED_PIN).on()

      sensor.skip_frames(30) # Give the user time to get ready.

      pyb.LED(RED_LED_PIN).off()

      pyb.LED(BLUE_LED_PIN).on()

      m = mjpeg.Mjpeg("test1.mjpeg")

      #mjpeg.Mjpeg(filename, width=Auto, height=Auto)创建一个mjpeg对象,

      #filename为保存mjpeg动图的文件路径

      print("You're on camera!")

      for i in range(200):

      clock.tick()
      
      m.add_frame(sensor.snapshot())
      
      #mjpeg.add_frame(image, quality=50)
      
      #quality为视频压缩质量。
      
      print(clock.fps())
      

      m.close(clock.fps())

      pyb.LED(BLUE_LED_PIN).off()

      print("Done! Reset the camera to see the saved recording.")
      测试的例程,重新上电还是一样0字节

      发布在 OpenMV Cam
      U
      uye4
    • 用保存视频的例程,在sd卡里的视频怎么是0字节大小?

      0_1555991686810_858f2cd2-c2e0-4dc4-a3f0-3d4629c8a530-image.png

      发布在 OpenMV Cam
      U
      uye4
    • RE: 数据类型转化迟迟不行?
      import sensor, image, time, pyb, math
      from pyb import UART,Pin,Timer
      import utime
      import json
      uart=pyb.UART(3,115200,timeout_char=1000)
      
      
      threshold_index = 0 # 0 for red, 1 for green, 2 for blue
      
      # 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 = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
                    (30, 100, -64, -8, -32, 32), # generic_green_thresholds
                    (0, 100, -16, 127, -128, -31)] # generic_blue_thresholds
      #-------------------摄像头初始化-----------------------------
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      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()
      #start = pyb.millis() # get value of millisecond counter  获取毫秒计数器的值
      verify_code=b'\xFF\x00\xAA\xEA\xFF'
      # 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.
      def find_max(blobs):
          max_size=0
          for blob in blobs:
           if blob[2]*blob[3]>max_size:
              max_blob=blob
              max_size=blob[2]*blob[3]
          return max_blob
         #if(blob[5]==sensor.width/2) and (blob[6]==sensor.height/2):
      while(True):
          clock.tick()
          img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)#摄像头畸变矫正
          blobs = img.find_blobs([thresholds[2]])
          #print(img.width()/2,img.height()/2)
      
          if blobs:
              max_blob=find_max(blobs)
              #img.draw_rectangle(max_blob.rect())
              img.draw_cross(max_blob.cx(),max_blob.cy())
              print("you're on camera!")
              #sensor.snapshot().save("LHP.jpg")
              #x="[%u]"%(max_blob.cx())
              #y="[%u]"%(max_blob.cy())
              x=hex(max_blob.cx())
              y=hex(max_blob.cy())
              print(x,y)
              x_h=(x>>8)&0xff
              #x_l=hex(x&0xff)
              #y_h=((y>>8)&0x0ff)
              #y_l=(y&0xff)
              #rc=x_h+x_l+y_h+y_l
              #data=bytearray([0x02,x_h,x_l,y_h,y_l,0x00,rc])
             #print('you send:',data)
      

      报错就和上面一样,我就想把坐标数据拆成十六进制的打包发送

      发布在 OpenMV Cam
      U
      uye4
    • 数据类型转化迟迟不行?

      0_1555762894291_707312c6-72b9-43ff-b74e-0eadd15278ec-image.png
      试了好几种转换,就是报错。

      发布在 OpenMV Cam
      U
      uye4
    • RE: 代码出现类型错误?如何解决?

      @gtxp 楼主,解决没

      发布在 OpenMV Cam
      U
      uye4
    • RE: 形状检测和颜色检测,颜色能识别蓝色圆,形状却圈住红色的圆

      0_1555644430540_A4.png 报错了,我想先颜色检测后再霍夫圆,不知道怎么解决你说的for c in img.find_circles的问题

      发布在 OpenMV Cam
      U
      uye4
    • 形状检测和颜色检测,颜色能识别蓝色圆,形状却圈住红色的圆
      # Single Color RGB565 Blob Tracking Example
      #
      # This example shows off single color RGB565 tracking using the OpenMV Cam.
      
      import sensor, image, time,pyb,math
      from pyb import UART,Pin,Timer
      import json
      uart=pyb.UART(3,115200,timeout_char=1000)
      
      
      threshold_index = 0 # 0 for red, 1 for green, 2 for blue
      
      # 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 = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
                    (30, 100, -64, -8, -32, 32), # generic_green_thresholds
                    (0, 100, -16, 127, -128, -31)] # generic_blue_thresholds
      #-------------------摄像头初始化-----------------------------
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      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()
      #start = pyb.millis() # get value of millisecond counter  获取毫秒计数器的值
      
      # 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.
      def find_max(blobs):
          max_size=0
          for blob in blobs:
           if blob[2]*blob[3]>max_size:
              max_blob=blob
              max_size=blob[2]*blob[3]
          return max_blob
         #if(blob[5]==sensor.width/2) and (blob[6]==sensor.height/2):
      while(True):
          clock.tick()
          img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)#摄像头畸变矫正
          for c in img.find_circles(threshold=3500,x_margin=20,y_margin=20,
          r_margin=20,r_min=2,r_max=100,r_step=2):
              area=(c.x()-c.r(),c.y()-c.r(),2*c.r(),2*c.r())
              statistics=img.get_statistics(roi=area)
              #print(statistics)
      
          blobs = img.find_blobs([thresholds[2]])
          #print(img.width()/2,img.height()/2)
      
          if blobs:
              img.draw_circle((c.x(),c.y(),c.r()),color=(0,0,255))
              max_blob=find_max(blobs)
              #img.draw_rectangle(max_blob.rect())
              img.draw_cross(max_blob.cx(),max_blob.cy())
              output_str="[%d,%d]"%(max_blob.cx(),max_blob.cy())
              print('you send:',output_str)
              uart.write( output_str+'\r\n')
          else:
               #img.draw_rectangle(area,color=(255,0,0))
               print('not found!')
      

      0_1555560618830_~GZ)[78~P(OU]CK68_RV4(N.png

      发布在 OpenMV Cam
      U
      uye4