Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waikato-datamining/opex4j
Java library for the OPEX JSON format.
https://github.com/waikato-datamining/opex4j
java json object-detection
Last synced: 5 days ago
JSON representation
Java library for the OPEX JSON format.
- Host: GitHub
- URL: https://github.com/waikato-datamining/opex4j
- Owner: waikato-datamining
- License: mit
- Created: 2023-02-27T19:51:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-18T22:32:44.000Z (5 months ago)
- Last Synced: 2024-06-20T03:40:56.286Z (5 months ago)
- Topics: java, json, object-detection
- Language: Java
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# opex4j
Java library for the [OPEX JSON format](https://github.com/WaikatoLink2020/objdet-predictions-exchange-format)
(faster Python alternative: [fast-opex](https://github.com/waikato-datamining/fast-opex)).## JSON
Here is an [example](src/test/resources/opex4j/simple.json):
```json
{
"timestamp": "...",
"id": "str",
"objects": [
{
"score": 1.0,
"label": "person",
"bbox": {
"top": 100,
"left": 100,
"bottom": 150,
"right": 120
},
"polygon": {
"points": [
[100, 100],
[150, 100],
[150, 120],
[100, 120]
]
}
},
{
"score": 0.95,
"label": "house",
"bbox": {
"top": 100,
"left": 100,
"bottom": 200,
"right": 200
},
"polygon": {
"points": [
[100, 100],
[200, 100],
[200, 200],
[100, 200]
]
},
"meta": {
"price": "500k"
}
}
],
"meta": {
"key1": "value1",
"key2": "value2"
}
}
```**Notes:**
* supported timestamp formats: `yyyyMMdd_HHmmss.SSSSSS` and `yyyy-MM-dd HH:mm:ss.SSSSSS`
## Reading/Writing
To read predictions:
```java
import opex4j.ObjectPredictions;
import java.io.InputStream;
import java.io.File;
import java.io.Reader;public class Examples {
public static void main(String[] args) throws Exception {
// from string
ObjectPredictions preds = ObjectPredictions.newInstance("{...}");// from file
ObjectPredictions preds = ObjectPredictions.newInstance(new File("predictions.json"));// from reader
Reader reader = ...;
ObjectPredictions preds = ObjectPredictions.newInstance(reader);
reader.close();
// from stream
InputStream stream = ...;
ObjectPredictions preds = ObjectPredictions.newInstance(stream);
stream.close();
}
}
```To write predictions:
```java
import opex4j.ObjectPredictions;
import java.io.File;
import java.io.OutputStream;
import java.io.Writer;public class Examples {
public static void main(String[] args) throws Exception {
ObjectPredictions preds = ...;// to string (not pretty printed)
String s = preds.toString(false);// to file (pretty printed, implicitly)
ObjectPredictions.write(new File("predictions.json"));// to writer (pretty printed, explicitly)
Writer writer = ...;
ObjectPredictions.write(writer, true);
writer.close();
// to stream (not pretty printed)
OutputStream stream = ...;
preds.write(stream, false);
stream.close();
}
}
```## Maven
Use the following dependency in your `pom.xml`:
```xml
nz.ac.waikato.cms.adams
opex4j
0.0.3
```