LBP

Dear All,

I use lbp descriptor to recognize a pattern and, to filter local noise, i divide the image in several part with each a lbp descriptor.
My problem is if i use more than 4 lbp pattern, whatever the resolution, i have frequently deconnexion and it does not seem stable.

Do you have any knowledge about this problem and advice to do it better ?
Thanks,

Code ?

Here is a simplified code, where you can select the number of line and column.
If you have an SD Card, you can pass the lbp save step at the 2nd path.

In VGA :

  • 1 lines and 1 columns works
  • 1 lines and 2 columns works
  • 2 lines and 1 columns does not work
  • 2 lines and 2 columns does not work

It stops at the lbp save step.

import sensor, image

# Reset sensor
sensor.reset()
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time=1000)

# Variable to define 
nline = 1
ncolumn = 2
thres = 15000
stext = 2

# Size definition
zoneW = sensor.width()
zoneH = sensor.height()
wcolumn = int(zoneW / ncolumn)
hline = int(zoneH / nline)

# Save lbp features
mode = "save"  #0
if mode == "save" :
   print("save -------------")
   img = sensor.snapshot()
   for i in range(0,nline) :
      for j in range(0,ncolumn) :
         dn = img.find_lbp( (int(j*wcolumn), int(i*hline), int(wcolumn), int(hline)) )
         filename = "lbp%d.lbp" % int(i*ncolumn+j)
         if image.save_descriptor(dn, "%s" % filename) == False :
            print("Error : ", filename)

print("check -------------")
while (True):
   img = sensor.snapshot()
   OK = 0
   for i in range(0, nline) :
      for j in range(0, ncolumn) :
         d1 = img.find_lbp( ( int(j*wcolumn), int(i*hline), int(wcolumn), int(hline) ) )
         filename = "lbp%d.lbp" % int(i*ncolumn+j)
         dn = image.load_descriptor("%s" % filename)
         dist = image.match_descriptor(dn, d1)
         img.draw_string(int(j*wcolumn), int(i*hline) + 10, "%d" % dist, color=(0,0,0), scale=stext)
         if dist < thres :
            OK += 1

   if OK > 0 :
      print( "O_Ok : %d" % OK)
   else :
      print("Nok")

Thanks for your help,

Below is the simplified code, where you can define the number of line and column which define the number of areas where the lbp is defined and checked.
I tested the M7 and H7 camera, and both get problem if i increase the number of line and column.

With openmv 2.2.0 :
For M7 (rev 3.4.1), in VGA :

  • 1 line and 1 column works
  • 1 line and 2 column works
  • 2 line and 1 column does not work
  • 2 line and 2 column does not work
    It stops at the lbp save step.

For H7 (rev 3.4.1), in VGA :

  • 3 lines and 3 columns works but disconnect
import sensor, image

# Reset sensor
sensor.reset()
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time=1000)

# Variable to define
nline = 4
ncolumn = 4
thres = 15000
stext = 2

# Size definition
zoneW = sensor.width()
zoneH = sensor.height()
wcolumn = int(zoneW / ncolumn)
hline = int(zoneH / nline)

# Save lbp features
mode = "save"  #0
if mode == "save" :
   print("save -------------")
   img = sensor.snapshot()
   for i in range(0,nline) :
      for j in range(0,ncolumn) :
         dn = img.find_lbp( (int(j*wcolumn), int(i*hline), int(wcolumn), int(hline)) )
         n = i*ncolumn+j
         filename = "lbp" + str(n) + ".lbp"
         if image.save_descriptor(dn, "%s" % filename) == False :
            print("Error : ", filename)

print("check -------------")
while (True):
   img = sensor.snapshot()
   OK = 0
   for i in range(0, nline) :
      for j in range(0, ncolumn) :
         d1 = img.find_lbp( ( int(j*wcolumn), int(i*hline), int(wcolumn), int(hline) ) )
         filename = "lbp%d.lbp" % int(i*ncolumn+j)
         dn = image.load_descriptor("%s" % filename)
         dist = image.match_descriptor(dn, d1)
         img.draw_string(int(j*wcolumn), int(i*hline) + 10, "%d" % dist, color=(0,0,0), scale=stext)
         if dist < thres :
            OK += 1

   if OK > 0 :
      print( "O_Ok : %d" % OK)
   else :
      print("Nok")

It seems to be a memory problem, but i dont know how free memory.

Thanks for help,

It’s a bug in LBP ROI. Can you test the attached image ?
firmware.zip (923 KB)

Wowwwww, i tested a 6x6 lbp on M7, and it works fine.
Which file from github i have to update to get this ?
Thanks,

lbp.c

Thanks,
I red lbp.c and i discovered the weight are optimized for face recognition.
I would like to use for another use, what is the default values, and how can i define it to my own case ?

I think it depends on the application, you should search for LBP papers.

Well i understand than lbp_weights has a high value around eyes, medium value for mouth and ear, then low level for cheeks.
If i want to have a neutral use, i can set 1 for all the 7x7 matrix.

I dont understand what is for the uniform_tbl matrix ?

Please see the “Face Recognition with Local Binary Patterns” paper if you want more details.

well, the uniform matrix is to reduce the number of lbp (256 possibility) to 59 most common.
So it is not usefull to change for specific use.
Thanks,