Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed null00001_binMask.png
Binary file not shown.
Binary file removed null00001_output.png
Binary file not shown.
Binary file removed null00001_raw.png
Binary file not shown.
8 changes: 1 addition & 7 deletions pi_scripts/installVisionProcessOnPi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@ fi
# TODO Explain-y comments

scp ${PI_USER}@${PI_ADDR} pi_scripts/vision.service ${PI_USER}@${PI_ADDR}:/tmp
ssh ${PI_USER}@${PI_ADDR} "sudo cp /tmp/vision.service /etc/systemd/system"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl stop vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl disable vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl daemon-reload"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl enable vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl start vision.service"

ssh ${PI_USER}@${PI_ADDR} "sudo cp /tmp/vision.service /etc/systemd/system && sudo systemctl stop vision.service && sudo systemctl disable vision.service && sudo systemctl daemon-reload && sudo systemctl enable vision.service && sudo systemctl start vision.service"

4 changes: 1 addition & 3 deletions pi_scripts/restartVisionProcessOnPi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ fi

# SSH to the pi and restart the vision process
echo "Restarting vision process on ${PI_USER}@${PI_ADDR}"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl stop vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl daemon-reload"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl start vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl stop vision.service && sudo systemctl daemon-reload && sudo systemctl start vision.service"
4 changes: 1 addition & 3 deletions pi_scripts/uninstallVisionProcessOnPi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ if [[ $1 != "" ]]; then
PI_ADDR=$1
fi

ssh ${PI_USER}@${PI_ADDR} "sudo systemctl stop vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl disable vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo rm /etc/systemd/system/vision.service"
ssh ${PI_USER}@${PI_ADDR} "sudo systemctl stop vision.service && sudo systemctl disable vision.service && sudo rm /etc/systemd/system/vision.service"
2 changes: 1 addition & 1 deletion pi_scripts/windows/pushCodeToPi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi
echo "Make sure you've done a \"git pull\" so that you're deploying the latest code!"
echo

./gradlew build -PbuildType=arm-raspbian -PtestType=windows
gradlew build -PbuildType=arm-raspbian -PtestType=windows

# ERROR HANDLING: check that the build succeeded
if [ $? -ne 0 ]; then
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/ca/team2706/vision/trackerboxreloaded/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import java.awt.image.BufferedImage;

import ca.team2706.vision.trackerboxreloaded.Main.VisionParams;

public class Bundle {
private BufferedImage raw,binMask,output;
private int timestamp;
private VisionParams params;

public Bundle(BufferedImage raw, BufferedImage binMask, BufferedImage output, int timestamp) {
public Bundle(BufferedImage raw, BufferedImage binMask, BufferedImage output, int timestamp, VisionParams params) {
this.raw = raw;
this.binMask = binMask;
this.output = output;
this.timestamp = timestamp;
this.params = params;
}

public BufferedImage getBinMask() {
Expand All @@ -28,4 +32,9 @@ public BufferedImage getRaw() {
public int getTimeStamp(){
return timestamp;
}

public VisionParams getParams() {
return params;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ca.team2706.vision.trackerboxreloaded;

import java.util.HashMap;
import java.util.Map;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;

public class CameraServer extends Thread {

public static Map<Integer, VideoCapture> cameras = new HashMap<Integer, VideoCapture>();

public static void startServer() {
new CameraServer().start();
}

public static void initCamera(int id) throws Exception {

if (cameras.keySet().contains(id)) {
return;
}

VideoCapture capture = new VideoCapture(id);

cameras.put(id, capture);
capture.read(frame1);
frames.put(id, frame1);

}

private static Mat frame1;
private static Map<Integer, Mat> frames = new HashMap<Integer, Mat>();

public static Mat getFrame(int camera) {

return frames.get(camera);

}

private Mat frame;

@Override
public void run() {

while (true) {

for (int i : cameras.keySet()) {

VideoCapture capture = cameras.get(i);

capture.read(frame);

frames.put(i, frame);

}

try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}

}
196 changes: 196 additions & 0 deletions src/main/java/ca/team2706/vision/trackerboxreloaded/ConfigParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package ca.team2706.vision.trackerboxreloaded;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class ConfigParser {

public static Map<String, String> getProperties(File f, String name) throws Exception {

List<String> lines = new ArrayList<String>();

Scanner in = new Scanner(f);

while (in.hasNextLine()) {
lines.add(in.nextLine());
}

in.close();

int startLine = 0, endLine = 0;

boolean foundStart = false;

for (int i = 0; i < lines.size(); i++) {

String s = lines.get(i);

if(s.equals("")) {
continue;
}

if (!foundStart) {
if (s.trim().equals(name + ":")) {
startLine = i;
foundStart = true;
}

} else {

if (!s.startsWith(" ")) {
endLine = i;
break;
}

}

}
if(endLine == 0) {
endLine = lines.size();
}

Map<String, String> properties = new HashMap<String, String>();

for (int i = startLine + 1; i < endLine; i++) {

// Get the line and remove the spaces
String s = lines.get(i).substring(2);

if (s.split("=").length >= 2) {

String key = s.split("=")[0];
String value = s.split("=")[1];

properties.put(key, value);
}

}

return properties;

}

public static List<String> listLists(File f) throws Exception {

Scanner in = new Scanner(f);
List<String> lines = new ArrayList<String>();

while (in.hasNextLine()) {
lines.add(in.nextLine());
}

in.close();

List<String> lists = new ArrayList<String>();

for (String s : lines) {

if(s.equals("")) {
continue;
}

if (!s.startsWith(" ")) {

String name = s.trim().substring(0, s.trim().length() - 1);

lists.add(name);

}

}

return lists;

}

public static void saveList(File f, String name, Map<String, String> data) throws Exception {

Scanner in = new Scanner(f);

List<String> lines = new ArrayList<String>();

while (in.hasNextLine()) {

lines.add(in.nextLine());

}

in.close();

int startLine = 0, endLine = 0;

boolean foundStart = false;

for (int i = 0; i < lines.size(); i++) {

String s = lines.get(i);

if(s.equals("")) {
continue;
}

if (!foundStart) {

if (s.equals(name + ":")) {
startLine = i;
foundStart = true;
}

} else {

if (!s.startsWith(" ")) {
endLine = i;
break;
}

}

}

if(endLine == 0) {
endLine = lines.size();
}

List<String> newLines = new ArrayList<String>();

for(int i = 0; i < lines.size(); i++) {

if(!(i >= startLine) && !(i < endLine)) {
newLines.add(lines.get(i));
}

}

//We have the fjson file minus the list we want to save

newLines.add(name+":");

for(String key : data.keySet()) {

String value = data.get(key);

newLines.add(" "+key+"="+value);
}

//Now we need to save it

f.delete();
f.createNewFile();

PrintWriter out = new PrintWriter(new FileWriter(f,true));

for(String s : newLines) {
out.println(s);
}

out.close();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ public void updateImage(BufferedImage image) {
return;
}
this.image = image;
Graphics g = this.image.createGraphics();
g.setColor(Color.WHITE);
g.drawString(Main.filename, 50, 50);
g.dispose();

// If the image width or height is more or less than the last image change the
// size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public void run() {
}

try {
Main.imgDump(b.getRaw(), "raw",b.getTimeStamp());
Main.imgDump(b.getBinMask(), "binMask", b.getTimeStamp());
Main.imgDump(b.getOutput(), "output", b.getTimeStamp());
Main.imgDump(b.getRaw(), "raw",b.getTimeStamp(),b.getParams());
Main.imgDump(b.getBinMask(), "binMask", b.getTimeStamp(),b.getParams());
Main.imgDump(b.getOutput(), "output", b.getTimeStamp(),b.getParams());
} catch (Exception e) {
//Non fatal error
}
Expand Down
Loading