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: ")
erc1.eval(1)
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)
output:
running manually:
!!!!!! did run 1
should run through detectRegions:
unlikely, that you'll get it to work. e.g. the eval() function would need to know about the ERStat object, and it's not exposed to python. also, pyjthon objects are not c++ objects, and cython does not know c++