@ Action ( name = "Extract text from image" , description = EXTRACT_TEXT_FROM_IMAGE_DESC , outputs = { @ Output ( value = RETURN_CODE , description = RETURN_CODE_DESC ) , @ Output ( value = RETURN_RESULT , description = RETURN_RESULT_DESC ) , @ Output ( value = TEXT_STRING , description = TEXT_STRING_DESC ) , @ Output ( value = TEXT_JSON , description = TEXT_JSON_DESC ) , @ Output ( value = EXCEPTION , description = EXCEPTION_DESC ) , } , responses = { @ Response ( text = SUCCESS , field = RETURN_CODE , value = ReturnCodes . SUCCESS , matchType = COMPARE_EQUAL , responseType = RESOLVED , description = SUCCESS_DESC ) , @ Response ( text = FAILURE , field = RETURN_CODE , value = ReturnCodes . FAILURE , matchType = COMPARE_EQUAL , responseType = ERROR , isOnFail = true , description = FAILURE_DESC ) } ) public Map < String , String > execute ( @ Param ( value = FILE_PATH , required = true , description = FILE_PATH_DESC ) String filePath , @ Param ( value = DATA_PATH , required = true , description = DATA_PATH_DESC ) String dataPath , @ Param ( value = LANGUAGE , required = true , description = LANGUAGE_DESC ) String language , @ Param ( value = TEXT_BLOCKS , description = TEXT_BLOCKS_DESC ) String textBlocks , @ Param ( value = DESKEW , description = DESKEW_DESC ) String deskew ) { dataPath = defaultIfEmpty ( dataPath , EMPTY ) ; language = defaultIfEmpty ( language , ENG ) ; textBlocks = defaultIfEmpty ( textBlocks , FALSE ) ; deskew = defaultIfEmpty ( deskew , FALSE ) ; final List < String > exceptionMessages = verifyExtractTextInputs ( filePath , dataPath , textBlocks , deskew ) ; if ( ! exceptionMessages . isEmpty ( ) ) { return getFailureResultsMap ( StringUtilities . join ( exceptionMessages , NEW_LINE ) ) ; } try { final String resultText = extractTextFromImage ( filePath , dataPath , language , textBlocks , deskew ) ; final Map < String , String > result = getSuccessResultsMap ( resultText ) ; if ( Boolean . parseBoolean ( textBlocks ) ) { result . put ( TEXT_JSON , resultText ) ; } else { result . put ( TEXT_STRING , resultText ) ; } return result ; } catch ( Exception e ) { return getFailureResultsMap ( e ) ; } }
This operation extracts the text from a specified file given as input using Tesseract s OCR library .