Skip to content

Commit b279e5e

Browse files
committed
Adjust import settings
1 parent bdae0c2 commit b279e5e

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7+
targetgen-lib = { path = "targetgen-lib"}
78
clap = {version = "4.5.20", features = ["default"]}
9+
simple_logger = "5.0.0"
10+
log = "0.4.22"

src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
use log::LevelFilter;
2+
use simple_logger::SimpleLogger;
3+
use targetgen_lib::generator;
4+
use targetgen_lib::generator::TargetGenerator;
5+
16
fn main() {
27

8+
}
9+
10+
#[ignore]
11+
#[test]
12+
fn create_live_test() {
13+
SimpleLogger::new().with_level(LevelFilter::Debug).init().unwrap();
14+
15+
generator::util::cleanup_output("output").unwrap();
16+
17+
let mut tg = TargetGenerator::new("backgrounds", "objects", "output/annotations.json").unwrap();
18+
tg.config.permit_collisions = false;
19+
tg.config.do_random_rotation = true;
20+
tg.generate_targets(1, ..6, "output").unwrap();
21+
22+
tg.close();
323
}

targetgen-lib/src/generator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use util::STANDARD_PPM;
2020

2121
pub mod coco;
2222
pub mod error;
23-
pub(crate) mod util;
23+
pub mod util;
2424
pub mod config;
2525

2626
const COLLISION_ATTEMPTS: u32 = 15;
@@ -30,7 +30,7 @@ pub struct TargetGenerator {
3030
pub object_manager: ObjectManager,
3131
background_loader: BackgroundLoader,
3232
coco_generator: Arc<Mutex<CocoGenerator>>,
33-
pub(crate) config: TargetGeneratorConfig,
33+
pub config: TargetGeneratorConfig,
3434
resized_cache: Cache<String, DynamicImage>,
3535
}
3636

targetgen-lib/src/generator/util.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fs;
2+
use std::path::Path;
13
use crate::generator::error::GenerationError;
24
use image::metadata::Orientation;
35
use image::DynamicImage;
@@ -67,6 +69,18 @@ pub fn is_image_type(path: &str) -> bool {
6769
path.ends_with(".png") || path.ends_with(".jpg") || path.ends_with(".jpeg")
6870
}
6971

72+
pub fn cleanup_output<P: AsRef<Path>>(folder_path: P) -> std::io::Result<()> {
73+
for entry in fs::read_dir(folder_path)? {
74+
let entry = entry?;
75+
let path = entry.path();
76+
77+
if entry.file_type()?.is_file() && (is_image_type(path.to_str().unwrap()) || path.extension().unwrap() == "json") {
78+
fs::remove_file(entry.path())?;
79+
}
80+
}
81+
Ok(())
82+
}
83+
7084
#[test]
7185
fn test_is_image_type() {
7286
assert_eq!(is_image_type("test.png"), true);

targetgen-lib/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(dead_code)] // allows unused struct members
22

3-
mod backgrounds;
4-
mod objects;
5-
mod generator;
3+
pub mod backgrounds;
4+
pub mod objects;
5+
pub mod generator;

0 commit comments

Comments
 (0)