-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
st1002: implementation of Range Image Local Set (#455)
This required ST 1202 transformations, which in turn required ST 1010 SDCC. Includes usual javadoc, unit tests and a generator example.
- Loading branch information
Showing
129 changed files
with
10,496 additions
and
4 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
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
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
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
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
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,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jmisb</groupId> | ||
<artifactId>examples</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>rangeimagegenerator</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Range image generator example</name> | ||
<description>Example code that generates ST 1002 range image test files.</description> | ||
<properties> | ||
<main.class>org.jmisb.examples.rangeimagegenerator.GeneratorCLI</main.class> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jmisb</groupId> | ||
<artifactId>jmisb-api-ffmpeg</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-cli</groupId> | ||
<artifactId>commons-cli</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jmisb</groupId> | ||
<artifactId>st1002</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.theoryinpractise</groupId> | ||
<artifactId>googleformatter-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
11 changes: 11 additions & 0 deletions
11
examples/rangeimagegenerator/src/main/java/module-info.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,11 @@ | ||
module org.jmisb.examples.rangeimagegenerator { | ||
requires org.jmisb.api.ffmpeg; | ||
requires org.jmisb.api; | ||
requires org.jmisb.core; | ||
requires org.jmisb.st1002; | ||
requires org.jmisb.st1010; | ||
requires org.jmisb.st1202; | ||
requires commons.cli; | ||
requires java.desktop; | ||
requires org.slf4j; | ||
} |
211 changes: 211 additions & 0 deletions
211
...s/rangeimagegenerator/src/main/java/org/jmisb/examples/rangeimagegenerator/Generator.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,211 @@ | ||
package org.jmisb.examples.rangeimagegenerator; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
import java.util.UUID; | ||
import javax.imageio.ImageIO; | ||
import org.jmisb.api.common.KlvParseException; | ||
import org.jmisb.api.klv.st1204.CoreIdentifier; | ||
import org.jmisb.api.video.CodecIdentifier; | ||
import org.jmisb.api.video.IVideoFileOutput; | ||
import org.jmisb.api.video.KlvFormat; | ||
import org.jmisb.api.video.MetadataFrame; | ||
import org.jmisb.api.video.VideoFileOutput; | ||
import org.jmisb.api.video.VideoFrame; | ||
import org.jmisb.api.video.VideoOutputOptions; | ||
import org.jmisb.core.video.TimingUtils; | ||
import org.jmisb.st1002.GeneralizedTransformation; | ||
import org.jmisb.st1002.IRangeImageMetadataValue; | ||
import org.jmisb.st1002.RangeImageCompressionMethod; | ||
import org.jmisb.st1002.RangeImageEnumerations; | ||
import org.jmisb.st1002.RangeImageLocalSet; | ||
import org.jmisb.st1002.RangeImageMetadataKey; | ||
import org.jmisb.st1002.RangeImageSource; | ||
import org.jmisb.st1002.RangeImageryDataType; | ||
import org.jmisb.st1002.ST1002PrecisionTimeStamp; | ||
import org.jmisb.st1002.ST1002VersionNumber; | ||
import org.jmisb.st1002.SinglePointRangeMeasurement; | ||
import org.jmisb.st1002.SinglePointRangeMeasurementColumn; | ||
import org.jmisb.st1002.SinglePointRangeMeasurementRow; | ||
import org.jmisb.st1010.SDCC; | ||
import org.jmisb.st1202.Denominator_X; | ||
import org.jmisb.st1202.Denominator_Y; | ||
import org.jmisb.st1202.GeneralizedTransformationLocalSet; | ||
import org.jmisb.st1202.GeneralizedTransformationParametersKey; | ||
import org.jmisb.st1202.IGeneralizedTransformationMetadataValue; | ||
import org.jmisb.st1202.SDCC_FLP; | ||
import org.jmisb.st1202.ST1202DocumentVersion; | ||
import org.jmisb.st1202.TransformationEnumeration; | ||
import org.jmisb.st1202.X_Numerator_Constant; | ||
import org.jmisb.st1202.X_Numerator_X; | ||
import org.jmisb.st1202.X_Numerator_Y; | ||
import org.jmisb.st1202.Y_Numerator_Constant; | ||
import org.jmisb.st1202.Y_Numerator_X; | ||
import org.jmisb.st1202.Y_Numerator_Y; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Generator { | ||
|
||
private static Logger LOG = LoggerFactory.getLogger(Generator.class); | ||
private final int width = 1280; | ||
private final int height = 960; | ||
private final int bitRate = 500_000; | ||
private final int gopSize = 30; | ||
private final double frameRate = 15.0; | ||
private final double frameDuration = 1.0 / frameRate; | ||
private final int duration = 60; | ||
private KlvFormat klvFormat = KlvFormat.Synchronous; | ||
private CodecIdentifier codec = CodecIdentifier.H264; | ||
private String filename = "rangeimage.ts"; | ||
|
||
public Generator() throws KlvParseException {} | ||
|
||
public void setKlvFormat(KlvFormat klvFormat) { | ||
this.klvFormat = klvFormat; | ||
} | ||
|
||
public void setCodec(CodecIdentifier codec) { | ||
this.codec = codec; | ||
} | ||
|
||
public void setOutputFile(String filename) { | ||
this.filename = filename; | ||
} | ||
|
||
public void generate() throws KlvParseException { | ||
showConfiguration(); | ||
CoreIdentifier coreIdentifier = new CoreIdentifier(); | ||
coreIdentifier.setMinorUUID(UUID.randomUUID()); | ||
coreIdentifier.setVersion(1); | ||
|
||
try (IVideoFileOutput output = | ||
new VideoFileOutput( | ||
new VideoOutputOptions( | ||
width, height, bitRate, frameRate, gopSize, klvFormat, codec))) { | ||
output.open(filename); | ||
|
||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); | ||
try { | ||
image = ImageIO.read(new File("test1280.jpg")); | ||
} catch (IOException e) { | ||
// TODO: log | ||
} | ||
|
||
final long numFrames = duration * Math.round(frameRate); | ||
long startTime = System.currentTimeMillis(); | ||
double pts = 1000.0 * System.currentTimeMillis(); // Close enough for this. | ||
for (long i = 0; i < numFrames; ++i) { | ||
output.addVideoFrame(new VideoFrame(image, pts * 1.0e-6)); | ||
SortedMap<RangeImageMetadataKey, IRangeImageMetadataValue> values = new TreeMap<>(); | ||
values.put( | ||
RangeImageMetadataKey.PrecisionTimeStamp, | ||
new ST1002PrecisionTimeStamp((long) pts)); | ||
values.put(RangeImageMetadataKey.DocumentVersion, new ST1002VersionNumber(2)); | ||
values.put( | ||
RangeImageMetadataKey.RangeImageEnumerations, | ||
new RangeImageEnumerations( | ||
RangeImageCompressionMethod.NO_COMPRESSION, | ||
RangeImageryDataType.PERSPECTIVE, | ||
RangeImageSource.RANGE_SENSOR)); | ||
values.put( | ||
RangeImageMetadataKey.SinglePointRangeMeasurement, | ||
new SinglePointRangeMeasurement(8000)); | ||
values.put( | ||
RangeImageMetadataKey.SinglePointRangeMeasurementRowCoordinate, | ||
new SinglePointRangeMeasurementRow(403)); | ||
values.put( | ||
RangeImageMetadataKey.SinglePointRangeMeasurementColumnCoordinate, | ||
new SinglePointRangeMeasurementColumn(803)); | ||
Map<GeneralizedTransformationParametersKey, IGeneralizedTransformationMetadataValue> | ||
st1202values = new TreeMap<>(); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.X_Numerator_x, new X_Numerator_X(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.X_Numerator_y, new X_Numerator_Y(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.X_Numerator_Constant, | ||
new X_Numerator_Constant(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.Y_Numerator_x, new Y_Numerator_X(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.Y_Numerator_y, new Y_Numerator_Y(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.Y_Numerator_Constant, | ||
new Y_Numerator_Constant(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.Denominator_x, new Denominator_X(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.Denominator_y, new Denominator_Y(0)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.DocumentVersion, | ||
new ST1202DocumentVersion(2)); | ||
SDCC sdcc = new SDCC(); | ||
sdcc.setValues( | ||
new double[][] { | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, | ||
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} | ||
}); | ||
st1202values.put(GeneralizedTransformationParametersKey.SDCC, new SDCC_FLP(sdcc)); | ||
st1202values.put( | ||
GeneralizedTransformationParametersKey.TransformationEnumeration, | ||
TransformationEnumeration.CHILD_PARENT); | ||
values.put( | ||
RangeImageMetadataKey.GeneralizedTransformationLocalSet, | ||
new GeneralizedTransformation( | ||
new GeneralizedTransformationLocalSet(st1202values))); | ||
RangeImageLocalSet localSet = new RangeImageLocalSet(values); | ||
output.addMetadataFrame(new MetadataFrame(localSet, pts)); | ||
pts += frameDuration * 1.0e6; | ||
long elapsedTime = System.currentTimeMillis() - startTime; | ||
long requiredElapsedTime = (long) ((i + 1) * frameDuration * 1000.0); | ||
long waitTime = requiredElapsedTime - elapsedTime; | ||
if (waitTime > 0) { | ||
TimingUtils.shortWait(waitTime); | ||
} | ||
} | ||
|
||
} catch (IOException e) { | ||
LOG.error("Failed to write file", e); | ||
} | ||
} | ||
|
||
private void showConfiguration() { | ||
System.out.println("Generating with configuration:"); | ||
System.out.println(toString()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Generator{" | ||
+ "width=" | ||
+ width | ||
+ ", height=" | ||
+ height | ||
+ ", bitRate=" | ||
+ bitRate | ||
+ ", gopSize=" | ||
+ gopSize | ||
+ ", frameRate=" | ||
+ frameRate | ||
+ ", frameDuration=" | ||
+ frameDuration | ||
+ ", duration=" | ||
+ duration | ||
+ ",\nklvFormat=" | ||
+ klvFormat | ||
+ ",\nfilename=" | ||
+ filename | ||
+ '}'; | ||
} | ||
} |
Oops, something went wrong.