Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Use custom classifier in ERFilter with python

I want to use a custom classifier and use the python opencv API (3.x) for ERFilter.

I wonder why the eval method is not called, from what I found in the sources, this is the method that classifies the regions and I need to implement.

I appreciate any help, it seems a very uncommon situation since I cannot find examples for this...

Thank you all!

Below is a minimum example (also hosted here)

import cv2
import numpy as np
import ctypes
# needs opencv-contrib

class customClassifier(cv2.text_ERFilter_Callback):
    def eval(self, stat) -> ctypes.c_double:
        print("!!!!!! did run", stat)
        return 0.0

erc1 = customClassifier()
print("running manually: ")
er1 = cv2.text.createERFilterNM1(erc1,16,0.00015,0.13,0.2,True,0.1)

#erc2 = cv2.text.loadClassifierNM2('/Users/bongo/Downloads/trained_classifierNM2.xml')
#er2 = cv2.text.createERFilterNM2(erc2,0.5)
print("should run through detectRegions:")
img = np.zeros((10,10,3), dtype=np.uint8)
regions = cv2.text.detectRegions(img,er1,None)


running manually: 
!!!!!! did run 1
should run through detectRegions: