added group contours method and target intersection

This commit is contained in:
ori agranat
2019-09-16 21:45:04 +03:00
parent adc5aa2399
commit e7e0632b2b
3 changed files with 101 additions and 36 deletions

View File

@@ -53,6 +53,7 @@ public class CameraProcess implements Runnable {
List<MatOfPoint> FoundContours = new ArrayList<>();
List<MatOfPoint> FilteredContours = new ArrayList<>();
List<RotatedRect> GroupedContours = new ArrayList<>();
Mat inputMat = new Mat();
Mat bgrMat = new Mat();
Mat hsvThreshMat = new Mat();
@@ -68,36 +69,40 @@ public class CameraProcess implements Runnable {
FilteredContours.clear();
currentPipeline = SettingsManager.Cameras.get(CameraName).pipelines.get(SettingsManager.CamerasCurrentPipeline.get(CameraName));
cv_sink.grabFrame(inputMat);
if (inputMat.cols() !=0 && inputMat.rows() != 0) {
Imgproc.cvtColor(inputMat, bgrMat, Imgproc.COLOR_RGB2BGR, 3);
if (inputMat.cols() == 0 && inputMat.rows() == 0) { continue; }
// Imgproc.cvtColor(inputMat, bgrMat, Imgproc.COLOR_RGB2BGR, 3);
Scalar hsvLower = new Scalar(currentPipeline.hue.get(0), currentPipeline.saturation.get(0), currentPipeline.value.get(0));
Scalar hsvUpper = new Scalar(currentPipeline.hue.get(1), currentPipeline.saturation.get(1), currentPipeline.value.get(1));
Scalar hsvLower = new Scalar(currentPipeline.hue.get(0), currentPipeline.saturation.get(0), currentPipeline.value.get(0));
Scalar hsvUpper = new Scalar(currentPipeline.hue.get(1), currentPipeline.saturation.get(1), currentPipeline.value.get(1));
visionProcess.HSVThreshold(inputMat, hsvThreshMat, hsvLower, hsvUpper, currentPipeline.erode, currentPipeline.dilate);
FoundContours = visionProcess.FindContours(hsvThreshMat);
FilteredContours = visionProcess.FilterContours(FoundContours, currentPipeline.area, currentPipeline.ratio, currentPipeline.extent, currentPipeline.sort_mode, currentPipeline.target_intersection, currentPipeline.target_group);
visionProcess.HSVThreshold(inputMat, hsvThreshMat, hsvLower, hsvUpper, currentPipeline.erode, currentPipeline.dilate);
FoundContours = visionProcess.FindContours(hsvThreshMat);
FilteredContours = visionProcess.FilterContours(FoundContours, currentPipeline.area, currentPipeline.ratio, currentPipeline.extent, currentPipeline.sort_mode, currentPipeline.target_intersection, currentPipeline.target_group);
GroupedContours = visionProcess.GroupTargets(FilteredContours,currentPipeline.target_intersection,currentPipeline.target_group);
if (currentPipeline.is_binary == 1) {
Imgproc.cvtColor(hsvThreshMat, hsvThreshMat, Imgproc.COLOR_GRAY2BGR, 3);
outputMat = hsvThreshMat;
} else {
outputMat = inputMat;
}
if (FilteredContours.size() > 0) {
for (int i = 0; i < FilteredContours.size(); i++) {
Imgproc.drawContours(outputMat, FilteredContours, i, contourColor, 10);
}
}
cv_publish.putFrame(outputMat);
inputMat.release();
hsvThreshMat.release();
for (MatOfPoint oldMat : FoundContours) { oldMat.release(); }
for (MatOfPoint oldMat1 : FilteredContours) { oldMat1.release(); }
if (currentPipeline.is_binary == 1) {
Imgproc.cvtColor(hsvThreshMat, hsvThreshMat, Imgproc.COLOR_GRAY2BGR, 3);
outputMat = hsvThreshMat;
} else {
outputMat = inputMat;
}
if (GroupedContours.size() > 0) {
List<MatOfPoint> a = new ArrayList<>();
Point[] vertices = new Point[4];
GroupedContours.get(0).points(vertices);
a.add(new MatOfPoint(vertices));
Imgproc.drawContours(outputMat,a, 0, contourColor, 3);
}
cv_publish.putFrame(outputMat);
inputMat.release();
hsvThreshMat.release();
for (MatOfPoint oldMat : FoundContours) { oldMat.release(); }
for (MatOfPoint oldMat1 : FilteredContours) { oldMat1.release(); }
memManager.run();
endTime = System.nanoTime();
}