mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Language selection for OCR. Fixes #107
This commit is contained in:
parent
3feeb568d8
commit
2618e0ac90
@ -9,6 +9,7 @@
|
|||||||
* SndUp users will be able to upload audio in their account by using their API Key again. ([#134](https://github.com/manuelcortez/TWBlue/issues/134))
|
* SndUp users will be able to upload audio in their account by using their API Key again. ([#134](https://github.com/manuelcortez/TWBlue/issues/134))
|
||||||
* old tweets shouldn't be added as new items in buffers. ([#116,](https://github.com/manuelcortez/TWBlue/issues/116)) ([#133](https://github.com/manuelcortez/TWBlue/issues/133))
|
* old tweets shouldn't be added as new items in buffers. ([#116,](https://github.com/manuelcortez/TWBlue/issues/116)) ([#133](https://github.com/manuelcortez/TWBlue/issues/133))
|
||||||
* All mentionned users should be displayed correctly in Twishort's long tweets. ([#116,](https://github.com/manuelcortez/TWBlue/issues/116)) ([#135](https://github.com/manuelcortez/TWBlue/issues/135))
|
* All mentionned users should be displayed correctly in Twishort's long tweets. ([#116,](https://github.com/manuelcortez/TWBlue/issues/116)) ([#135](https://github.com/manuelcortez/TWBlue/issues/135))
|
||||||
|
* It is possible to select a language for OCR service from the extras panel, in the account settings dialogue. You can, however, set this to detect automatically. OCR should work better in languages with special characters or non-english symbols. ([#107](https://github.com/manuelcortez/TWBlue/issues/107))
|
||||||
* And more ([#136,](https://github.com/manuelcortez/TWBlue/issues/136))
|
* And more ([#136,](https://github.com/manuelcortez/TWBlue/issues/136))
|
||||||
|
|
||||||
## Changes in version 0.90
|
## Changes in version 0.90
|
||||||
|
@ -1598,9 +1598,14 @@ class Controller(object):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
img = tweet["entities"]["media"][0]
|
img = tweet["entities"]["media"][0]
|
||||||
|
if buffer.session.settings["mysc"]["ocr_language"] != "":
|
||||||
|
ocr_lang = buffer.session.settings["mysc"]["ocr_language"]
|
||||||
|
else:
|
||||||
|
ocr_lang = ocr.OCRSpace.short_langs.index(tweet["lang"])
|
||||||
|
ocr_lang = ocr.OCRSpace.OcrLangs[ocr_lang]
|
||||||
api = ocr.OCRSpace.OCRSpaceAPI()
|
api = ocr.OCRSpace.OCRSpaceAPI()
|
||||||
try:
|
try:
|
||||||
text = api.OCR_URL(img["media_url"])
|
text = api.OCR_URL(img["media_url"], lang=ocr_lang)
|
||||||
except ocr.OCRSpace.APIError as er:
|
except ocr.OCRSpace.APIError as er:
|
||||||
output.speak(_(u"Unable to extract text"))
|
output.speak(_(u"Unable to extract text"))
|
||||||
return
|
return
|
||||||
|
@ -167,6 +167,8 @@ class accountSettingsController(globalSettingsController):
|
|||||||
self.dialog.set_value("sound", "indicate_img", self.config["sound"]["indicate_img"])
|
self.dialog.set_value("sound", "indicate_img", self.config["sound"]["indicate_img"])
|
||||||
self.dialog.create_extras(OCRSpace.translatable_langs)
|
self.dialog.create_extras(OCRSpace.translatable_langs)
|
||||||
self.dialog.set_value("extras", "sndup_apiKey", self.config["sound"]["sndup_api_key"])
|
self.dialog.set_value("extras", "sndup_apiKey", self.config["sound"]["sndup_api_key"])
|
||||||
|
language_index = OCRSpace.OcrLangs.index(self.config["mysc"]["ocr_language"])
|
||||||
|
self.dialog.extras.ocr_lang.SetSelection(language_index)
|
||||||
self.dialog.realize()
|
self.dialog.realize()
|
||||||
self.dialog.set_title(_(u"Account settings for %s") % (self.user,))
|
self.dialog.set_title(_(u"Account settings for %s") % (self.user,))
|
||||||
self.response = self.dialog.get_response()
|
self.response = self.dialog.get_response()
|
||||||
@ -202,7 +204,7 @@ class accountSettingsController(globalSettingsController):
|
|||||||
if set(self.config["general"]["buffer_order"]) != set(buffers_list) or buffers_list != self.config["general"]["buffer_order"]:
|
if set(self.config["general"]["buffer_order"]) != set(buffers_list) or buffers_list != self.config["general"]["buffer_order"]:
|
||||||
self.needs_restart = True
|
self.needs_restart = True
|
||||||
self.config["general"]["buffer_order"] = buffers_list
|
self.config["general"]["buffer_order"] = buffers_list
|
||||||
|
self.config["mysc"]["ocr_language"] = OCRSpace.OcrLangs[self.dialog.extras.ocr_lang.GetSelection()]
|
||||||
# if self.config["other_buffers"]["show_followers"] != self.dialog.get_value("buffers", "followers"):
|
# if self.config["other_buffers"]["show_followers"] != self.dialog.get_value("buffers", "followers"):
|
||||||
# self.config["other_buffers"]["show_followers"] = self.dialog.get_value("buffers", "followers")
|
# self.config["other_buffers"]["show_followers"] = self.dialog.get_value("buffers", "followers")
|
||||||
# pub.sendMessage("create-new-buffer", buffer="followers", account=self.user, create=self.config["other_buffers"]["show_followers"])
|
# pub.sendMessage("create-new-buffer", buffer="followers", account=self.user, create=self.config["other_buffers"]["show_followers"])
|
||||||
@ -239,7 +241,7 @@ class accountSettingsController(globalSettingsController):
|
|||||||
self.config["sound"]["indicate_audio"] = self.dialog.get_value("sound", "indicate_audio")
|
self.config["sound"]["indicate_audio"] = self.dialog.get_value("sound", "indicate_audio")
|
||||||
self.config["sound"]["indicate_geo"] = self.dialog.get_value("sound", "indicate_geo")
|
self.config["sound"]["indicate_geo"] = self.dialog.get_value("sound", "indicate_geo")
|
||||||
self.config["sound"]["indicate_img"] = self.dialog.get_value("sound", "indicate_img")
|
self.config["sound"]["indicate_img"] = self.dialog.get_value("sound", "indicate_img")
|
||||||
self.config["sound"]["sndup_api_key"] = self.dialog.get_value("extras", "apiKey")
|
self.config["sound"]["sndup_api_key"] = self.dialog.get_value("extras", "sndup_apiKey")
|
||||||
self.buffer.session.sound.config = self.config["sound"]
|
self.buffer.session.sound.config = self.config["sound"]
|
||||||
self.buffer.session.sound.check_soundpack()
|
self.buffer.session.sound.check_soundpack()
|
||||||
self.config.write()
|
self.config.write()
|
||||||
|
@ -15,12 +15,14 @@ class OCRSpaceAPI(object):
|
|||||||
self.key = key
|
self.key = key
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
def OCR_URL(self, url, overlay=False):
|
def OCR_URL(self, url, overlay=False, lang=None):
|
||||||
payload = {
|
payload = {
|
||||||
'url': url,
|
'url': url,
|
||||||
'isOverlayRequired': overlay,
|
'isOverlayRequired': overlay,
|
||||||
'apikey': self.key,
|
'apikey': self.key,
|
||||||
}
|
}
|
||||||
|
if lang != None:
|
||||||
|
payload.update(language=lang)
|
||||||
r = requests.post(self.url, data=payload)
|
r = requests.post(self.url, data=payload)
|
||||||
result = r.json()['ParsedResults'][0]
|
result = r.json()['ParsedResults'][0]
|
||||||
if result['ErrorMessage']:
|
if result['ErrorMessage']:
|
||||||
|
Loading…
Reference in New Issue
Block a user