Skip to content

Commit a78a07a

Browse files
authored
Fix Blur and RGBThreshold for Python. Add RGBThreshold tests (#727)
1 parent ee22b9a commit a78a07a

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/python/operations/Blur.vm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
A numpy.ndarray that has been blurred.
1111
"""
1212
if(type is BlurType.Box_Blur):
13-
ksize = 2 * round(radius) + 1
14-
return cv2.blur(src,(ksize,ksize))
13+
ksize = int(2 * round(radius) + 1)
14+
return cv2.blur(src, (ksize, ksize))
1515
elif(type is BlurType.Gaussian_Blur):
16-
ksize = 6 * round(radius) + 1
17-
return cv2.GaussianBlur(src, (ksize,ksize), round(radius))
16+
ksize = int(6 * round(radius) + 1)
17+
return cv2.GaussianBlur(src, (ksize, ksize), round(radius))
1818
elif(type is BlurType.Median_Filter):
19-
ksize = 2 * round(radius) + 1
19+
ksize = int(2 * round(radius) + 1)
2020
return cv2.medianBlur(src, ksize)
2121
else:
22-
return cv2.bilateralFilter(src,-1,round(radius),round(radius))
22+
return cv2.bilateralFilter(src, -1, round(radius), round(radius))

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/python/operations/RGB_Threshold.vm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@staticmethod
2-
def $tMeth.name($step.name())(input, red, green, blue, out):
2+
def $tMeth.name($step.name())(input, red, green, blue):
33
"""Segment an image based on color ranges.
44
Args:
55
input: A BGR numpy.ndarray.
6-
hue: A list of two numbers the are the min and max red.
7-
sat: A list of two numbers the are the min and max green.
8-
lum: A list of two numbers the are the min and max blue.
6+
red: A list of two numbers the are the min and max red.
7+
green: A list of two numbers the are the min and max green.
8+
blue: A list of two numbers the are the min and max blue.
99
Returns:
1010
A black and white numpy.ndarray.
1111
"""

ui/src/test/java/edu/wpi/grip/ui/codegeneration/RGBThresholdTesting.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,27 @@
1111
import edu.wpi.grip.ui.codegeneration.tools.PipelineInterfacer;
1212
import edu.wpi.grip.util.Files;
1313

14+
import org.junit.Test;
1415
import org.opencv.core.Mat;
1516

16-
import java.util.ArrayList;
17+
import java.util.Arrays;
1718
import java.util.List;
1819
import java.util.Optional;
1920

2021
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertTrue;
2223

24+
@SuppressWarnings("PMD.JUnitSpelling")
2325
public class RGBThresholdTesting extends AbstractGenerationTesting {
2426

2527
boolean setup() {
2628
final Step rgb = gen.addStep(new OperationMetaData(RGBThresholdOperation.DESCRIPTION,
2729
() -> new RGBThresholdOperation(isf, osf)));
2830
loadImage(Files.gompeiJpegFile);
2931
OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0);
30-
List<Double> rVal = new ArrayList<Double>();
31-
List<Double> gVal = new ArrayList<Double>();
32-
List<Double> bVal = new ArrayList<Double>();
33-
rVal.add(new Double(46));
34-
rVal.add(new Double(188));
35-
gVal.add(new Double(0));
36-
gVal.add(new Double(110));
37-
bVal.add(new Double(0));
38-
bVal.add(new Double(110));
32+
List<Double> rVal = Arrays.asList(46d, 188d);
33+
List<Double> gVal = Arrays.asList(0d, 110d);
34+
List<Double> bVal = Arrays.asList(0d, 110d);
3935
for (InputSocket sock : rgb.getInputSockets()) {
4036
String sockHint = sock.getSocketHint().getIdentifier();
4137
if ("Input".equals(sockHint)) {
@@ -64,4 +60,10 @@ void pipelineTest(PipelineInterfacer pip) {
6460
Mat gripMat = HelperTools.bytedecoMatToCVMat((org.bytedeco.javacpp.opencv_core.Mat) out.get());
6561
assertMatWithin(genMat, gripMat, 2.0);
6662
}
63+
64+
@Test
65+
public void test() {
66+
test(this::setup, this::pipelineTest, "RGBThresholdTesting");
67+
}
68+
6769
}

0 commit comments

Comments
 (0)