Use custom classifier in ERFilter with python

asked 2019-12-14 12:43:13 -0500

bong0 gravatar image

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:
edit retag flag offensive close merge delete

Comments

2

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++

berak gravatar imageberak ( 2019-12-15 03:06:07 -0500 )edit