|
@@ -8,6 +8,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.io.*;
|
|
|
+import java.nio.file.*;
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 前端控制器
|
|
@@ -39,13 +43,17 @@ public class BaseFarmController {
|
|
|
// Object res = func.invoke(Integer.class, new Object[]{lastData,curretData});
|
|
|
// System.out.println( i+"-->"+res);
|
|
|
// }
|
|
|
-
|
|
|
- for (int i = 0; i < 10000; i++) {
|
|
|
- int[] lastData = new int[]{2,0,222,-5,-6,-8,-4,-2,-7,-2,-4,-5,-5,-7,-6,-2,-4,-7,0,-5,-5,-1,0,-2,-4,-6,-4,-2,-6,-5,-6,-3,-4,-6,-7,-6,1,-5,-7,-4,-5,-7,-4,-3,-3,-6,-5,-6,-7,-1,0,-5,-6,-4,-8,-7,-6,-5,-7,-5,-4,-5,-5,-5,-6,-3,-5,-4,-6,-6,-7,-4,-6,-5,-7,-6,-7,-12,1,-8,-6,-6,-4,-6,-5,-5,-4,-4,-4,-6,-4,-8,-11,-5,-2,-6,-5,-3,-7,-4,-6,-5,-5,-6,-7,-5,0,-3,-5,-3,-6,-4,-6,-6,-7,-5,-5,-4,-6,-3,-7,-7,-5,-6,-3,-6,-9,-6,-4,-7,-4};
|
|
|
- int[] curretData = new int[]{110,22,178,3,-6,-8,-4,-5,-4,-6,-7,-7,-6,-8,-4,-7,-7,-8,-5,-12,-6,-8,-6,-5,-8,-5,-8,-8,-7,-4,-8,-169,-479,-389,-380,-336,-247,-191,-151,-137,-117,-85,-16,-5,-2,-6,-3,-4,-2,-7,-2,-4,-4,-8,-6,-3,-5,-4,-3,-3,-2,-3,-6,-3,-5,-3,-1,-4,-3,1,144,468,409,363,328,238,179,148,124,108,75,6,-7,-3,-6,-5,-3,-5,-8,-5,-7,-7,-7,-7,-1,-3,-5,-5,-9,-6,0,-12,-9,-4,-10,-6,-6,-6,-10,-132,-469,-446,-367,-334,-251,-191,-153,-133,-113,-89,-20,0,-3,-2,-6,-4,-4,-4,-3,-6,-4};
|
|
|
- int num = MyNativeClass.LibraryshowChar.LIBRARY_CHAR.current_detection(lastData, curretData);
|
|
|
+ int[] lastData = new int[]{2,0,222,-5,-6,-8,-4,-2,-7,-2,-4,-5,-5,-7,-6,-2,-4,-7,0,-5,-5,-1,0,-2,-4,-6,-4,-2,-6,-5,-6,-3,-4,-6,-7,-6,1,-5,-7,-4,-5,-7,-4,-3,-3,-6,-5,-6,-7,-1,0,-5,-6,-4,-8,-7,-6,-5,-7,-5,-4,-5,-5,-5,-6,-3,-5,-4,-6,-6,-7,-4,-6,-5,-7,-6,-7,-12,1,-8,-6,-6,-4,-6,-5,-5,-4,-4,-4,-6,-4,-8,-11,-5,-2,-6,-5,-3,-7,-4,-6,-5,-5,-6,-7,-5,0,-3,-5,-3,-6,-4,-6,-6,-7,-5,-5,-4,-6,-3,-7,-7,-5,-6,-3,-6,-9,-6,-4,-7,-4};
|
|
|
+ int[] curretData = new int[]{110,22,178,3,-6,-8,-4,-5,-4,-6,-7,-7,-6,-8,-4,-7,-7,-8,-5,-12,-6,-8,-6,-5,-8,-5,-8,-8,-7,-4,-8,-169,-479,-389,-380,-336,-247,-191,-151,-137,-117,-85,-16,-5,-2,-6,-3,-4,-2,-7,-2,-4,-4,-8,-6,-3,-5,-4,-3,-3,-2,-3,-6,-3,-5,-3,-1,-4,-3,1,144,468,409,363,328,238,179,148,124,108,75,6,-7,-3,-6,-5,-3,-5,-8,-5,-7,-7,-7,-7,-1,-3,-5,-5,-9,-6,0,-12,-9,-4,-10,-6,-6,-6,-10,-132,-469,-446,-367,-334,-251,-191,-153,-133,-113,-89,-20,0,-3,-2,-6,-4,-4,-4,-3,-6,-4};
|
|
|
+ System.out.println(lastData);
|
|
|
+ System.out.println(curretData);
|
|
|
+ for (int i = 0; i < 10000; i++) {
|
|
|
+ int num = MyNativeClass.LibraryshowChar.LIBRARY_CHAR.current_detection(lastData, curretData);
|
|
|
+// int num = MyNativeClass.LibraryshowChar.LIBRARY_CHAR.current_detection();
|
|
|
// 0没测到 1检测到
|
|
|
if (num == -1){
|
|
|
+ System.out.println(lastData);
|
|
|
+ System.out.println(curretData);
|
|
|
System.out.println( i+"-->"+num);
|
|
|
}
|
|
|
}
|
|
@@ -55,8 +63,121 @@ public class BaseFarmController {
|
|
|
@GetMapping("/test1")
|
|
|
public String add2() throws InterruptedException {
|
|
|
|
|
|
- String add = add();
|
|
|
- return add;
|
|
|
+ // 步骤1: 将两个数组写入临时文件
|
|
|
+ int[] array1 = new int[]{2,0,222,-5,-6,-8,-4,-2,-7,-2,-4,-5,-5,-7,-6,-2,-4,-7,0,-5,-5,-1,0,-2,-4,-6,-4,-2,-6,-5,-6,-3,-4,-6,-7,-6,1,-5,-7,-4,-5,-7,-4,-3,-3,-6,-5,-6,-7,-1,0,-5,-6,-4,-8,-7,-6,-5,-7,-5,-4,-5,-5,-5,-6,-3,-5,-4,-6,-6,-7,-4,-6,-5,-7,-6,-7,-12,1,-8,-6,-6,-4,-6,-5,-5,-4,-4,-4,-6,-4,-8,-11,-5,-2,-6,-5,-3,-7,-4,-6,-5,-5,-6,-7,-5,0,-3,-5,-3,-6,-4,-6,-6,-7,-5,-5,-4,-6,-3,-7,-7,-5,-6,-3,-6,-9,-6,-4,-7,-4};
|
|
|
+ int[] array2 = new int[]{110,22,178,3,-6,-8,-4,-5,-4,-6,-7,-7,-6,-8,-4,-7,-7,-8,-5,-12,-6,-8,-6,-5,-8,-5,-8,-8,-7,-4,-8,-169,-479,-389,-380,-336,-247,-191,-151,-137,-117,-85,-16,-5,-2,-6,-3,-4,-2,-7,-2,-4,-4,-8,-6,-3,-5,-4,-3,-3,-2,-3,-6,-3,-5,-3,-1,-4,-3,1,144,468,409,363,328,238,179,148,124,108,75,6,-7,-3,-6,-5,-3,-5,-8,-5,-7,-7,-7,-7,-1,-3,-5,-5,-9,-6,0,-12,-9,-4,-10,-6,-6,-6,-10,-132,-469,-446,-367,-334,-251,-191,-153,-133,-113,-89,-20,0,-3,-2,-6,-4,-4,-4,-3,-6,-4};
|
|
|
+
|
|
|
+ String tempInputFile = "temp_input.txt";
|
|
|
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempInputFile))) {
|
|
|
+ String array1String = String.join(",", Arrays.stream(array1).mapToObj(String::valueOf).toArray(String[]::new));
|
|
|
+ writer.write(array1String);
|
|
|
+ writer.newLine(); // 换行
|
|
|
+
|
|
|
+ // 写入第二个数组
|
|
|
+ String array2String = String.join(",", Arrays.stream(array2).mapToObj(String::valueOf).toArray(String[]::new));
|
|
|
+ writer.write(array2String);
|
|
|
+ writer.newLine(); // 换行
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return e.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤2: 调用C程序
|
|
|
+ String cProgramPath = "/root/svm_detection_c/predict"; // 替换为你的C程序的实际路径
|
|
|
+ String tempOutputFile = "temp_output.txt"; // 假设C程序将结果写入此文件
|
|
|
+ ProcessBuilder processBuilder = new ProcessBuilder(cProgramPath, tempInputFile, tempOutputFile);
|
|
|
+ try {
|
|
|
+ Process process = processBuilder.start();
|
|
|
+ int exitCode = process.waitFor();
|
|
|
+ if (exitCode != 0) {
|
|
|
+ System.err.println("C program execution failed with exit code: " + exitCode);
|
|
|
+ return "C program execution failed with exit code: " + exitCode;
|
|
|
+ }
|
|
|
+ } catch (IOException | InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return e.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤3: 读取结果文件
|
|
|
+ try (BufferedReader reader = new BufferedReader(new FileReader(tempOutputFile))) {
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ System.out.println(line); // 或者你可以将结果存储到某个变量或集合中
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤4: 删除所有文件
|
|
|
+// Path inputFilePath = Paths.get(tempInputFile);
|
|
|
+// Path outputFilePath = Paths.get(tempOutputFile);
|
|
|
+// try {
|
|
|
+// Files.deleteIfExists(inputFilePath);
|
|
|
+// Files.deleteIfExists(outputFilePath);
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+ return "成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/test5")
|
|
|
+ public String add5() throws InterruptedException {
|
|
|
+
|
|
|
+ // 步骤1: 将两个数组写入临时文件
|
|
|
+ int[] array2 = new int[]{2,0,222,-5,-6,-8,-4,-2,-7,-2,-4,-5,-5,-7,-6,-2,-4,-7,0,-5,-5,-1,0,-2,-4,-6,-4,-2,-6,-5,-6,-3,-4,-6,-7,-6,1,-5,-7,-4,-5,-7,-4,-3,-3,-6,-5,-6,-7,-1,0,-5,-6,-4,-8,-7,-6,-5,-7,-5,-4,-5,-5,-5,-6,-3,-5,-4,-6,-6,-7,-4,-6,-5,-7,-6,-7,-12,1,-8,-6,-6,-4,-6,-5,-5,-4,-4,-4,-6,-4,-8,-11,-5,-2,-6,-5,-3,-7,-4,-6,-5,-5,-6,-7,-5,0,-3,-5,-3,-6,-4,-6,-6,-7,-5,-5,-4,-6,-3,-7,-7,-5,-6,-3,-6,-9,-6,-4,-7,-4};
|
|
|
+ int[] array1 = new int[]{110,22,178,3,-6,-8,-4,-5,-4,-6,-7,-7,-6,-8,-4,-7,-7,-8,-5,-12,-6,-8,-6,-5,-8,-5,-8,-8,-7,-4,-8,-169,-479,-389,-380,-336,-247,-191,-151,-137,-117,-85,-16,-5,-2,-6,-3,-4,-2,-7,-2,-4,-4,-8,-6,-3,-5,-4,-3,-3,-2,-3,-6,-3,-5,-3,-1,-4,-3,1,144,468,409,363,328,238,179,148,124,108,75,6,-7,-3,-6,-5,-3,-5,-8,-5,-7,-7,-7,-7,-1,-3,-5,-5,-9,-6,0,-12,-9,-4,-10,-6,-6,-6,-10,-132,-469,-446,-367,-334,-251,-191,-153,-133,-113,-89,-20,0,-3,-2,-6,-4,-4,-4,-3,-6,-4};
|
|
|
+
|
|
|
+ String tempInputFile = "temp_input.txt";
|
|
|
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempInputFile))) {
|
|
|
+ String array1String = String.join(",", Arrays.stream(array1).mapToObj(String::valueOf).toArray(String[]::new));
|
|
|
+ writer.write(array1String);
|
|
|
+ writer.newLine(); // 换行
|
|
|
+
|
|
|
+ // 写入第二个数组
|
|
|
+ String array2String = String.join(",", Arrays.stream(array2).mapToObj(String::valueOf).toArray(String[]::new));
|
|
|
+ writer.write(array2String);
|
|
|
+ writer.newLine(); // 换行
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return e.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤2: 调用C程序
|
|
|
+ String cProgramPath = "/root/svm_detection_c/predict"; // 替换为你的C程序的实际路径
|
|
|
+ String tempOutputFile = "temp_output.txt"; // 假设C程序将结果写入此文件
|
|
|
+ ProcessBuilder processBuilder = new ProcessBuilder(cProgramPath, tempInputFile, tempOutputFile);
|
|
|
+ try {
|
|
|
+ Process process = processBuilder.start();
|
|
|
+ int exitCode = process.waitFor();
|
|
|
+ if (exitCode != 0) {
|
|
|
+ System.err.println("C program execution failed with exit code: " + exitCode);
|
|
|
+ return "C program execution failed with exit code: " + exitCode;
|
|
|
+ }
|
|
|
+ } catch (IOException | InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return e.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤3: 读取结果文件
|
|
|
+ try (BufferedReader reader = new BufferedReader(new FileReader(tempOutputFile))) {
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ System.out.println(line); // 或者你可以将结果存储到某个变量或集合中
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤4: 删除所有文件
|
|
|
+// Path inputFilePath = Paths.get(tempInputFile);
|
|
|
+// Path outputFilePath = Paths.get(tempOutputFile);
|
|
|
+// try {
|
|
|
+// Files.deleteIfExists(inputFilePath);
|
|
|
+// Files.deleteIfExists(outputFilePath);
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+ return "成功";
|
|
|
}
|
|
|
|
|
|
|