Opencv_contrib: LBFmodel.yaml not loading on Android

Created on 31 May 2020  Â·  2Comments  Â·  Source: opencv/opencv_contrib

Hi,

Very recently the OpenCV extra classes were brilliantly imported enabling builds in Python-for-Android. When trying to detect facial landmarks on Android I received the following error:

"Nonetype object has no attribute 'fit'"

I traced the problem to the process of loading the LBFmodel.yaml file where loadModel returns 'None'. Why isn't it loading? Is it due to the file size (36MB) and a memory issue for example? (if absolutely necessary I will learn how train my own LBF lighter weight model). Any help would be greatly appreciated :) It has no trouble loading the 'haarcascade_frontalface_default.xml' model and easily finds face binding boxes. The file paths are all correct also.

An extract from my code is below:

      lm_model_2=c_dir+"lbfmodel.yaml"

      ii_file = "tmp_r_i.png"
      tmp_tiny_width = 600
      tmp_img = p_img.open(i_file)
      i_perc = tmp_tiny_width/float(tmp_img.size[0])
      i_height = int(float(tmp_img.size[1]) * float(i_perc))
      tmp_img2 = tmp_img.resize((tmp_tiny_width, i_height), p_img.ANTIALIAS)
      tmp_img2.save(ii_file)

      img_1 = cv2.imread(ii_file)
      img = cv2.cvtColor(img_1, cv2.COLOR_BGR2GRAY)
      det = cv2.CascadeClassifier(lm_model)
      faces = det.detectMultiScale(img)

      l_det1 = cv2.face.createFacemarkLBF()
      l_det = l_det1.loadModel(lm_model_2)
      ff_locations_01 = l_det.fit(img, faces)
incomplete invalid question (invalid tracker)

Most helpful comment

loadModel() does not return a new instance (returns void)

All 2 comments

loadModel() does not return a new instance (returns void)

Oh yes of course, how stupid of me,

Thanks berak

Was this page helpful?
0 / 5 - 0 ratings