SethRobinson / UGT

Universal Game Translator - Uses Google's Cloud Vision to read and speak dialog from any image/game in any language
https://www.codedojo.com/?p=2426
Other
120 stars 24 forks source link

Repeated Text with DOCUMENT_TEXT_DETECTION #33

Closed Meerkov closed 3 years ago

Meerkov commented 3 years ago

The issue is around line ~570 in GameLogicComponent.

It reuses the TextArea object instead of creating a new one for each paragraph. Making this change fixes the duplicated text issue...

New code should be something like this


string myLanguage = "";
        cJSON_ArrayForEach(detectedLanguage, detectedLanguages)
        {
            const cJSON *languageCode = cJSON_GetObjectItemCaseSensitive(detectedLanguage, "languageCode");
            myLanguage = languageCode->valuestring;
            //LogMsg("Found language %s", languageCode->valuestring);
        }

        const cJSON *paragraph;
        const cJSON *paragraphs = cJSON_GetObjectItemCaseSensitive(block, "paragraphs");

        int paraCount = 0;
        cJSON_ArrayForEach(paragraph, paragraphs)
        {
            TextArea textArea;
        //  assert(paraCount == 0 && "Should only be one of these!");
            ReadFromParagraph(paragraph, textArea);
            textArea.language = myLanguage;

            if (textArea.m_rect.get_width() > 5 && textArea.m_rect.get_height() > 5)
                m_textareas.push_back(textArea);
            paraCount++;
        }
SethRobinson commented 3 years ago

Thanks, applied this fix