@@ -43,7 +43,8 @@ public class Pupil {
4343 public int WHITE = 255 ;
4444 /*This value might need to be alternated to allow the threshold effect to make the cresent
4545 * more prominent*/
46- public int GRAY = 240 ;
46+ public int GRAY = 240 ; //treshold value for white-dot
47+ public int LIGHTGRAY = 224 ; //threshold value for crescent
4748 public int BLACK = 0 ;
4849
4950 /*Values for contouring*/
@@ -86,7 +87,8 @@ public WhiteDot getWhiteDot() {
8687 Imgproc .cvtColor (src , gray , Imgproc .COLOR_BGR2GRAY );
8788
8889 /*This is the test image to test if the image will be converted to grayscale*/
89- //Highgui.imwrite("gray-test.jpg", gray);
90+ Highgui .imwrite ("gray-test.jpg" , gray );
91+ Highgui .imread ("gray-test.jpg" );
9092
9193 /*Applies the threshold effect on the image for white values. Takes the image in
9294 * gray and detects pixels of GRAY and turns it WHITE, and it stores it back to gray.*/
@@ -269,8 +271,48 @@ public int compare(Pair<MatOfPoint, Double> p1, Pair<MatOfPoint, Double> p2) {
269271 * @return
270272 */
271273 public double getCrescent () {
272-
273- return 0 ;
274+
275+ /* Create a new Mat to store the picture*/
276+ Mat source = new Mat ();
277+ /* copies the instance variable into source*/
278+ mat .copyTo (source );
279+ Mat gray = new Mat ();
280+
281+ /* convert the source picture into grayscale and store it into gray*/
282+ Imgproc .cvtColor (source , gray , Imgproc .COLOR_BGR2GRAY );
283+
284+ /* those values above 240, will turned to white, the remaining values to black*/
285+ Imgproc .threshold (gray , gray , GRAY , WHITE , Imgproc .THRESH_BINARY );
286+
287+ /* an arraylist of points used to store the contours found in the image */
288+ List <MatOfPoint > contours = new ArrayList <MatOfPoint >();
289+
290+ Imgproc .findContours (gray .clone (), contours , new Mat (), Imgproc .RETR_LIST , Imgproc .CHAIN_APPROX_SIMPLE );
291+ Imgproc .drawContours (gray , contours , fillCONTOURS , new Scalar (WHITE , WHITE , WHITE ), contourTHICKNESS );
292+
293+ if (contours .isEmpty ()) {
294+ log .error ("No crescent found" );
295+ return 0.0 ;
296+ }
297+
298+ double maxArea = 0.0 ;
299+
300+ /* loop through the contour arrayList and for each contour calculate its area */
301+ for (int i = 0 ; i < contours .size (); i ++) {
302+
303+ maxArea = Imgproc .contourArea (contours .get (i ));
304+
305+ if (maxArea )
306+
307+
308+
309+ }
310+
311+
312+
313+
314+
315+ return 0.0 ;
274316 }
275317
276318 /**
0 commit comments