mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
more tests fixes
This commit is contained in:
parent
c49b1bc6d5
commit
b0e1cb473a
@ -1,8 +1,10 @@
|
||||
package org.opencv.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
@ -426,24 +428,19 @@ public class OpenCVTestCase extends TestCase {
|
||||
}
|
||||
|
||||
protected static String readFile(String path) {
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
stream = new FileInputStream(new File(path));
|
||||
FileChannel fc = stream.getChannel();
|
||||
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
|
||||
fc.size());
|
||||
return Charset.defaultCharset().decode(bb).toString();
|
||||
BufferedReader br = new BufferedReader(new FileReader(path));
|
||||
String line;
|
||||
StringBuffer result = new StringBuffer();
|
||||
while ((line = br.readLine()) != null) {
|
||||
result.append(line);
|
||||
result.append("\n");
|
||||
}
|
||||
return result.toString();
|
||||
} catch (IOException e) {
|
||||
OpenCVTestRunner.Log("Failed to read file \"" + path
|
||||
+ "\". Exception is thrown: " + e);
|
||||
return null;
|
||||
} finally {
|
||||
if (stream != null)
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
OpenCVTestRunner.Log("Exception is thrown: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,9 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase {
|
||||
extractor.write(filename);
|
||||
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.ORB</name>\n<WTA_K>2</WTA_K>\n<edgeThreshold>31</edgeThreshold>\n<firstLevel>0</firstLevel>\n<nFeatures>500</nFeatures>\n<nLevels>8</nLevels>\n<patchSize>31</patchSize>\n<scaleFactor>1.2000000476837158e+00</scaleFactor>\n<scoreType>0</scoreType>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e\\+000", "e+00"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
@ -109,7 +111,9 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase {
|
||||
extractor.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\nname: \"Feature2D.ORB\"\nWTA_K: 2\nedgeThreshold: 31\nfirstLevel: 0\nnFeatures: 500\nnLevels: 8\npatchSize: 31\nscaleFactor: 1.2000000476837158e+00\nscoreType: 0\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e\\+000", "e+00"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,7 +87,9 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
|
||||
extractor.write(filename);
|
||||
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SIFT</name>\n<contrastThreshold>4.0000000000000001e-02</contrastThreshold>\n<edgeThreshold>10.</edgeThreshold>\n<nFeatures>0</nFeatures>\n<nOctaveLayers>3</nOctaveLayers>\n<sigma>1.6000000000000001e+00</sigma>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
@ -96,7 +98,9 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
|
||||
extractor.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\nname: \"Feature2D.SIFT\"\ncontrastThreshold: 4.0000000000000001e-02\nedgeThreshold: 10.\nnFeatures: 0\nnOctaveLayers: 3\nsigma: 1.6000000000000001e+00\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
package org.opencv.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
@ -452,24 +454,19 @@ public class OpenCVTestCase extends TestCase {
|
||||
}
|
||||
|
||||
protected static String readFile(String path) {
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
stream = new FileInputStream(new File(path));
|
||||
FileChannel fc = stream.getChannel();
|
||||
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
|
||||
fc.size());
|
||||
return Charset.defaultCharset().decode(bb).toString();
|
||||
BufferedReader br = new BufferedReader(new FileReader(path));
|
||||
String line;
|
||||
StringBuffer result = new StringBuffer();
|
||||
while ((line = br.readLine()) != null) {
|
||||
result.append(line);
|
||||
result.append("\n");
|
||||
}
|
||||
return result.toString();
|
||||
} catch (IOException e) {
|
||||
OpenCVTestRunner.Log("Failed to read file \"" + path
|
||||
+ "\". Exception is thrown: " + e);
|
||||
return null;
|
||||
} finally {
|
||||
if (stream != null)
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
OpenCVTestRunner.Log("Exception is thrown: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user