parent
5aee002796
commit
855e2a7522
1 changed files with 13 additions and 9 deletions
|
@ -2,8 +2,8 @@ package com.esdtwo.objectdetection.lab3;
|
|||
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class Cli
|
|||
//Print to user while also printing to file
|
||||
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
//private static DateTimeFormatter fileDateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss");
|
||||
private static DateTimeFormatter fileDateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss");
|
||||
|
||||
//Experimentally determined values for the min and max for thresholding
|
||||
private static final double lowHue = 0;
|
||||
|
@ -144,11 +144,10 @@ public class Cli
|
|||
logger.trace(approxContour.toString());
|
||||
logger.info("Contour area: " + area);
|
||||
logger.info("Contour segments: " + approxContour.arrayHeight());
|
||||
//Only use big contours with a lot of vertices
|
||||
//Only use contours with a large amount of
|
||||
if (approxContour.arrayHeight() > 8 && area > 8000){
|
||||
logger.info("Found valid contour!");
|
||||
logger.warn("Found valid contour!");
|
||||
i++;
|
||||
//Determine centre of the object in pixels, print and save to temp storage
|
||||
Moments centroid = moments(contour);
|
||||
double cX = centroid.m10() / centroid.m00();
|
||||
double cY = centroid.m01() / centroid.m00();
|
||||
|
@ -160,7 +159,6 @@ public class Cli
|
|||
rightCentroids.add(centre);
|
||||
}
|
||||
|
||||
//Draw circle on the original image around the approximate image
|
||||
circle(readImage,centre,2,new Scalar(0,0,255,0));
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +169,13 @@ public class Cli
|
|||
|
||||
logger.info("Saving to file...");
|
||||
i = 0;
|
||||
//Save original image (with contours and centers drawn on it) to a file
|
||||
for(Mat contour : contours.get()){
|
||||
logger.trace(contour.toString());
|
||||
if (!contour.empty()){
|
||||
//saveImage(contour,file.getParent(),"final-"+i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
saveImage(readImage,file.getName(),"import-with-contours");
|
||||
} else{
|
||||
logger.error("Invalid file location!");
|
||||
|
@ -213,7 +217,7 @@ public class Cli
|
|||
//Trim out the jpg portion. We don't need that information, and it will swell our dataset.
|
||||
String trimmedLocation = location.replaceAll(".jpg","");
|
||||
//Make sure to save to the current directory, and save as PNG
|
||||
String savedFile = trimmedLocation + name + /*fileDateTime.format(LocalDateTime.now()) +*/ ".png";
|
||||
String savedFile = trimmedLocation + name + fileDateTime.format(LocalDateTime.now()) + ".png";
|
||||
//Dump image to file
|
||||
imwrite(savedFile,image);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue