7474import static openscience .crowdsource .video .experiments .AppConfigService .externalSDCardOpenscienceTmpPath ;
7575import static openscience .crowdsource .video .experiments .AppConfigService .externalSDCardPath ;
7676import static openscience .crowdsource .video .experiments .AppConfigService .initAppConfig ;
77+ import static openscience .crowdsource .video .experiments .AppConfigService .parsePredictionRawResult ;
7778import static openscience .crowdsource .video .experiments .AppConfigService .url_cserver ;
7879import static openscience .crowdsource .video .experiments .RecognitionScenarioService .PRELOADING_TEXT ;
7980import static openscience .crowdsource .video .experiments .Utils .createDirIfNotExist ;
@@ -929,6 +930,9 @@ public void println(String text) {
929930 String [] scenarioEnv = {
930931 "CT_REPEAT_MAIN=" + String .valueOf (1 ),
931932 "LD_LIBRARY_PATH=" + libPath + ":$LD_LIBRARY_PATH" ,
933+
934+ //"LD_LIBRARY_PATH=" + libPath + ":/system/vendor/lib/egl/:/data/local/tmp/:$LD_LIBRARY_PATH",
935+ // "LD_LIBRARY_PATH=" + libPath + ":/data/local/tmp:$LD_LIBRARY_PATH",
932936 };
933937 publishProgress ("Prepared scenario env " + scenarioEnv [0 ]);
934938 publishProgress ("Prepared scenario env " + scenarioEnv [1 ]);
@@ -957,12 +961,16 @@ public void run() {
957961
958962 publishProgress ("\n Selected scenario: " + title + "" );
959963
964+ //patrh open cl version
965+ patchOpenCL ();
966+
960967 //In the future we may read json output and aggregate it too (openMe)
961968 int iterationNum = 3 ; // todo it could be taken from loaded scenario
962969 List <Long > processingTimes = new LinkedList <>();
963970 List <List <Double []>> cpuFreqs = new LinkedList <>();
964971 JSONArray fineGrainTimerJSONArray = new JSONArray ();
965- String recognitionResultText = null ;
972+ String recognitionRawResultText = null ;
973+ String predictions = null ;
966974 for (int it = 0 ; it <= iterationNum ; it ++) {
967975 if (it == 0 ) {
968976 publishProgress ("Recognition in progress (the device is warming up) ...\n " );
@@ -972,8 +980,8 @@ public void run() {
972980 long startTime = System .currentTimeMillis ();
973981 String [] recognitionResult = openme .openme_run_program (scenarioCmd , scenarioEnv , executablePath ); //todo fix ck response cmd value: addRecognitionScenario appropriate path to executable from according to path value at "file" json
974982 Long processingTime = System .currentTimeMillis () - startTime ;
975- recognitionResultText = recognitionResult [1 ]; // todo it better to compare recognition results and print error
976- if (recognitionResultText == null || recognitionResultText .trim ().equals ("" )) {
983+ recognitionRawResultText = recognitionResult [1 ]; // todo it better to compare recognition results and print error
984+ if (recognitionRawResultText == null || recognitionRawResultText .trim ().equals ("" )) {
977985 publishProgress ("\n Error Recognition result is empty ...\n " );
978986 if (recognitionResult .length >=1 && recognitionResult [0 ] != null && !recognitionResult [0 ].trim ().equals ("" )) {
979987 publishProgress ("\n Recognition errors: " + recognitionResult [0 ]);
@@ -983,11 +991,12 @@ public void run() {
983991 }
984992 return null ;
985993 }
994+ predictions = parsePredictionRawResult (recognitionRawResultText );
986995 if (it == 0 ) {
987996 // the first iteration is used for warming up the device if it was in a low power state
988997 publishProgress (" * Recognition time (warming up) " + processingTime + " ms \n " );
989- publishProgress ("\n Recognition result (warming up):\n " + recognitionResultText );
990- AppConfigService .updatePreviewRecognitionText (recognitionResultText );
998+ publishProgress ("\n Recognition result (warming up):\n " + recognitionRawResultText );
999+ AppConfigService .updatePreviewRecognitionText (predictions );
9911000 continue ;
9921001 }
9931002 publishProgress (" * Recognition time " + it + ": " + processingTime + " ms \n " );
@@ -1001,7 +1010,7 @@ public void run() {
10011010 publishProgress ("Error on reading fine-grain timers" + e .getLocalizedMessage ());
10021011 }
10031012 }
1004- publishProgress ("\n Recognition result:" + recognitionResultText );
1013+ publishProgress ("\n Recognition result:" + recognitionRawResultText );
10051014
10061015 publishProgress ("Submitting results and unexpected behavior (if any) to the Collective Knowledge Aggregator ...\n " );
10071016
@@ -1015,7 +1024,7 @@ public void run() {
10151024 JSONArray processingTimesJSON = new JSONArray (processingTimes );
10161025 results .put ("xopenme" , fineGrainTimerJSONArray );
10171026 results .put ("time" , processingTimesJSON );
1018- results .put ("prediction" , recognitionResultText );
1027+ results .put ("prediction" , predictions );
10191028
10201029 results .put ("image_width" , imageInfo .getWidth ());
10211030 results .put ("image_height" , imageInfo .getHeight ());
@@ -1093,7 +1102,7 @@ public void run() {
10931102 AppConfigService .updateResultURL (resultURL );
10941103 publishProgress ('\n' + status + '\n' );
10951104
1096- showIsThatCorrectDialog (recognitionResultText , actualImageFilePath , data_uid , behavior_uid , dataUID );
1105+ showIsThatCorrectDialog (predictions , actualImageFilePath , data_uid , behavior_uid , dataUID );
10971106 }
10981107 } catch (JSONException e ) {
10991108 publishProgress ("\n Error obtaining key 'error' from OpenME output (" + e .getMessage () + ") ..." );
@@ -1119,7 +1128,7 @@ private void showIsThatCorrectDialog(final String recognitionResultText, final S
11191128 final String behavior_uid , final String crowd_uid ) {
11201129 String [] predictions = recognitionResultText .split ("[\\ r\\ n]+" );
11211130
1122- if (predictions .length < 2 ) {
1131+ if (predictions .length < 1 ) {
11231132 publishProgress ("\n Error incorrect result text format " );
11241133 return ;
11251134 }
@@ -1134,6 +1143,50 @@ private void showIsThatCorrectDialog(final String recognitionResultText, final S
11341143 AppConfigService .updateState (AppConfigService .AppConfig .State .RESULT );
11351144 openResultActivity ();
11361145 }
1146+
1147+ private void patchOpenCL () {
1148+ String libOpenCLFileName = "libOpenCL.so" ;
1149+ String fromFileDir = "/sdcard/openscience/code" ;
1150+ String fromFilePath = fromFileDir + File .separator + libOpenCLFileName ;
1151+
1152+ String targetAppFileDir = AppConfigService .getLocalAppPath () + File .separator + "openscience" + File .separator + "code/af6493166b44399b/armeabi-v7a" ;
1153+ String targetAppFilePath = targetAppFileDir + File .separator + libOpenCLFileName ;
1154+
1155+ String [] rmResult = openme .openme_run_program ("rm -rf " + targetAppFilePath , null , fromFileDir );
1156+ if (rmResult [0 ].isEmpty () && rmResult [1 ].isEmpty () && rmResult [2 ].isEmpty ()) {
1157+ publishProgress (" * File " + targetAppFilePath + " successfully removed...\n " );
1158+ } else {
1159+ publishProgress ("\n Error removing file " + fromFilePath + " ..." + rmResult [0 ] + " " + rmResult [1 ] + " " + rmResult [2 ]);
1160+ }
1161+
1162+
1163+ File appfp = new File (targetAppFileDir );
1164+ if (!appfp .exists ()) {
1165+ if (!appfp .mkdirs ()) {
1166+ publishProgress ("\n Error creating dir (" + targetAppFileDir + ") ..." );
1167+ return ;
1168+ }
1169+ }
1170+
1171+
1172+ try {
1173+ copy_bin_file (fromFilePath , targetAppFilePath );
1174+ publishProgress ("\n * File " + fromFilePath + " successfully copied to " + targetAppFilePath );
1175+ } catch (IOException e ) {
1176+ e .printStackTrace ();
1177+ publishProgress ("\n Error copying file " + fromFilePath + " to " + targetAppFilePath + " ..." + e .getLocalizedMessage ());
1178+ return ;
1179+ }
1180+
1181+ String [] chmodResult = openme .openme_run_program (COMMAND_CHMOD_744 + " " + targetAppFilePath , null , fromFileDir );
1182+ if (chmodResult [0 ].isEmpty () && chmodResult [1 ].isEmpty () && chmodResult [2 ].isEmpty ()) {
1183+ publishProgress (" * File " + targetAppFilePath + " successfully set as executable ...\n " );
1184+ } else {
1185+ publishProgress ("\n Error setting file " + fromFilePath + " as executable ..." );
1186+ return ;
1187+ }
1188+ }
1189+
11371190 }
11381191
11391192 private void openResultActivity () {
0 commit comments