-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use InetAddress.localhost() for getting hostname, add test for mat copy
- Loading branch information
1 parent
86829a7
commit a65ffd2
Showing
2 changed files
with
93 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
core/src/test/java/edu/wpi/grip/core/operations/composite/PublishVideoOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package edu.wpi.grip.core.operations.composite; | ||
|
||
import edu.wpi.grip.util.Files; | ||
|
||
import org.bytedeco.javacpp.opencv_core; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.opencv.core.Mat; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class PublishVideoOperationTest { | ||
|
||
@BeforeClass | ||
public static void initialize() { | ||
// Make sure the OpenCV JNI is loaded | ||
blackHole(PublishVideoOperation.DESCRIPTION); | ||
} | ||
|
||
@Test | ||
public void testCopyJavaCvToOpenCvMat() { | ||
// given | ||
final Mat openCvMat = new Mat(); | ||
|
||
// then (with the GRIP logo) | ||
test(Files.imageFile.createMat(), openCvMat); | ||
|
||
// and again (with gompei) to confirm that changing the input will be cleanly copied to the | ||
// output image and cleanly overwrite any existing data | ||
test(Files.gompeiJpegFile.createMat(), openCvMat); | ||
} | ||
|
||
private static void test(opencv_core.Mat javaCvMat, Mat openCvMat) { | ||
// when | ||
PublishVideoOperation.copyJavaCvToOpenCvMat(javaCvMat, openCvMat); | ||
|
||
// then | ||
|
||
// test the basic properties (same size, type, etc.) | ||
assertEquals("Wrong width", javaCvMat.cols(), openCvMat.cols()); | ||
assertEquals("Wrong height", javaCvMat.rows(), openCvMat.rows()); | ||
assertEquals("Wrong type", javaCvMat.type(), openCvMat.type()); | ||
assertEquals("Wrong channel amount", javaCvMat.channels(), openCvMat.channels()); | ||
assertEquals("Wrong bit depth", javaCvMat.depth(), openCvMat.depth()); | ||
|
||
// test the raw data bytes - they should be identical | ||
final int width = javaCvMat.cols(); | ||
final int height = javaCvMat.rows(); | ||
final int channels = javaCvMat.channels(); | ||
|
||
final ByteBuffer buffer = javaCvMat.createBuffer(); | ||
assertThat("JavaCV byte buffer is smaller than expected!", | ||
buffer.capacity(), greaterThanOrEqualTo(width * height * channels)); | ||
|
||
final byte[] javaCvData = new byte[width * height * channels]; | ||
buffer.get(javaCvData); | ||
|
||
final byte[] openCvData = new byte[width * height * channels]; | ||
openCvMat.get(0, 0, openCvData); | ||
|
||
assertArrayEquals("Wrong data bytes", javaCvData, openCvData); | ||
} | ||
|
||
// workaround for FindBugs reporting unused variables | ||
private static void blackHole(Object ignore) { | ||
// nop | ||
} | ||
|
||
} |