mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Revert "Merge branch 'speckle-rejection' into 'ui-integration'"
This reverts merge request !21
This commit is contained in:
@@ -24,6 +24,7 @@ public class Main {
|
||||
|
||||
private static final int DEFAULT_PORT = 8888;
|
||||
|
||||
private static int webserverPort = DEFAULT_PORT;
|
||||
private static boolean ntServerMode = false;
|
||||
private static boolean manageNetwork = true;
|
||||
private static boolean ignoreRoot = false;
|
||||
@@ -42,7 +43,7 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Platform CurrentPlatform = Platform.getCurrentPlatform();
|
||||
public static final Platform CurrentPlatform = Platform.getCurrentPlatform();
|
||||
|
||||
private static void handleArgs(String[] args) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
@@ -126,10 +127,12 @@ public class Main {
|
||||
|
||||
// Attempt to load the JNI Libraries
|
||||
try {
|
||||
if (CurrentPlatform.equals(Platform.LINUX_ARM64))
|
||||
CameraServerJNI.forceLoad();
|
||||
CameraServerCvJNI.forceLoad();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load JNI Libraries!");
|
||||
var errorStr = CurrentPlatform.equals(Platform.UNSUPPORTED) ? "Unsupported platform!" : "Failed to load JNI Libraries!";
|
||||
throw new RuntimeException(errorStr);
|
||||
}
|
||||
|
||||
if (CameraManager.initializeCameras()) {
|
||||
@@ -149,7 +152,6 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
int webserverPort = DEFAULT_PORT;
|
||||
System.out.printf("Starting Webserver at port %d\n", webserverPort);
|
||||
Server.main(webserverPort);
|
||||
} else {
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
package com.chameleonvision.network;
|
||||
|
||||
import com.chameleonvision.settings.NetworkSettings;
|
||||
import com.chameleonvision.settings.SettingsManager;
|
||||
import com.chameleonvision.util.ShellExec;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LinuxNetworking extends SysNetworking {
|
||||
|
||||
private ShellExec shell = new ShellExec(true, true);
|
||||
|
||||
@Override
|
||||
public boolean setDHCP() {
|
||||
String[] clearArgs = { "addr", "flush", "dev", networkInterface.name };
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.chameleonvision.network;
|
||||
|
||||
import com.chameleonvision.settings.GeneralSettings;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class NetworkInterface {
|
||||
public final String name;
|
||||
public final String displayName;
|
||||
@@ -41,8 +43,9 @@ public class NetworkInterface {
|
||||
}
|
||||
// Transform the resulting value in xxx.xxx.xxx.xxx format, like if
|
||||
/// it was a standard address...
|
||||
// Return the address thus created...
|
||||
return ((shiftby >> 24) & 255) + "." + ((shiftby >> 16) & 255) + "." + ((shiftby >> 8) & 255) + "." + (shiftby & 255);
|
||||
String maskString = ((shiftby >> 24) & 255) + "." + ((shiftby >> 16) & 255) + "." + ((shiftby >> 8) & 255) + "." + (shiftby & 255);
|
||||
// Return the address thus created...
|
||||
return maskString;
|
||||
// return InetAddress.getByName(maskString);
|
||||
}
|
||||
catch(Exception e) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.chameleonvision.network;
|
||||
|
||||
|
||||
import com.chameleonvision.settings.NetworkSettings;
|
||||
import com.chameleonvision.settings.Platform;
|
||||
import com.chameleonvision.settings.SettingsManager;
|
||||
|
||||
@@ -11,7 +12,8 @@ import java.util.List;
|
||||
public class NetworkManager {
|
||||
private NetworkManager() {}
|
||||
|
||||
private static SysNetworking networking;
|
||||
protected static SysNetworking networking;
|
||||
protected static NetworkInterface botInterface = null;
|
||||
private static boolean isManaged = false;
|
||||
|
||||
public static void initialize(boolean manage) {
|
||||
@@ -62,7 +64,7 @@ public class NetworkManager {
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkInterface botInterface = goodInterfaces.get(0);
|
||||
botInterface = goodInterfaces.get(0);
|
||||
networking.setNetworkInterface(botInterface);
|
||||
} else {
|
||||
isManaged = false;
|
||||
@@ -76,10 +78,6 @@ public class NetworkManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] GetTeamNumberIPBytes(int teamNumber) {
|
||||
return new byte[]{(byte) (teamNumber / 100), (byte) (teamNumber % 100)};
|
||||
}
|
||||
|
||||
private static boolean loadFromGeneralSettings() {
|
||||
if (!isManaged) {
|
||||
return true;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.chameleonvision.util.ShellExec;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public abstract class SysNetworking {
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.chameleonvision.network;
|
||||
|
||||
import com.chameleonvision.settings.NetworkSettings;
|
||||
import com.chameleonvision.settings.SettingsManager;
|
||||
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.chameleonvision.settings;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import com.chameleonvision.util.Utilities;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
public class NetworkSettings {
|
||||
public String connectionType, ip, netmask, gateway, hostname;
|
||||
|
||||
public void run() {
|
||||
// String adapter = getAdapter();
|
||||
if (SystemUtils.IS_OS_LINUX) {//TODO check linux commands
|
||||
String adapter = getAdapter();
|
||||
if (!adapter.equals("")) {
|
||||
executeCommand("ifconfig " + adapter + " down");
|
||||
if (connectionType.equals("DHCP"))
|
||||
executeCommand("dhclient -r " + adapter);
|
||||
else if (connectionType.equals("Static")) {
|
||||
executeCommand("ifconfig " + adapter + " " + this.ip + " netmask " + this.netmask);
|
||||
executeCommand("route add default gw " + this.gateway + " " + adapter);
|
||||
}
|
||||
executeCommand("ifconfig " + adapter + " up");
|
||||
}
|
||||
executeCommand("hostnamectl set-hostname " + this.hostname);
|
||||
}
|
||||
// //TODO check windows commands
|
||||
// else if (SystemUtils.IS_OS_WINDOWS) {
|
||||
// if (!adapter.equals("")) {
|
||||
// if (connectionType.equals("DHCP")){
|
||||
// executeCommand("cmd /c interface ip set address \"" + adapter + "\" dhcp");
|
||||
// }
|
||||
// else if (connectionType.equals("Static")) {
|
||||
// executeCommand("cmd /c netsh interface ip set address \"" + adapter + "\" static " + this.ip + " " + this.netmask + " " + this.gateway + "1");
|
||||
// }
|
||||
// }
|
||||
// //TODO find a way to change hostname in windows
|
||||
// }
|
||||
}
|
||||
|
||||
private void executeCommand(String command) {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
System.out.println("Executing "+ command);
|
||||
p.waitFor();
|
||||
p.destroy();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while executing command!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetTeamNumberIPBytes(int teamNumber) {
|
||||
return new byte[]{(byte) (teamNumber / 100), (byte) (teamNumber % 100)};
|
||||
}
|
||||
|
||||
public static String getAdapter() {
|
||||
try {//TODO fix windows get adapter
|
||||
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
|
||||
for (NetworkInterface netint : Collections.list(nets)) {
|
||||
Enumeration<InetAddress> ee = netint.getInetAddresses();
|
||||
for (InetAddress addr : Collections.list(ee))
|
||||
if (addr instanceof Inet4Address) {
|
||||
var addrString = addr.toString();
|
||||
if ((addr.getAddress()[0] & 0xFF) == 10 && (addr.getAddress()[1] & 0xFF) == 168) {
|
||||
System.out.println("found robot network interface at " + netint.getName() + " ip: " + addr.getHostAddress());
|
||||
return netint.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
System.err.println("Socket exception while trying to find current IP");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,7 @@ public enum Platform {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
while (!shell.isOutputCompleted()) {
|
||||
// ignored
|
||||
}
|
||||
while (!shell.isOutputCompleted()) {}
|
||||
if (shell.getExitCode() == 0) {
|
||||
var out = shell.getOutput();
|
||||
out = out.split("\n")[0];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chameleonvision.settings;
|
||||
|
||||
import com.chameleonvision.network.NetworkManager;
|
||||
import com.chameleonvision.util.FileHelper;
|
||||
import com.chameleonvision.vision.camera.CameraManager;
|
||||
import com.google.gson.Gson;
|
||||
@@ -20,6 +21,16 @@ public class SettingsManager {
|
||||
|
||||
public static void initialize() {
|
||||
initGeneralSettings();
|
||||
// if (manageNetwork) {
|
||||
|
||||
// NetworkSettings netSettings = new NetworkSettings();
|
||||
// netSettings.hostname = GeneralSettings.hostname;
|
||||
// netSettings.gateway = GeneralSettings.gateway;
|
||||
// netSettings.netmask = GeneralSettings.netmask;
|
||||
// netSettings.connectionType = GeneralSettings.connection_type;
|
||||
// netSettings.ip = GeneralSettings.ip;
|
||||
// netSettings.run();
|
||||
// }
|
||||
var allCameras = CameraManager.getAllCamerasByName();
|
||||
if (!allCameras.containsKey(GeneralSettings.currentCamera) && allCameras.size() > 0) {
|
||||
var cam = allCameras.entrySet().stream().findFirst().get().getValue();
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ShellExec {
|
||||
* http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
private static class StreamGobbler extends Thread {
|
||||
private class StreamGobbler extends Thread {
|
||||
private InputStream is;
|
||||
private StringBuilder output;
|
||||
private volatile boolean completed; // mark volatile to guarantee a thread safety
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public static List<Integer> getDigits(int num) {
|
||||
List<Integer> digits = new ArrayList<>();
|
||||
List<Integer> digits = new ArrayList<Integer>();
|
||||
collectDigits(num, digits);
|
||||
return digits;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public class CVProcess {
|
||||
private Mat binaryMat = new Mat();
|
||||
private List<MatOfPoint> filteredContours = new ArrayList<>();
|
||||
private Comparator<RotatedRect> sortByCentermostComparator = Comparator.comparingDouble(this::calcDistance);
|
||||
private List<MatOfPoint> speckleRejectedContours = new ArrayList<>();
|
||||
private Comparator<MatOfPoint> sortByMomentsX = Comparator.comparingDouble(this::calcMomentsX);
|
||||
private List<RotatedRect> finalCountours = new ArrayList<>();
|
||||
private MatOfPoint2f intersectMatA = new MatOfPoint2f();
|
||||
@@ -87,20 +86,6 @@ public class CVProcess {
|
||||
return filteredContours;
|
||||
}
|
||||
|
||||
List<MatOfPoint> rejectSpeckles(List<MatOfPoint> inputContours, Double minimumPercentOfAverage) {
|
||||
double averageArea = 0.0;
|
||||
for(MatOfPoint c : inputContours) {
|
||||
averageArea += Imgproc.contourArea(c);
|
||||
}
|
||||
averageArea /= inputContours.size();
|
||||
var minimumAllowableArea = minimumPercentOfAverage / 100.0 * averageArea;
|
||||
speckleRejectedContours.clear();
|
||||
for(MatOfPoint c : inputContours) {
|
||||
if(Imgproc.contourArea(c) >= minimumAllowableArea) speckleRejectedContours.add(c);
|
||||
}
|
||||
return speckleRejectedContours;
|
||||
}
|
||||
|
||||
private double calcDistance(RotatedRect rect) {
|
||||
return FastMath.sqrt(FastMath.pow(cameraValues.CenterX - rect.center.x, 2) + FastMath.pow(cameraValues.CenterY - rect.center.y, 2));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.chameleonvision.vision.process;
|
||||
|
||||
import org.opencv.core.RotatedRect;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class PipelineResult {
|
||||
public boolean IsValid = false;
|
||||
public double CalibratedX = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user