Skip to content

Commit 02b2b69

Browse files
author
Rahul
committed
Merge pull request #6 from rsshah/master
moved the test file to the appropriate location
2 parents fc40c2b + 24e5a47 commit 02b2b69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+71
-41686
lines changed

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/Controller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.ucsd.globalties.dvs.core.excel.ExcelDataGenerator;
1414

1515
/**
16-
* A cannibalized MVC artifact that hides access of the logic (e.g. the Patient class)
16+
* An MVC-esque artifact that hides access of the logic (e.g. the Patient class)
1717
* from the front-end. Maybe you can improve this (specifically the front-end exclusive
1818
* pieces) but for now you may add to this if necessary, because this class should not have
1919
* much more functionality unless the front-end requires it.

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/Eye.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,32 @@ private Pupil findPupil() {
104104
Core.circle(fsrc, new Point(finalPupil[0], finalPupil[1]), (int) finalPupil[2], new Scalar(255,0,0),2);
105105
Highgui.imwrite("detected-pupil.jpg", fsrc);*/
106106

107-
log.info("Pupil found: x: " + finalPupil[0] + " y: " + finalPupil[1] + " r: " + finalPupil[2]);
107+
log.info("Pupil found: x: {} y: {} r: {}", finalPupil[0], finalPupil[1], finalPupil[2]);
108108
//Crop eye mat and create pupil mat
109109
Point topLeft = new Point(finalPupil[0]-finalPupil[2],finalPupil[1]-finalPupil[2]);
110110
Point bottomRight = new Point(finalPupil[0]+finalPupil[2],finalPupil[1]+finalPupil[2]);
111111
//check if top left point is negative and thus outside of image bounds and should be adjusted to be a valid point
112112
//TODO do we even want these adjusted rects to be returned as pupils?
113113
if (topLeft.x < 0 || topLeft.y < 0) {
114-
log.warn("Top left point is out of image bounds (" + topLeft.x + "," + topLeft.y + ").");
114+
log.warn("Top left point is out of image bounds ({},{}).", topLeft.x, topLeft.y);
115115
if (topLeft.x < 0) {
116116
topLeft.x = 0;
117117
}
118118
if (topLeft.y < 0) {
119119
topLeft.y = 0;
120120
}
121-
log.warn("Continuing with (" + topLeft.x + "," + topLeft.y + ").");
121+
log.warn("Continuing with ({},{}).", topLeft.x, topLeft.y);
122122
}
123123
//check if bottom right point is larger than img size and thus should be adjusted
124124
if (bottomRight.x > src.size().width || bottomRight.y > src.size().height) {
125-
log.warn("Bottom right point is out of image bounds (" + bottomRight.x + "," + bottomRight.y + ").");
125+
log.warn("Bottom right point is out of image bounds ({},{}).", bottomRight.x, bottomRight.y);
126126
if (bottomRight.x > src.size().width) {
127127
bottomRight.x = src.size().width;
128128
}
129129
if (bottomRight.y > src.size().height) {
130130
bottomRight.y = src.size().height;
131131
}
132-
log.warn("Continuing with (" + bottomRight.x + "," + bottomRight.y + ").");
132+
log.warn("Continuing with ({},{})", bottomRight.x, bottomRight.y);
133133
}
134134
Rect pupilArea = new Rect(topLeft, bottomRight);
135135
Mat pupilMat = new Mat(src, pupilArea);

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/EyeDisease.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* An enum to represent all of the diseases that this program detects.
1414
* Register a DiseaseDetector that implements an algorithm to detect
15-
* the disease in the construct of the EyeDisease enum object.
15+
* the disease in the constructor of the EyeDisease enum object.
1616
* @author Rahul
1717
*
1818
*/

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/Main.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ public class Main extends Application {
2727
// OpenCV constants for face/eye detection
2828
private static final String HAAR_FACE = "/haarcascade_frontalface_alt.xml";
2929
private static final String HAAR_EYE = "/haarcascade_eye.xml";
30-
31-
//Mostly front end constants.
32-
//TODO move to constants class or something
33-
public static final String[] sceneLabels = {"Name","Date of Birth","Gender","Ethnicity","Language","Room Number","School","Screening Comment"};
30+
31+
// Mostly front end constants.
32+
// TODO move to constants class or something
33+
public static final String[] sceneLabels = { "Name", "Date of Birth", "Gender", "Ethnicity", "Language",
34+
"Room Number", "School", "Screening Comment" };
3435
public static final String inputScreenID = "inputGrid";
3536
public static final String inputScreenFile = "/views/input_grid.fxml";
3637
public static final String photoGridID = "photoGrid";
@@ -39,74 +40,69 @@ public class Main extends Application {
3940
public static final String detectGridFile = "/views/detect_grid.fxml";
4041
public static final String resultGridID = "resultGrid";
4142
public static final String resultGridFile = "/views/result_grid.fxml";
42-
43-
//The paths of the face/eye detection resource fields
43+
44+
// The paths of the face/eye detection resource fields
4445
public static String HAAR_FACE_PATH;
4546
public static String HAAR_EYE_PATH;
46-
47+
4748
private static int BUFFER_SIZE = Short.MAX_VALUE;
4849
private static Controller controller;
4950
public static final String OUTPUT_FILE = "output/";
50-
51-
51+
5252
public static void main(String[] args) {
5353
(new File("output")).mkdir(); // create temporary output folder
5454
controller = new Controller();
5555
loadLibraryComponents();
5656
launch(args);
5757
}
58-
58+
5959
/**
6060
* Load the OpenCV resources used for face and eye detection.
6161
*/
6262
public static void loadLibraryComponents() {
6363
// load OpenCV constants
64-
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
64+
// System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
6565
loadOpencvLibrary();
66-
//Workaround for "/" thing, load as file then get filepath
66+
// Workaround for "/" thing, load as file then get filepath
6767
File fp = new File(Main.class.getResource(HAAR_FACE).getFile());
6868
File ep = new File(Main.class.getResource(HAAR_EYE).getFile());
6969
HAAR_FACE_PATH = fp.getAbsolutePath();
7070
HAAR_EYE_PATH = ep.getAbsolutePath();
7171
}
72-
72+
7373
/**
74-
* Load the OpenCV native library appropriate for this operating system.
75-
* The library file is stored in the running directory.
74+
* Load the OpenCV native library appropriate for this operating system. The
75+
* library file is stored in the running directory.
7676
*/
7777
private static void loadOpencvLibrary() {
7878
try {
7979
InputStream in = null;
8080
File fileOut = null;
8181
String osName = System.getProperty("os.name");
8282
log.info(osName);
83-
if(osName.startsWith("Windows")){
83+
if (osName.startsWith("Windows")) {
8484
int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model"));
85-
if(bitness == 32){
85+
if (bitness == 32) {
8686
log.info("32 bit detected");
8787
in = Main.class.getResourceAsStream("/opencv/opencv_java249_x86.dll");
88-
fileOut = File.createTempFile("lib", ".dll");
89-
}
90-
else if (bitness == 64){
88+
} else if (bitness == 64) {
9189
log.info("64 bit detected");
9290
in = Main.class.getResourceAsStream("/opencv/opencv_java249_x64.dll");
93-
fileOut = File.createTempFile("lib", ".dll");
94-
}
95-
else{
91+
} else {
9692
log.info("Unknown bit detected - trying with 32 bit");
9793
in = Main.class.getResourceAsStream("/opencv/opencv_java249_x86.dll");
98-
fileOut = File.createTempFile("lib", ".dll");
94+
9995
}
100-
}
101-
else if(osName.equals("Mac OS X")){
96+
fileOut = File.createTempFile("lib", ".dll");
97+
} else if (osName.equals("Mac OS X")) {
10298
log.info("Mac os detected");
10399
in = Main.class.getResourceAsStream("/opencv/libopencv_java249.dylib");
104100
fileOut = File.createTempFile("lib", ".dylib");
105101
}
106102

107103
OutputStream out = new BufferedOutputStream(new FileOutputStream(fileOut), BUFFER_SIZE);
108104
int b = 0;
109-
105+
110106
while ((b = in.read()) >= 0) {
111107
out.write(b);
112108
}
@@ -123,8 +119,8 @@ else if(osName.equals("Mac OS X")){
123119
* Launch the JavaFX UI
124120
*/
125121
@Override
126-
public void start(Stage stage) throws Exception {
127-
122+
public void start(Stage stage) throws Exception {
123+
128124
try {
129125
stage.setTitle("Digital Vision Screening");
130126
FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/main.fxml"));

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/Photo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private Rect findFaceRoi(Mat image) {
7272
// find faces and put the results inside of the faceDetections object.
7373
faceDetector.detectMultiScale(image, faceDetections, 1.05, 2, flag, new Size(30,30), new Size(image.width(),image.height()));
7474

75-
log.info(String.format("Detected %s faces for img: %s", faceDetections.toArray().length, path));
75+
log.info("Detected {} faces for img: {}", faceDetections.toArray().length, path);
7676
Rect detectedFace;
7777
if (faceDetections == null || faceDetections.toArray().length == 0) {
7878
// go straight into eye detection on current image if no face is found
@@ -98,7 +98,7 @@ public Pair<Eye, Eye> findEyes() {
9898
eyeDetector.detectMultiScale(faceImage, eyeDetections);
9999

100100
List<Rect> detectedEyes = eyeDetections.toList();
101-
log.info(String.format("Detected %s eyes for img: %s", detectedEyes.size(), path));
101+
log.info("Detected {} eyes for img: {}", detectedEyes.size(), path);
102102
List<Rect> eyes = new ArrayList<>(2);
103103
if (detectedEyes.size() < 2) {
104104
log.error("Minimum two eyes required.");

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/Pupil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public WhiteDot getWhiteDot() {
8787
// Find the closest contour that matches certain criteria (currently checks for size)
8888
for (Pair<MatOfPoint, Double> pair : contourDistances) {
8989
double area = Imgproc.contourArea(pair.getLeft());
90-
log.info("whiteDot distance: " + pair.getRight() + ", area: " + area);
90+
log.info("whiteDot distance: {}, area: {}", pair.getRight(), area);
9191

9292
if (area < 10 || area > 200.0) { // basic bounds checking, may need some tuning
9393
continue;
@@ -116,10 +116,10 @@ public WhiteDot getWhiteDot() {
116116
log.error("[WhiteDot Detection] unfulfilled invariant: adjacent edge of triangle is bigger than hypotenuse");
117117
return null;
118118
}
119-
log.info("[WhiteDot Detection] Computing angle for xDist: " + xDist + ", dist: " + distance);
119+
log.info("[WhiteDot Detection] Computing angle for xDist: {}, dist: {}", xDist, distance);
120120
double angle = Math.acos(xDist / distance);
121121

122-
log.info("[WhiteDot Detection] computed white dot with distance: " + distance + ", angle: " + Math.toDegrees(angle) + ", area: " + wdarea);
122+
log.info("[WhiteDot Detection] computed white dot with distance: {}, angle: {}, area: {}", distance, Math.toDegrees(angle), wdarea);
123123
this.whiteDot = new WhiteDot(distance, wdarea, angle);
124124
return whiteDot;
125125
}

dvs-core/src/main/resources/opencv/opencv_java249_x84.dll renamed to dvs-core/src/main/resources/opencv/opencv_java249_x86.dll

File renamed without changes.

dvs-core/src/main/java/com/ucsd/globalties/dvs/core/PupilDetectionTest.java renamed to dvs-core/src/test/java/com/ucsd/globalties/dvs/core/PupilDetectionTestIT.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313
import com.ucsd.globalties.dvs.core.Photo.PhotoType;
1414
import com.ucsd.globalties.dvs.core.tools.Pair;
15+
import org.junit.*;
1516

1617
/**
17-
* A very simplistic test class.
18-
* This should be in the test package, I might move it later.
19-
* It is not in the test package because there were issues linking
20-
* Maven build procedures to a native library (because OpenCV is necessary
21-
* for this test to run), but with the addition of the runtime native library
22-
* loading function, this can be moved safely.
23-
* TODO move to test package
18+
* An integration test for pupil detection.
19+
* This class runs pupil detection (and thus face and eye detection) on a list of manually
20+
* managed images. It currently asserts nothing, but when accuracy of pupil detection is
21+
* improved (and better/more pictures are taken), it can serve as a real integration test.
22+
* Maven does not, by default, compile integration tests. You may run this class individually,
23+
* or use the maven integration-test phase to run this class (with some settings, I think).
2424
* @author Rahul
2525
*
2626
*/
2727
@Slf4j
28-
public class PupilDetectionTest {
28+
public class PupilDetectionTestIT {
2929
private static final List<Pair<String, String>> TEST_PAIRS = Arrays.asList(
3030
new Pair<String, String>("Andrei_1.jpg", "Andrei_2.jpg"),
3131
new Pair<String, String>("Sabit_1.jpg", "Sabit_2.jpg"),
@@ -44,31 +44,28 @@ public class PupilDetectionTest {
4444
private static long timeTaken = 0;
4545

4646
private static final ExecutorService threadpool = Executors.newFixedThreadPool(TEST_PAIRS.size() / 2);
47-
48-
public static void main(String[] args) {
47+
48+
@Before
49+
public void setupAndClean() {
4950
Main.loadLibraryComponents();
50-
clean();
51-
run();
52-
}
53-
54-
public static void clean() {
5551
for (Iterator<Pair<String, String>> it = TEST_PAIRS.iterator(); it.hasNext();) {
5652
Pair<String, String> picPair = it.next();
57-
File fst = new File(PupilDetectionTest.class.getResource("/pics/" + picPair.getLeft()).getFile());
53+
File fst = new File(PupilDetectionTestIT.class.getResource("/pics/" + picPair.getLeft()).getFile());
5854
if (!fst.exists()) {
5955
log.warn("pic file: " + fst.getAbsolutePath() + " does not exist");
6056
it.remove();
6157
continue;
6258
}
63-
File snd = new File(PupilDetectionTest.class.getResource("/pics/" + picPair.getRight()).getFile());
59+
File snd = new File(PupilDetectionTestIT.class.getResource("/pics/" + picPair.getRight()).getFile());
6460
if (!fst.exists()) {
6561
log.warn("pic file: " + snd.getAbsolutePath() + " does not exist");
6662
it.remove();
6763
}
6864
}
6965
}
7066

71-
public static void run() {
67+
@Test
68+
public void run() {
7269
long s = System.currentTimeMillis();
7370
for (int i = 0; i < TEST_PAIRS.size(); i++) {
7471
final int index = i;
@@ -78,8 +75,8 @@ public void run() {
7875
int found = 0;
7976
try {
8077
Patient p = Patient.builder().name("Test" + index).build();
81-
File l = new File(PupilDetectionTest.class.getResource("/pics/" + test.getLeft()).getFile());
82-
File r = new File(PupilDetectionTest.class.getResource("/pics/" + test.getRight()).getFile());
78+
File l = new File(PupilDetectionTestIT.class.getResource("/pics/" + test.getLeft()).getFile());
79+
File r = new File(PupilDetectionTestIT.class.getResource("/pics/" + test.getRight()).getFile());
8380
Photo pL = new Photo(l.getAbsolutePath(), p, PhotoType.VERTICAL);
8481
Photo pR = new Photo(r.getAbsolutePath(), p, PhotoType.HORIZONTAL);
8582
if (pL.getLeftEye().getPupil() != null) {
@@ -93,35 +90,39 @@ public void run() {
9390
}
9491
if (pR.getRightEye().getPupil() != null) {
9592
found++;
96-
}
97-
results[index] = found;
93+
}
9894
} catch (Exception ex) {
99-
results[index] = found;
10095
log.error(String.format("Exception raised for pair %s, %s", test.getLeft(), test.getRight(), ex));
101-
}
102-
if (counter.incrementAndGet() == TEST_PAIRS.size()) {
103-
timeTaken = s;
104-
printResults();
96+
} finally {
97+
results[index] = found;
98+
counter.incrementAndGet();
10599
}
106100
}
107101
};
108102
threadpool.execute(r);
109103
}
104+
// this is kind of lame, the real way to do this is a CountdownLatch but cba
105+
while (counter.get() < TEST_PAIRS.size()) {
106+
try {
107+
Thread.sleep(100);
108+
} catch (Exception e) {}
109+
}
110+
timeTaken = s;
111+
printResults();
110112
}
111113

112-
public static void printResults() {
114+
public void printResults() {
113115
log.info("Time taken (s): " + (System.currentTimeMillis() - timeTaken) / 1000);
114116
int total = 0;
115117
for (int i = 0; i < results.length; i++) {
116118
total += results[i];
117119
Pair<String, String> pair = TEST_PAIRS.get(i);
118-
log.info(String.format("Pupil test for pair %s, %s found %d/4 pupils", pair.getLeft(), pair.getRight(), results[i]));
120+
log.info("Pupil test for pair {}, {} found {}/4 pupils", pair.getLeft(), pair.getRight(), results[i]);
119121
}
120122
log.info("Test complete. Double check all results by looking at the images.");
121-
log.info(String.format("Found: %d/%d", total, TEST_PAIRS.size() * 4));
123+
log.info("Found: {}/{}", total, TEST_PAIRS.size() * 4);
122124
if (total != TEST_PAIRS.size() * 4) {
123-
log.error("Expected: " + (TEST_PAIRS.size() * 4) + " images, found: " + total);
125+
log.error("Expected: {} images, found: {}", TEST_PAIRS.size() * 4, total);
124126
}
125-
System.exit(0);
126127
}
127128
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Placeholder file so that the parent resources folder is created. Otherwise, everyone who clones this repository will need to manually create a test/resources folder themselves, because Git does not write empty folders.

0 commit comments

Comments
 (0)