notAI-tech / NudeNet

Lightweight nudity detection
https://nudenet.notai.tech/
GNU Affero General Public License v3.0
1.66k stars 335 forks source link

How to draw boxes? #122

Closed burgerlawful closed 8 months ago

burgerlawful commented 9 months ago

I've been playing around with this locally in Python but I can't figure out how to use draw boxes over the image with the values returned from detections. I tried to use some code from the censor function in the v2 branch, but the boxes end up with the wrong dimensions. I'm not sure if it returns the wrong box values or if I am just doing something wrong.

kalvinmc commented 9 months ago

Yeah the box values seem to be off for me aswell.

I dug around through the code and found that the box returned is [x, y, width, height]. But if I transform this to top upper right lower coordinated as (box[0], box[1], box[0] + box[2], box[1] + box[3]) for cropping, the x0 coordinate in combination with the width seems to always be off. Either it starts too to the right on the left breast and doesn't cover it all on the left side or too to the left on the right breast and doesn't cover it all on the right side. Actually, I ended up noticing the y height combination is off aswell.

This used to work perfectly with v2 but in v2 I didn't have to change the box coordinates at all. I could just pass it to crop as they were. It seems the box values changed between v2 and v3

The web version does it perfectly for the same image. The thing I noticed is that the web version shows me a smaller image and mine are large images.

bedapudi6788 commented 9 months ago

In the pre processing of the image, padding etc is done, thus changing the dimensions of the original input image.

For drawing boxes, these new dimensions have to be mapped back.

I will add a censor() function with these changes in a few days.

bedapudi6788 commented 8 months ago

The boxes logic is fixed by @pa4y in https://github.com/notAI-tech/NudeNet/pull/128

bedapudi6788 commented 8 months ago

https://github.com/notAI-tech/NudeNet/blob/a6004400aadffdcbe10f4fc463adb94a53ee7197/nudenet/nudenet.py#L132

censor function is now added. refer to readme for example.