kpcyrd / nude-rs

High performance nudity detection in rust
https://docs.rs/nude
GNU Lesser General Public License v3.0
132 stars 9 forks source link

Using in Python #1

Open Dentrax opened 5 years ago

Dentrax commented 5 years ago

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!

kpcyrd commented 5 years ago

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

Dentrax commented 5 years ago

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

kpcyrd commented 5 years ago

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

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()
}