Advertisement
RenabaReD

Untitled

May 18th, 2021
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. def _OCRerror(x):
  2. ''' a, b, gamma sont les curseurs du réglage du niveau '''
  3. assert len(x)==3
  4. a,b,gamma = x[0], x[1], x[2]
  5. assert ticket_ocr.dtype == np.uint8
  6. assert 0<=a<b<=255
  7.  
  8. img = ticket_ocr
  9. img[img >= a] = 255*(img[img >= a]-a)/(b-a) # niveau
  10. img[img < a] = 0
  11. img = ske.adjust_gamma(img, gamma)
  12. ocr_data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT)
  13. conf = sum([float(x) for x in ocr_data['conf']])
  14. return -conf # il faut maximiser la confiance, donc minimiser -conf
  15.  
  16. x0 = [0,255,1.0]
  17. bounds = [(0,255), (0,255), (0.01,9.99)]
  18. cons = ({'type': 'ineq',
  19. 'fun': lambda x: x[1] - x[0] - 1}) # b >= a + 1
  20. res = spopt.minimize(_OCRerror, x0, method='cobyla', bounds=bounds, constraints=cons)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement