kpcyrd/nude-rs

Using in Python

Opened this issue · 3 comments

Hey, @kpcyrd

Thanks for the project. Rust implementation is really really fast than Python. I wonder something. How I use this project in the Python?

Like this:

def call_nude_rs_lib(image_path):
    return nude.scan(image_path).analyse()

Thank you!

That's possible, but currently not a priority since I'm consuming the library from rust in sn0int. To use this library with python you would need to wrap it into a C FFI api, compile it to a .so and then write a python wrapper. You can find a helper library over here: https://github.com/rochacbruno/rust-python-example

@kpcyrd Is it works if i extern this function to Python?

It sort of depends how much of the api you want to access. Usually you would need:

  • the scan function which returns a scan struct
  • the analyse method that operates on the scan struct and returns an Analysis struct
  • a way to access the fields of that struct

Note that you also need an image-rs object. If you want to make it as simple as possible and you only need the true/false info you can export a function like this:

fn is_nude(path: &str) -> Result<bool> {
    let img = image::open(path);
    nude::scan(&img).is_nude()
}