导航

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

    yzgk 发布的帖子

    • RE: 人脸分辨每个样本都是相差8000多,本人与本人都差7000-9000,换过很多样本,背景均匀,人脸很大,还是不行

      @kidswong999 已经好了,不同人脸虽然差异很小但可以分辨出

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: 人脸分辨每个样本都是相差8000多,本人与本人都差7000-9000,换过很多样本,背景均匀,人脸很大,还是不行

      @kidswong999 https://pan.baidu.com/s/1BW2XXy3weS9N7czQNXiR7g
      提取码:1111

      发布在 OpenMV Cam
      Y
      yzgk
    • 人脸分辨每个样本都是相差8000多,本人与本人都差7000-9000,换过很多样本,背景均匀,人脸很大,还是不行
      import sensor, time, image, lcd, math,pyb
      from pyb import UART
      
      RED_LED_PIN = 1
      BLUE_LED_PIN = 3
      NUM_SUBJECTS = 6 #图像库中不同人数,一共6人
      NUM_SUBJECTS_IMGS = 10 #每人有3张样本图片
      
      uart = UART(3, 115200)
      sensor.reset()
      sensor.set_contrast(3)
      sensor.set_gainceiling(16)
      sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
      sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
      sensor.skip_frames(10)
      sensor.skip_frames(time = 1000) #等待1s
      
      face_cascade = image.HaarCascade("frontalface", stages=25)
      clock = time.clock()
      lcd.init()
      
      def face1():
          #uart.write("a,ok\r\n")
          print("a,ok")
      
          j=0
          sensor.reset()
          sensor.set_contrast(3)
          sensor.set_gainceiling(16)
          sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
          sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
          sensor.skip_frames(10) # Let new settings take affect.
          sensor.skip_frames(time = 1000) #等待1s
      
          while (True):
              pyb.LED(RED_LED_PIN).on()
              img = sensor.snapshot()    # 拍摄一张照片
              lcd.display(sensor.snapshot())
              objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)     #thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
              for r in objects:
                  img.draw_rectangle(r)        #在找到的目标上画框,标记出来
              if objects:
                  for object in objects:
                      fs=object[2]*object[3]
                      if fs>=14884:
                          j+=1
                          if j==10:
                              print(fs)
                              print(objects)
                              #uart.write("a,over\r\n")
                              break
                  if j==10:
                      uart.write("a")
                      pyb.LED(RED_LED_PIN).off()    #红灯灭,蓝灯亮
                      pyb.LED(BLUE_LED_PIN).on()
                      pyb.LED(BLUE_LED_PIN).off()
                      break
      
      def dis_face():
          #global NUM_SUBJECTS  #图像库中不同人数,一共6人
          #NUM_SUBJECTS = 4
      
          #uart.write("c,ok\r\n")
          print("c,ok")
      
          sensor.reset() # Initialize the camera sensor.
          sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
          sensor.set_framesize(sensor.B128X128) # or sensor.QQVGA (or others)
          sensor.set_windowing((92,112))
          sensor.skip_frames(10) # Let new settings take affect.
          sensor.skip_frames(time = 3000) #等待1s
          lcd.init()
      
          #SUB = "s1"
          img = sensor.snapshot() # 拍摄当前人脸。
          #img = image.Image("singtown/%s/1.pgm"%(SUB))
          d0 = img.find_lbp((0, 0, img.width(), img.height()))     #d0为当前人脸的lbp特征
          img = None
          pmin = 999999
          num=0
          pyb.LED(RED_LED_PIN).on()
          lcd.display(sensor.snapshot())
      
          for s in range(1, NUM_SUBJECTS+1):
              #lcd.display(sensor.snapshot())
              dist = 0
              for i in range(2, NUM_SUBJECTS_IMGS+1):
                  img = image.Image("sample/s%d/%d.pgm"%(s, i))
                  d1 = img.find_lbp((0, 0, img.width(), img.height())) #d1为第s文件夹中的第i张图片的lbp特征
                  dist += image.match_descriptor(d0, d1) #计算d0 d1即样本图像与被检测人脸的特征差异度。
              print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS))
              if (dist/NUM_SUBJECTS_IMGS)<pmin:
                  pmin=(dist/NUM_SUBJECTS_IMGS)
                  num=s
              print(pmin)
          if pmin<10000:
              if num==1:
                  uart.write("d")
              if num==2:
                  uart.write("e")
              if num==3:
                  uart.write("f")
              if num==4:
                  uart.write("g")
              if num==5:
                  uart.write("h")
              if num==6:
                  uart.write("i")
          elif pmin>10000:
              uart.write("j")
          print(num) # num为当前最匹配的人的编号。
          #uart.write("%d\r\n" %num)
          #uart.write("c,over\r\n")
      
          pyb.LED(RED_LED_PIN).off()    #红灯灭,蓝灯亮
          pyb.LED(BLUE_LED_PIN).on()
          pyb.LED(BLUE_LED_PIN).off()
      
      def dis_face1():
          #global NUM_SUBJECTS  #图像库中不同人数,一共6人
          #NUM_SUBJECTS = 4
      
          #uart.write("c,ok\r\n")
          print("m,ok")
      
          sensor.reset() # Initialize the camera sensor.
          sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
          sensor.set_framesize(sensor.B128X128) # or sensor.QQVGA (or others)
          sensor.set_windowing((92,112))
          sensor.skip_frames(10) # Let new settings take affect.
          sensor.skip_frames(time = 1000) #等待1s
          lcd.init()
      
          #SUB = "s1"
          img = sensor.snapshot() # 拍摄当前人脸。
          #img = image.Image("singtown/%s/1.pgm"%(SUB))
          d0 = img.find_lbp((0, 0, img.width(), img.height()))     #d0为当前人脸的lbp特征
          img = None
          pmin = 999999
          num=0
          pyb.LED(RED_LED_PIN).on()
          lcd.display(sensor.snapshot())
      
          for s in range(1, NUM_SUBJECTS+1):
              #lcd.display(sensor.snapshot())
              dist = 0
              for i in range(2, NUM_SUBJECTS_IMGS+1):
                  img = image.Image("sample/s%d/%d.pgm"%(s, i))
                  d1 = img.find_lbp((0, 0, img.width(), img.height())) #d1为第s文件夹中的第i张图片的lbp特征
                  dist += image.match_descriptor(d0, d1) #计算d0 d1即样本图像与被检测人脸的特征差异度。
              print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS))
              if (dist/NUM_SUBJECTS_IMGS)<pmin:
                  pmin=(dist/NUM_SUBJECTS_IMGS)
                  num=s
              print(pmin)
          #if pmin<6500:
              #if num==1:
                  #uart.write("d")
              #if num==2:
                  #uart.write("e")
              #if num==3:
                  #uart.write("f")
              #if num==4:
                  #uart.write("g")
              #if num==5:
                  #uart.write("h")
              #if num==6:
                  #uart.write("i")
          #elif pmin>6500:
              uart.write("j")
          print(num) # num为当前最匹配的人的编号。
          #uart.write("%d\r\n" %num)
          #uart.write("c,over\r\n")
      
          pyb.LED(RED_LED_PIN).off()    #红灯灭,蓝灯亮
          pyb.LED(BLUE_LED_PIN).on()
          pyb.LED(BLUE_LED_PIN).off()
      
      def length():
          #uart.write("b,ok\r\n")
          print("b,ok")
      
          K=4148#the value should be measured
          length=0
      
          sensor.reset()
          sensor.set_contrast(3)
          sensor.set_gainceiling(16)
          sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
          sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
          sensor.skip_frames(10) # Let new settings take affect.
          sensor.skip_frames(time = 1000) #等待1s
      
          while (True):
              pyb.LED(RED_LED_PIN).on()
              img = sensor.snapshot()    # 拍摄一张照片
              lcd.display(sensor.snapshot())
              objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)     #thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
      
              for r in objects:
                  img.draw_rectangle(r)        #在找到的目标上画框,标记出来
              if objects:
                  for object in objects:
                      print(object[2],object[3])
                      cx = int(object[0]+object[2]/2)
                      cy = int(object[1]+object[3]/2)
      
                      Lm = (object[2]+object[3])/2
                      length = K/Lm
                      img.draw_cross(cx, cy) # cx, cy
      
                      print(length)
                      #uart.write("%d\r\n" %length)
                      #uart.write("b,over\r\n")
                      break
              if length!=0:
                  uart.write("l")
                  pyb.LED(RED_LED_PIN).off()    #红灯灭,蓝灯亮
                  pyb.LED(BLUE_LED_PIN).on()
                  pyb.LED(BLUE_LED_PIN).off()
                  break
      
      def snapshot1():
          #uart.write("k,ok\r\n")
          print("k,ok")
      
      
          print("%d\r\n" %NUM_SUBJECTS)
      
          sensor.reset() # Initialize the camera sensor.
          sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
          sensor.set_framesize(sensor.HQVGA) # B128X128or sensor.QQVGA (or others)
          sensor.set_windowing((92,112))
          sensor.skip_frames(10) # Let new settings take affect.
          sensor.skip_frames(time = 1000)
          clock = time.clock()
      
          num = 2 #设置被拍摄者序号,第一个人的图片保存到s1文件夹,第二个人的图片保存到s2文件夹,以此类推。每次更换拍摄者时,修改num值。
          n = 10 #设置每个人拍摄图片数量。
      
          while(n):
              pyb.LED(RED_LED_PIN).on()     #红灯亮
              lcd.display(sensor.snapshot())
              sensor.skip_frames(time = 3000) #等待3s,准备一下表情。
      
              pyb.LED(RED_LED_PIN).off()    #红灯灭,蓝灯亮
              pyb.LED(BLUE_LED_PIN).on()
              print(n)
              sensor.snapshot().save("data/s%s/%s.pgm" % (num, n) ) #保存截取到的图片到SD卡
              n -= 1
              pyb.LED(BLUE_LED_PIN).off()
      
              if n==1:
                  print("Done! Reset the camera to see the saved image.")
      
              #uart.write("k,over\r\n")
              uart.write("k\r\n")
      
      
      while(True):
      
          #clock.tick()
      
      
          #img = sensor.snapshot()        #1
          #lcd.display(sensor.snapshot()) #2  这两行无论哪一行运行,串口都无法接收到数据
      
          a='0'
      
          if uart.any():
              a=uart.readline().decode()
              print(a)
         #pyb.delay(100)
      
          if a=='a':
              #uart.write("a,ready\r\n")
              face1()              #人脸识别(日常模式)
              print("face1")
      
          if a=='b':
              #uart.write("b,ready\r\n")
              length()              #人脸识别(测额头距)
              print("length")
      
          if a=='c':
              #uart.write("c,ready\r\n")
              dis_face()           #分辨人脸
              print("dis_face")
      
          if a=='k':
              #uart.write("k,ready\r\n")
              snapshot1()           #拍照保存(人脸样本)
              print("snapshot1")
      
          if a=='m':
              #uart.write("c,ready\r\n")
              dis_face1()           #分辨人脸
              print("dis_face1")
      
          #else:
              #print("not a ")
              #print("a:",a)
      
      
      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 谢谢你,问题解决了

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 0_1619771420003_4.png 这两行,你可以把代码贴到IDE中去试一下,只要这两行不注释掉,就无法发送数据

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 三次截图的不同之处在于,我把代码中的两行代码注释与否,所以才会得出不同结果,我想问的是代码中标记的两行代码为什么会影响串口发送数据?因为我看不到库是怎么写的,只有使用方法,所以现在不知道是哪里冲突还是怎样

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 0_1619771142268_3.jpg 这是第三张,接收到数据

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 0_1619771117326_2.jpg 这是第二张,没接到数据

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 0_1619771094232_1.jpg 这是第一张,没接到数据

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 你可以截下图我看下嘛?

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 我第一张是正常代码,无法接收到数据
      第二张是把拍照的函数注释掉,也无法接收
      第三张是把拍照和lcd显示的两个函数全注释掉,才能正常接收数据

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      @kidswong999 是前两张没收到数据,最后一张收到了

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      我想做的项目需要openMV作为识别装置,识别不同东西给32发送不同指令,并通过代码写的逻辑使得两块单片机通过互相通信实现自主运行

      发布在 OpenMV Cam
      Y
      yzgk
    • RE: uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?

      标记的两行中,只要存在任意一行就无法接收到数据,是芯片处理能力不够吗?我见lcd与串口3的管脚定义也并没有重复

      发布在 OpenMV Cam
      Y
      yzgk
    • uart.write()与sensor.snapshot()和lcd.display()为什么不能同时使用?
      import sensor, time, image, lcd, math,pyb
      from pyb import UART
      
      #RED_LED_PIN = 1
      #BLUE_LED_PIN = 3
      
      uart = UART(3, 115200)
      sensor.reset()
      sensor.set_contrast(3)
      sensor.set_gainceiling(16)
      sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
      sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
      sensor.skip_frames(10)
      sensor.skip_frames(time = 5000) #等待5s
      
      face_cascade = image.HaarCascade("frontalface", stages=25)
      clock = time.clock()
      lcd.init()
      
      def face1():
          uart.write("ok\r\n")
          print("ok")
          sensor.reset()
          sensor.set_contrast(3)
          sensor.set_gainceiling(16)
          sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
          sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
          sensor.skip_frames(10) # Let new settings take affect.
          sensor.skip_frames(time = 5000) #等待5s
      
          while (True):
              img = sensor.snapshot()    # 拍摄一张照片
              lcd.display(sensor.snapshot())
              objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)     #thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
              for r in objects:
                  img.draw_rectangle(r)        #在找到的目标上画框,标记出来
              if objects:
                  for object in objects:
                      fs=object[2]*object[3]
                  if fs>=14884:
                      print(fs)
                      print(objects)
                      break
      
      while(True):
         clock.tick()
         img = sensor.snapshot()        #1
         lcd.display(sensor.snapshot()) #2  这两行无论哪一行运行,串口都无法接收到数据
         a='0'
         if uart.any():
             a=uart.readline().decode()
             print(a)
         #pyb.delay(100)
         if a=='a':
              uart.write("a\r\n")
              #img = sensor.snapshot()
              face1()
              print("face1")
      

      0_1619697018286_1.jpg 0_1619697025996_2.jpg 0_1619697030893_3.jpg

      发布在 OpenMV Cam
      Y
      yzgk