Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _OCRerror(x):
- ''' a, b, gamma sont les curseurs du réglage du niveau '''
- assert len(x)==3
- a,b,gamma = x[0], x[1], x[2]
- assert ticket_ocr.dtype == np.uint8
- assert 0<=a<b<=255
- img = ticket_ocr
- img[img >= a] = 255*(img[img >= a]-a)/(b-a) # niveau
- img[img < a] = 0
- img = ske.adjust_gamma(img, gamma)
- ocr_data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT)
- conf = sum([float(x) for x in ocr_data['conf']])
- return -conf # il faut maximiser la confiance, donc minimiser -conf
- x0 = [0,255,1.0]
- bounds = [(0,255), (0,255), (0.01,9.99)]
- cons = ({'type': 'ineq',
- 'fun': lambda x: x[1] - x[0] - 1}) # b >= a + 1
- res = spopt.minimize(_OCRerror, x0, method='cobyla', bounds=bounds, constraints=cons)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement