For the gear vision code, we have it set to detect how many rectangles there are (their may be three rectangles if the robot is at an angle and spring hook cuts in half one of the rectangles). We are using OpenCV for the vision processing. We have the code set to print to the console the number of rectangles with: System.out.println( gtbr.filterContoursOutput().size() ) (gtbr is the gear vision pipeline). The first time the button is pressed, it returns the number of rectangles, but each time after that it gives a value of zero. I’m not sure why this happens. Any ideas?
Here is our code that gets called in Command. First time through it prints out the correct number of contours. All subsequent calls print 0 as the size of the filterContours list.
Mat mat = new Mat();
if(cvSink.grabFrame(mat) == 0) {
System.out.println(cvSink.getError());
} else {
GearPipeline gtbr = new GearPipeline();
gtbr.process(mat);
System.out.println("size: " + gtbr.filterContoursOutput().size());
}
There’s nothing glaringly wrong in the code you shared. You are creating a new Mat and new pipeline object every time execute is called (which is very expensive, and will cause memory issues). It may be something with cscore, but I’m not familiar enough with its internals to say anything definitively.
Something you can do pretty easily is compare the center-points of the three rectangles to find which two are the closest. Or you can try and find the two rectangles with the smallest area. Then basically create a new rectangle using the top left point of the top rectangle and the bottom right point of the bottom rectangle and you will have now combined the split target together. There are probably better ways to do this but this would be a very simple way of doing it.