User talk:Panamitsu/Archives/ 1

Latest comment: 1 month ago by Cwmhiraeth in topic DYK for Trumpet (ice cream)


DYK for Jenny Suo

On 7 February 2024, Did you know was updated with a fact from the article Jenny Suo, which you recently created, substantially expanded, or brought to good article status. The fact was ... that at the age of 14, Jenny Suo conducted a science experiment that ultimately led to GlaxoSmithKline pleading guilty to breaching consumer protection laws? The nomination discussion and review may be seen at Template:Did you know nominations/Jenny Suo. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Jenny Suo), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

Ganesha811 (talk) 02:09, 7 February 2024 (UTC)

Revisions

I, at the instruction of a company, am trying to update the article which references their own website. I have reinstated the published copy but I would like to understand why you have reverted our changes despite the reference URL is for the company of the same name (as the article)? ResonantCloud (talk) 06:23, 8 February 2024 (UTC)

Because your additions are copy pasted from the Toll Group's website. That is a copyright violation. —Panamitsu (talk) 06:55, 8 February 2024 (UTC)
Even though it's Toll putting these changes through? ResonantCloud (talk) 07:26, 8 February 2024 (UTC)
Thanks for getting back to me btw. If it's a case of rewording what is on the website, I can arrange that. ResonantCloud (talk) 07:28, 8 February 2024 (UTC)

DYK nomination of Supie

  Hello! Your submission of Supie at the Did You Know nominations page has been reviewed, and some issues with it may need to be clarified. Please review the comment(s) at your nomination's entry and respond there at your earliest convenience. Thank you for contributing to Did You Know! PCN02WPS (talk | contribs) 07:42, 14 February 2024 (UTC)

Did you know ...

... that I very much enjoyed seeing your frequent DYK contributions last year?

It's a shame that it's slowed down to a trickle this year. It would be fabulous if you could reach your previous enthusiasm! Schwede66 16:47, 14 February 2024 (UTC)

Haha thanks. I've been wanting to get back into it, but I've been so busy for the past few months. —Panamitsu (talk) 20:53, 14 February 2024 (UTC)

Re:Python-based face detection

Do you happen to have a colab or some browser-based UI for the solution you outlined in the reference desk? I am not that knowledgeable with Python but I did dabble with the likes of those voice deepfake solutions which used a offline web server as a front end. Blake Gripling (talk) 07:00, 9 February 2024 (UTC)

@Blakegripling ph I'm not aware of any existing program that can do this but it sounds like a fun little project, so I might make it myself. —Panamitsu (talk) 08:11, 9 February 2024 (UTC)
Aight, I am looking forward to it. Blake Gripling (talk) 09:11, 9 February 2024 (UTC)
Blake Gripling I've quickly thrown something together and it works quite well. The problem is that it has false positives and often does not recognise faces of babies. Here is an example:
File:Automatic face bluring test1 - Coloured-family.pngPanamitsu (talk) 03:00, 10 February 2024 (UTC)
I filtered the results based on the age model's confidences and it's a bit better but to get it perfect manual editing would be needed. I haven't yet decided if I'm going to make a GUI to manually add/remove blurs. —Panamitsu (talk) 03:08, 10 February 2024 (UTC)
Is it possible to feather the blur so the circles don't look as harsh though? Blake Gripling (talk) 04:07, 10 February 2024 (UTC)

@Blakegripling ph: Yeah that's possible. I'm too busy to add it myself. Here is the source code if you want to try adding it. It's a bit of a mess but oh well. I also don't respond to emails.

# Copyright Panamitsu (2024) CC BY 4.0

import numpy
import requests
import os.path
import face_recognition
from PIL import Image, ImageDraw, ImageFilter
import cv2


FILE = "test/family2.jpg"
MIN_AGE = 18
BLUR_AMOUNT = 20


# Model taken from paper by Gil Levi and Tal Hassner (2015): https://talhassner.github.io/home/publication/2015_CVPR
MODEL_URL = "https://drive.usercontent.google.com/u/0/uc?id=1kiusFljZc9QfcIYdU2s7xrtWHTraHwmW&export=download"
PROTOTXT_URL = "https://drive.usercontent.google.com/u/0/uc?id=1kWv0AjxGSN0g31OeJa02eBGM0R_jcjIl&export=download"

MODEL_PATH = "model/age.caffemodel"
PROTOTXT_PATH = "model/deploy.prototxt"

AGE_BRACKETS = [(0,2), (4,6), (8,12), (15,20), (25,32), (38,43), (48,53), (60,100)]


def download_files() -> None:
    # Download caffe model
    if not os.path.isfile(MODEL_PATH):
        print("Downloading model...")
        r = requests.get(MODEL_URL)
        open(MODEL_PATH , 'wb').write(r.content)

    # Download prototxt
    if not os.path.isfile(PROTOTXT_PATH):
        print("Downloading prototxt...")
        r = requests.get(PROTOTXT_URL)
        open(PROTOTXT_PATH , 'wb').write(r.content)


def too_young(bracket: tuple[int, int]) -> bool:
    """ Returns whether the person is too young and needs to be blurred"""
    return min(bracket) <= MIN_AGE


def calc_age(im: numpy.ndarray, age_model: cv2.dnn_Net) -> tuple[tuple[int, int], float]:
    blob = cv2.dnn.blobFromImage(im, 1.0, (227, 227), (78.4263377603, 87.7689143744, 114.895847746), swapRB=False)
    age_model.setInput(blob)
    preds = age_model.forward()
    i = preds[0].argmax()
    confidence = preds[0][i]
   
    return AGE_BRACKETS[i], confidence
   

def main():
    # Load in model
    download_files() # Download model if it doesn't already exist
    age_model = cv2.dnn.readNet(PROTOTXT_PATH, MODEL_PATH)

    # Find all faces in image

    im = Image.open(FILE).convert("RGB")

    face_locations = face_recognition.face_locations(face_recognition.load_image_file(FILE))

    # Get blurred image
    blurred = im.filter(ImageFilter.GaussianBlur(radius=BLUR_AMOUNT))

    mask = Image.new("RGBA", im.size, color="white")
    mask_draw = ImageDraw.Draw(mask)
    
    # Detect age for each face
    for face_location in face_locations:
        top, right, bottom, left = face_location

        # Estimate age
        face = cv2.cvtColor(numpy.array(im), cv2.COLOR_RGB2BGR)[top:bottom, left:right] # Crop and convert to cv2 image because I am lazy
        age_bracket, confidence = calc_age(face, age_model)

        # Draw mask if person is too young
        if too_young(age_bracket) and confidence > 0.5: # Only blur if high age confidence
            mask_draw.ellipse([(left, top),(right, bottom)], fill=(0, 0, 0, 0))


    final = Image.composite(im, blurred, mask)
    final.show()


if __name__ == "__main__":
    main()

Panamitsu (talk) 04:30, 10 February 2024 (UTC)

It's impressive you can achieve so much with only a couple of screens of code. I realise the imports are doing much of the hard work, but having such a diverse library of routines available is amazing.-gadfium 04:42, 10 February 2024 (UTC)
That's why Python is amazing! It's all plug and play. —Panamitsu (talk) 04:47, 10 February 2024 (UTC)
Noice one mate! Is it possible to make it so that it can be used with multiple images in a folder? Blake Gripling (talk) 05:40, 10 February 2024 (UTC)
Yep. I've just made the blur less harsh and I've made a GUI that allows you to remove incorrectly placed blurs, and I'll soon add the ability to manually add blurs. —Panamitsu (talk) 10:55, 11 February 2024 (UTC)
Will you release it somewhere soon? Blake Gripling (talk) 02:04, 12 February 2024 (UTC)
Yes. I've now got everything working. You can now manually add/remove blurs with a GUI, and it iterates over an input directory. It is currently a big mess of 200 lines so I'm going to spend some time cleaning it up later tonight. —Panamitsu (talk) 04:55, 12 February 2024 (UTC)
Alright, I'll look forward to it. Blake Gripling (talk) 06:22, 12 February 2024 (UTC)

Blakegripling ph Here you go. Questionable programming practices on my end.

First thing you're going to do once downloading this file is creating an "input" and "output" directory in the same folder that you place the Python file in.

Next thing you're going to need to do is install the packages. Run these commands (note that it may be slightly different depending on your Python installation):

  • pip install opencv-python
  • pip install face-recognition
  • pip install numpy
  • pip install pillow

Next, place this into a Python file and run it in the same directory.

# Copyright Panamitsu (2024) CC BY 4.0

import cv2
import face_recognition
import numpy
import os.path
from PIL import Image, ImageDraw, ImageFilter, ImageTk
import requests
import tkinter as tk
import tkinter.messagebox

MIN_AGE = 18
BLUR_AMOUNT = 8

INPUT_DIR  = "input"
OUTPUT_DIR = "output"

MIN_CONFIDENCE = 0.5

# Model taken from paper by Gil Levi and Tal Hassner (2015): https://talhassner.github.io/home/publication/2015_CVPR
MODEL_URL = "https://drive.usercontent.google.com/u/0/uc?id=1kiusFljZc9QfcIYdU2s7xrtWHTraHwmW&export=download"
PROTOTXT_URL = "https://drive.usercontent.google.com/u/0/uc?id=1kWv0AjxGSN0g31OeJa02eBGM0R_jcjIl&export=download"

MODEL_PATH = "model/age.caffemodel"
PROTOTXT_PATH = "model/deploy.prototxt"

AGE_BRACKETS = [(0,2), (4,6), (8,12), (15,20), (25,32), (38,43), (48,53), (60,100)]

# First position for when blurs are manually placed.
new_blur_x = None
new_blur_y = None

def on_blur_click(event):
    """
    Deletes blur region when mouse is clicked on it.
    This is only called when an object with the 'blur_spot' tag is clicked on.
    """
    
    # Delete the blur object under the mouse pointer 
    c.delete("current")


def on_right_click(event):
    """
    Creates a region to be blurred.
    The first right-click declares the start position, and the second right-click finished the saves the blur region.
    """

    global new_blur_x, new_blur_y

    if new_blur_x is None and new_blur_y is None:
        # First right click. Next one will create the blur spot
        new_blur_x = event.x
        new_blur_y = event.y
    else:
        # Second right click. Create the blur spot.
        add_blur(new_blur_x, new_blur_y, event.x, event.y)
        new_blur_x = None
        new_blur_y = None


def download_files() -> None:
    # Download caffe model
    if not os.path.isfile(MODEL_PATH):
        print("Downloading model...")
        r = requests.get(MODEL_URL)
        open(MODEL_PATH , 'wb').write(r.content)

    # Download prototxt
    if not os.path.isfile(PROTOTXT_PATH):
        print("Downloading prototxt...")
        r = requests.get(PROTOTXT_URL)
        open(PROTOTXT_PATH , 'wb').write(r.content)


def too_young(bracket: tuple[int, int]) -> bool:
    """ Returns whether the person is too young and needs to be blurred """
    return min(bracket) <= MIN_AGE


def calc_age(im: numpy.ndarray, age_model: cv2.dnn_Net) -> tuple[tuple[int, int], float]:
    """ Calculates age of given face """
    blob = cv2.dnn.blobFromImage(im, 1.0, (227, 227), (78.4263377603, 87.7689143744, 114.895847746), swapRB=False)
    age_model.setInput(blob)
    preds = age_model.forward()
    i = preds[0].argmax()
    confidence = preds[0][i]
    
    return AGE_BRACKETS[i], confidence


def add_blur(x1, y1, x2, y2):
    """ Adds a rectangle to the canvas to signal that the saved image will be blurred in this region. """
    c.create_rectangle(x1, y1, x2, y2, outline="red", fill="orange", dash=5, width=3, tags="blur_spot")


def show_instructions():
    tkinter.messagebox.showinfo("Instructions", """* Put all raw images in 'input' directory
* Faces which are detected to be too young will have blur regions placed over them. The program may incorrectly blur, or not blur a face. To fix this, a blur must be manually added/removed.
* To add a blur, right click on the start point and right click on the end point.
* To remove a blur, left click on an orange square.
* To save an image, click the 'Save image' button and it will be saved into the 'output' directory. The next image will now be displayed.""")


def init_gui():
    global root, c
    
    # Set up frames to put GUI in
    root = tk.Tk()
    root.title("Face blur")
    frame_canvas  = tk.Frame(root)
    frame_buttons = tk.Frame(root)
    frame_canvas.pack()
    frame_buttons.pack()

    # Set up buttons
    save_button = tk.Button(frame_buttons, text="Save image", command=save_image)
    save_button.pack()
    instructions_button = tk.Button(frame_buttons, text="Show instructions", command=show_instructions)
    instructions_button.pack()
    
    # Set up canvas
    c = tk.Canvas(frame_canvas, width=0, height=0) # Wait until we have loaded the image to set dimensions
    c.tag_bind("blur_spot", "<Button-1>", on_blur_click)
    c.bind("<Button-3>", on_right_click)
    c.pack()


def init():
    global age_model, iter_files

    # Get list of input image files
    iter_files = iter(os.listdir(INPUT_DIR))

    init_gui()

    # Load in model
    download_files() # Download model if it doesn't already exist
    age_model = cv2.dnn.readNet(PROTOTXT_PATH, MODEL_PATH)


def save_image():
    # Get blurred image
    blurred = im.filter(ImageFilter.GaussianBlur(radius=BLUR_AMOUNT))

    mask = Image.new("RGBA", im.size, color="white")

    # Blur each face
    for i in c.find_withtag("blur_spot"):
        mask_draw = ImageDraw.Draw(mask)
        mask_draw.ellipse(c.coords(i), fill=(0, 0, 0, 0))

    final = Image.composite(im, blurred, mask)
    final.save(f"{OUTPUT_DIR}/{file}")

    # Move on to next image file
    next_file()


def next_file():
    global file, im

    # Load the new image
    file = next(iter_files)
    im = Image.open(f"{INPUT_DIR}/{file}")

    # Clear canvas from previous image
    c.delete("all")
    
    # Set canvas size to new image size
    c.config(width=im.size[0], height=im.size[1])

    # Place image onto the canvas.
    im_tkinter = ImageTk.PhotoImage(im)
    root.im_tkinter = im_tkinter # Prevent garbage collector from deleting image...
    c.create_image((0, 0), anchor="nw", image=im_tkinter)

    # Find all faces in image
    face_locations = face_recognition.face_locations(face_recognition.load_image_file(f"{INPUT_DIR}/{file}"))

    # Detect age for each face
    for face_location in face_locations:
        y1, x2, y2, x1 = face_location

        # Estimate age
        face = cv2.cvtColor(numpy.array(im), cv2.COLOR_RGB2BGR)[y1:y2, x1:x2] # Crop and convert to cv2 image because I am lazy
        age_bracket, confidence = calc_age(face, age_model)

        # If person is too young, blur it
        if too_young(age_bracket) and confidence > MIN_CONFIDENCE: # Only blur if high age confidence
            add_blur(x1, y1, x2, y2)


def main():
    # Set up first image
    next_file()

    root.mainloop()


if __name__ == "__main__":
    init()
    main()

There's an instructions button on the bottom, but if you have trouble with getting this working or using it, please let me know. Try manually adding/removing blurs and save the image to make sure you understand it all. —Panamitsu (talk) 10:50, 12 February 2024 (UTC)

What if I want to run it silently i.e. it goes through all images then spits them out en masse silently sans intervention? Can this tool do it? Blake Gripling (talk) 10:54, 12 February 2024 (UTC)
Well you could but I would not recommend it given the amount of faces it does not recognise/gets age wrong. —Panamitsu (talk) 11:50, 12 February 2024 (UTC)
I am getting the following errors:
Downloading model...
Traceback (most recent call last):
File "C:\Users\Samantha\Desktop\ageblur\ageblur.py", line 202, in <module>
init()
File "C:\Users\Samantha\Desktop\ageblur\ageblur.py", line 138, in init
download_files() # Download model if it doesn't already exist
^^^^^^^^^^^^^^^^
File "C:\Users\Samantha\Desktop\ageblur\ageblur.py", line 67, in download_files
open(MODEL_PATH , 'wb').write(r.content)
^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'model/age.caffemodel'
All the required dependencies are satisfied tho. Blake Gripling (talk) 13:29, 12 February 2024 (UTC)
Oh yes I forgot to say, you also need to create a "model" folder. —Panamitsu (talk) 20:57, 12 February 2024 (UTC)
Now it's giving me this error:
Downloading model...
Downloading prototxt...
[libprotobuf ERROR D:\a\opencv-python\opencv-python\opencv\3rdparty\protobuf\src\google\protobuf\text_format.cc:335] Error parsing text-format opencv_caffe.NetParameter: 1:1: Expected identifier, got: <
Traceback (most recent call last):
File "C:\Users\Samantha\Desktop\ageblur\ageblur.py", line 202, in <module>
init()
File "C:\Users\Samantha\Desktop\ageblur\ageblur.py", line 139, in init
age_model = cv2.dnn.readNet(PROTOTXT_PATH, MODEL_PATH)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\caffe\caffe_io.cpp:1162: error: (-2:Unspecified error) FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse NetParameter file: model/deploy.prototxt in function 'cv::dnn::ReadNetParamsFromTextFileOrDie' Blake Gripling (talk) 00:26, 13 February 2024 (UTC)
nvm that, turns out Google Drive spazzed out so I had to DL the model files manually. Blake Gripling (talk) 00:30, 13 February 2024 (UTC)
Also, is it possible for the image in question to be scaled to the window, e.g. for high resolution images? Blake Gripling (talk) 00:37, 13 February 2024 (UTC)
Yes that's possible but that'll require some tweaking. —Panamitsu (talk) 01:53, 13 February 2024 (UTC)
Yea since some of the images tend to span beyond what the desktop can display lel Blake Gripling (talk) 01:59, 13 February 2024 (UTC)
Any idea on whether you'll work on scaling the window to fit the screen? Blake Gripling (talk) 01:02, 15 February 2024 (UTC)
Sorry I didn't realise that you were wanting that. I'll let you know once I get it done. —Panamitsu (talk) 01:03, 15 February 2024 (UTC)
Alright, take your time. Blake Gripling (talk) 02:19, 15 February 2024 (UTC)

@Blakegripling ph: Sorry it's been so long. I've been rather busy. Here I've got the resizing done. If you want to change the height, change the MAX_IM_HEIGHT value. It is currently set to 500 pixels. I've also made the blur editor display an oval instead of a rectangle so it better represents the rendered image.

# Copyright Panamitsu (2024) CC BY 4.0

import cv2
import face_recognition
import numpy
import os.path
from PIL import Image, ImageDraw, ImageFilter, ImageTk
import requests
import tkinter as tk
import tkinter.messagebox

MIN_AGE = 18
BLUR_AMOUNT = 8

INPUT_DIR  = "input"
OUTPUT_DIR = "output"

MIN_CONFIDENCE = 0.5

MAX_IM_HEIGHT = 500

# Model taken from paper by Gil Levi and Tal Hassner (2015): https://talhassner.github.io/home/publication/2015_CVPR
MODEL_URL = "https://drive.usercontent.google.com/u/0/uc?id=1kiusFljZc9QfcIYdU2s7xrtWHTraHwmW&export=download"
PROTOTXT_URL = "https://drive.usercontent.google.com/u/0/uc?id=1kWv0AjxGSN0g31OeJa02eBGM0R_jcjIl&export=download"

MODEL_PATH = "model/age.caffemodel"
PROTOTXT_PATH = "model/deploy.prototxt"

AGE_BRACKETS = [(0,2), (4,6), (8,12), (15,20), (25,32), (38,43), (48,53), (60,100)]

# First position for when blurs are manually placed.
new_blur_x = None
new_blur_y = None

def on_blur_click(event):
    """
    Deletes blur region when mouse is clicked on it.
    This is only called when an object with the 'blur_spot' tag is clicked on.
    """
    
    # Delete the blur object under the mouse pointer 
    c.delete("current")


def on_right_click(event):
    """
    Creates a region to be blurred.
    The first right-click declares the start position, and the second right-click finished the saves the blur region.
    """

    global new_blur_x, new_blur_y

    if new_blur_x is None and new_blur_y is None:
        # First right click. Next one will create the blur spot
        new_blur_x = event.x
        new_blur_y = event.y
    else:
        # Second right click. Create the blur spot.
        add_blur(new_blur_x, new_blur_y, event.x, event.y)
        new_blur_x = None
        new_blur_y = None


def download_files() -> None:
    # Download caffe model
    if not os.path.isfile(MODEL_PATH):
        print("Downloading model...")
        r = requests.get(MODEL_URL)
        open(MODEL_PATH , 'wb').write(r.content)

    # Download prototxt
    if not os.path.isfile(PROTOTXT_PATH):
        print("Downloading prototxt...")
        r = requests.get(PROTOTXT_URL)
        open(PROTOTXT_PATH , 'wb').write(r.content)


def too_young(bracket: tuple[int, int]) -> bool:
    """ Returns whether the person is too young and needs to be blurred """
    return min(bracket) <= MIN_AGE


def calc_age(im: numpy.ndarray, age_model: cv2.dnn_Net) -> tuple[tuple[int, int], float]:
    """ Calculates age of given face """
    blob = cv2.dnn.blobFromImage(im, 1.0, (227, 227), (78.4263377603, 87.7689143744, 114.895847746), swapRB=False)
    age_model.setInput(blob)
    preds = age_model.forward()
    i = preds[0].argmax()
    confidence = preds[0][i]
    
    return AGE_BRACKETS[i], confidence


def add_blur(x1, y1, x2, y2):
    """ Adds a rectangle to the canvas to signal that the saved image will be blurred in this region. """

    c.create_oval(x1, y1, x2, y2, outline="red", fill="orange", dash=5, width=3, tags="blur_spot")


def show_instructions():
    tkinter.messagebox.showinfo("Instructions", """* Put all raw images in 'input' directory
* Faces which are detected to be too young will have blur regions placed over them. The program may incorrectly blur, or not blur a face. To fix this, a blur must be manually added/removed.
* To add a blur, right click on the start point and right click on the end point.
* To remove a blur, left click on an orange square.
* To save an image, click the 'Save image' button and it will be saved into the 'output' directory. The next image will now be displayed.
* To resize the dimensions of the editor, edit the MAX_IM_HEIGHT value in the Python file.""")


def init_gui():
    global root, c
    
    # Set up frames to put GUI in
    root = tk.Tk()
    root.title("Face blur")
    frame_canvas  = tk.Frame(root)
    frame_buttons = tk.Frame(root)
    frame_canvas.pack()
    frame_buttons.pack()

    # Set up buttons
    save_button = tk.Button(frame_buttons, text="Save image", command=save_image)
    save_button.pack()
    instructions_button = tk.Button(frame_buttons, text="Show instructions", command=show_instructions)
    instructions_button.pack()
    
    # Set up canvas
    c = tk.Canvas(frame_canvas, width=0, height=0) # Wait until we have loaded the image to set dimensions
    c.tag_bind("blur_spot", "<Button-1>", on_blur_click)
    c.bind("<Button-3>", on_right_click)
    c.pack()


def init():
    global age_model, iter_files

    # Get list of input image files
    iter_files = iter(os.listdir(INPUT_DIR))

    init_gui()

    # Load in model
    download_files() # Download model if it doesn't already exist
    age_model = cv2.dnn.readNet(PROTOTXT_PATH, MODEL_PATH)


def save_image():
    # Get blurred image
    blurred = im.filter(ImageFilter.GaussianBlur(radius=BLUR_AMOUNT))

    mask = Image.new("RGBA", im.size, color="white")

    # Blur each face
    for i in c.find_withtag("blur_spot"):
        mask_draw = ImageDraw.Draw(mask)
        # Because the canvas image was resized, the canvas and output images have different sizes.
        # This means the rectangles do not have the correct coordinates for the output images. They have to be scaled again.
        blur_coords = tuple(i / resize_amount for i in c.coords(i)) 
        mask_draw.ellipse(blur_coords, fill=(0, 0, 0, 0))

    final = Image.composite(im, blurred, mask)
    final.save(f"{OUTPUT_DIR}/{file}")

    # Move on to next image file
    next_file()


def next_file():
    global file, im, resize_amount

    # Load the new image
    file = next(iter_files)
    im = Image.open(f"{INPUT_DIR}/{file}")

    # Clear canvas from previous image
    c.delete("all")

    # Resize image for canvas
    resize_amount = MAX_IM_HEIGHT / im.size[1]
    new_size = ((int(im.size[0] * resize_amount)), int(im.size[1] * resize_amount))
    im_tkinter = im.resize(new_size)
    
    # Set canvas size to new image size
    c.config(width=im_tkinter.size[0], height=im_tkinter.size[1])

    # Place image onto the canvas.
    im_tkinter = ImageTk.PhotoImage(im_tkinter)
    root.im_tkinter = im_tkinter # Prevent garbage collector from deleting image...
    c.create_image((0, 0), anchor="nw", image=im_tkinter)

    # Find all faces in image
    face_locations = face_recognition.face_locations(face_recognition.load_image_file(f"{INPUT_DIR}/{file}"))

    # Detect age for each face
    for face_location in face_locations:
        y1, x2, y2, x1 = face_location

        # Estimate age
        face = cv2.cvtColor(numpy.array(im), cv2.COLOR_RGB2BGR)[y1:y2, x1:x2] # Crop and convert to cv2 image because I am lazy
        age_bracket, confidence = calc_age(face, age_model)

        # If person is too young, blur it
        if too_young(age_bracket) and confidence > MIN_CONFIDENCE: # Only blur if high age confidence
            # Because the canvas image was resized, the canvas and output images have different sizes.
            # This means the rectangles do not have the correct coordinates for the output images. They have to be scaled again.
            x1 *= resize_amount
            y1 *= resize_amount
            x2 *= resize_amount
            y2 *= resize_amount
            add_blur(x1, y1, x2, y2)


def main():
    # Set up first image
    next_file()

    root.mainloop()


if __name__ == "__main__":
    init()
    main()

Panamitsu (talk) 10:07, 18 February 2024 (UTC)

Aight this one's good:
File:Day care centre face blur test.png Blake Gripling (talk) 10:16, 18 February 2024 (UTC)
@Blakegripling ph:Glad it works. Were those faces blurred automatically or did you manually enter them in? —Panamitsu (talk) 10:52, 18 February 2024 (UTC)
At least most of the faces are detected, though there have been both false negatives and positives. Idk if you're able to make the edges of the circles feathered rather than hard tho. Blake Gripling (talk) 11:49, 18 February 2024 (UTC)
I think blurring the mask should feather it. That's a one-liner. You could also try reducing the BLUR_AMOUNT value to make the blur less harsh, but that won't feather it. —Panamitsu (talk) 13:58, 18 February 2024 (UTC)
How do you blur the mask then? Blake Gripling (talk) 01:27, 19 February 2024 (UTC)
Just before the line
final = Image.composite(im, blurred, mask)
Add this line:
mask = mask.filter(ImageFilter.GaussianBlur(radius=3))
Adjust the radius value to your liking. Three seems to work the best for me.
Also, if you don't realise, with that image you put in the talk page, those orange circles is not the final output. Click "save image" and the the orange circles are replaced with blurs and is placed in the "output" folder. —Panamitsu (talk) 10:26, 19 February 2024 (UTC)
Yea I am aware of that one regarding the window. I was merely illustraing how effective it is if it works; there are indeed false positives as you pointed out earlier but it's nothing a little manual intervention can't fix. If anything this should make censoring images a tad faster now. Blake Gripling (talk) 12:40, 19 February 2024 (UTC)
OK, the script runs fine but I end up with an exception after the last image. Maybe it would be nice to make it exit gracefully? Blake Gripling (talk) 08:05, 21 February 2024 (UTC)
Sorry I forgot to add that. That's the iterator saying that there are no files left. To fix it, in the save_image function at the end, replace the "next_file"() with this:
try:
    next_file()
except StopIteration:
    print("All images have been blurred.")
    exit()
You can also add this to the next_file() call in the main function with a custom message saying "No files in input folder", but this iterator practice getting silly. I wanted to just use a for loop but I can't immediately figure out how due to the need to call root.mainloop(). —Panamitsu (talk) 11:22, 21 February 2024 (UTC)

Concern regarding Draft:Te Anau takahē statue

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Te Anau takahē statue, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 02:06, 15 February 2024 (UTC)

DYK for Jessica Mutch McKay

On 17 February 2024, Did you know was updated with a fact from the article Jessica Mutch McKay, which you recently created, substantially expanded, or brought to good article status. The fact was ... that Jessica Mutch McKay hosted debates between the leaders of New Zealand's two major political parties? The nomination discussion and review may be seen at Template:Did you know nominations/Jessica Mutch McKay. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Jessica Mutch McKay), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

Ganesha811 (talk) 00:02, 17 February 2024 (UTC)

Invitation to join New pages patrol

 

Hello Panamitsu!

  • The New Pages Patrol is currently struggling to keep up with the influx of new articles needing review. We could use a few extra hands to help.
  • We think that someone with your activity and experience is very likely to meet the guidelines for granting.
  • Reviewing/patrolling a page doesn't take much time, but it requires a strong understanding of Wikipedia’s CSD policy and notability guidelines.
  • Kindly read the tutorial before making your decision, and feel free to post on the project talk page with questions.
  • If patrolling new pages is something you'd be willing to help out with, please consider applying here.

Thank you for your consideration. We hope to see you around!

MediaWiki message delivery (talk) 15:21, 22 February 2024 (UTC)

Your draft article, User:Panamitsu/sandbox/Jack Massey Welsh

 

Hello, Panamitsu. It has been over six months since you last edited the Articles for Creation submission or Draft page you started, "sandbox/Jack Massey Welsh".

In accordance with our policy that Wikipedia is not for the indefinite hosting of material deemed unsuitable for the encyclopedia mainspace, the draft has been deleted. When you plan on working on it further and you wish to retrieve it, you can request its undeletion. An administrator will, in most cases, restore the submission so you can continue to work on it.

Thanks for your submission to Wikipedia, and happy editing. Liz Read! Talk! 22:02, 22 February 2024 (UTC)

DYK for Supie

On 24 February 2024, Did you know was updated with a fact from the article Supie, which you recently created, substantially expanded, or brought to good article status. The fact was ... that food was left to rot outside after the supermarket Supie went out of business? The nomination discussion and review may be seen at Template:Did you know nominations/Supie. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Supie), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

theleekycauldron (talk • she/her), Schwede66, and Kusma (talk) 00:02, 24 February 2024 (UTC)

Concern regarding Draft:Waitaki Marine Reserve

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Waitaki Marine Reserve, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 10:06, 6 March 2024 (UTC)

Concern regarding Draft:Te Umu Kōau Marine Reserve

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Te Umu Kōau Marine Reserve, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 10:07, 6 March 2024 (UTC)

Concern regarding Draft:Ōkaihae Marine Reserve

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Ōkaihae Marine Reserve, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 10:07, 6 March 2024 (UTC)

Concern regarding Draft:Hākinikini Marine Reserve

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Hākinikini Marine Reserve, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 10:07, 6 March 2024 (UTC)

Concern regarding Draft:Ōrau Marine Reserve

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Ōrau Marine Reserve, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 10:07, 6 March 2024 (UTC)

Concern regarding Draft:Papanui Marine Reserve

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Papanui Marine Reserve, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 10:08, 6 March 2024 (UTC)

DYK nomination of Shel Kaphan

  Hello! Your submission of Shel Kaphan at the Did You Know nominations page has been reviewed, and some issues with it may need to be clarified. Please review the comment(s) at your nomination's entry and respond there at your earliest convenience. Thank you for contributing to Did You Know! PCN02WPS (talk | contribs) 21:21, 8 March 2024 (UTC)

DYK for Milkrun

On 10 March 2024, Did you know was updated with a fact from the article Milkrun, which you recently created, substantially expanded, or brought to good article status. The fact was ... that only months after going out of business, Milkrun relaunched? The nomination discussion and review may be seen at Template:Did you know nominations/Milkrun. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Milkrun), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

RoySmith (talk) 00:03, 10 March 2024 (UTC)

Regarding your revert on antifeminism

Hi there, I see you reverted my change to antifeminism to link men's rights movement in the lede. Although MRAs are not mentioned in antifeminism, antifeminism is covered in depth in men's rights movement. BrigadierG (talk) 21:34, 10 March 2024 (UTC)

Yes that's right. There were two problems though. Firstly, you did not provide a reliable source, although this can easily be fixed. The main problem however is that the antifeminism article currently does not contain any information about the men's rights movement. As the lead is supposed to summarise the article's content (WP:LEAD), it would not be due for inclusion at the article's current state. —Panamitsu (talk) 00:18, 11 March 2024 (UTC)
@BrigadierG Sorry I forgot to ping you. —Panamitsu (talk) 05:54, 11 March 2024 (UTC)
Fair enough. I've re-added the link into the lead backed up with a bunch of sources copied from the main men's rights movement article. Was worried about creating a potential WP:POVFORK but on balance I think it's fine. BrigadierG (talk) 12:40, 11 March 2024 (UTC)
@BrigadierG Looks good now. Thanks for your work. —Panamitsu (talk) 13:53, 11 March 2024 (UTC)

Unexplained revert on Markus Persson

Why did you revert me? Polygnotus (talk) 09:28, 13 March 2024 (UTC)

@Polygnotus: "Cringe" is not a valid reason for removing well-sourced content. See content removal, which says Removing a section of an article needs to be at least explained and in some cases discussed. Unexplained content removal (UCR) occurs when the reason is not obvious; the edit is then open to being promptly reverted.Panamitsu (talk) 09:31, 13 March 2024 (UTC)
It is cringe, but it was removed because Wikipedia is an encyclopedia, not an indiscriminate collection of information. Since this factoid is not encyclopedically relevant it should be removed. The WP:ONUS is on those who want to include content to get consensus for its inclusion. Sure, he got swindled. But why included this unimportant fact into his Wikipedia page? Polygnotus (talk) 09:33, 13 March 2024 (UTC)
@Polygnotus: The mention of Mensa has been there for at least five years. It is your responsibility to make your point about why it should be removed. Not mine. —Panamitsu (talk) 11:59, 13 March 2024 (UTC)
Not according to the WP:V policy. You have to follow policy, even if you disagree with it. argumentum ad antiquitatem is a logical fallacy. Polygnotus (talk) 12:04, 13 March 2024 (UTC)
See Talk:Markus_Persson#Mensa. I have found you three more sources. —Panamitsu (talk) 12:07, 13 March 2024 (UTC)
Great, we finally have some sources. But please stop editwarring. Have a normal conversation on the talkpage. Polygnotus (talk) 12:22, 13 March 2024 (UTC)
@Polygnotus: I have some advice for you:
1) Read WP:BRD. All of it. You have said your interpretation of WP:BRD appears to be incorrect. We are at the Discuss stage. You are the one who creating the initial removal (Bold). I then reverted it (Revert). Then we started talking (Discuss). What you have done is revert again, which broke the BRD rule. This means your interpretation is the BRDR rule.
2) Claiming logical fallacies the way you have done is not entirely civil. Using these "arguments" you will have a hard time getting consensus agreeing with your proposed change. —Panamitsu (talk) 12:34, 13 March 2024 (UTC)
First of all I wasn't trying to be incivil, so if that is how I was perceived then that is my bad. I like reading, gimme a sec. Polygnotus (talk) 12:35, 13 March 2024 (UTC)
I think the better essay is perhaps Wikipedia:What editors mean when they say you have to follow BRD. I disagree with the idea that, because a problem has not been fixed, it is somehow the consensus. If that would be the case then the group with the loudest mouth would always win, because they could just keep going and going while everyone else loses interest. WP:NODEADLINE and all that. And I honestly still do not understand why you think this factoid is worthy of inclusion. To me its like saying he has a labrador, or that his neighbour is right-handed. Polygnotus (talk) 12:41, 13 March 2024 (UTC)
Just curious, how did you find those sources? Google refused to help me (possibly because of GDPR). Polygnotus (talk) 14:28, 13 March 2024 (UTC)
Here. —Panamitsu (talk) 23:33, 13 March 2024 (UTC)
See Talk:Markus_Persson#Mensa Polygnotus (talk) 09:40, 13 March 2024 (UTC)


Search and replace

Just a reminder that using search and replace to correct spellings is often not safe. See New Zealand cuisine, where you added macrons to hāngī, as appropriate, but also changed the spellings of words inappropriately. I noticed another editor fixing the other words today.-Gadfium (talk) 00:46, 14 March 2024 (UTC)

@Gadfium: Thanks, I've noticed this clbuttic mistake before so I started adding spaces before and after in the find/replace. Unfortunately it does look like a few slipped through. —Panamitsu (talk) 02:26, 14 March 2024 (UTC)
Great. That was an old example, so if you've changed your routine since then everything's copacetic.-Gadfium (talk) 02:51, 14 March 2024 (UTC)

Your draft article, Draft:Te Anau takahē statue

 

Hello, Panamitsu. It has been over six months since you last edited the Articles for Creation submission or Draft page you started, "Te Anau takahē statue".

In accordance with our policy that Wikipedia is not for the indefinite hosting of material, the draft has been deleted. When you plan on working on it further and you wish to retrieve it, you can request its undeletion. An administrator will, in most cases, restore the submission so you can continue to work on it.

Thanks for your submission to Wikipedia, and happy editing. Liz Read! Talk! 01:51, 15 March 2024 (UTC)

Category:Discrimination against men has been nominated for deletion

 

Category:Discrimination against men has been nominated for deletion. A discussion is taking place to decide whether it complies with the categorization guidelines. If you would like to participate in the discussion, you are invited to add your comments at the category's entry on the categories for discussion page. Thank you. Marcocapelle (talk) 08:42, 16 March 2024 (UTC)

Rotomahana (and others)

As yes, good point, thanks! DBaK (talk) 09:23, 21 March 2024 (UTC)

@DisillusionedBitterAndKnackered: I use that template to replace American spellings with New Zealand ones in AWB. People using American spellings here nowadays appears to be an epidemic. —Panamitsu (talk) 09:32, 21 March 2024 (UTC)

DYK for Jo-anne Wilkinson

On 25 March 2024, Did you know was updated with a fact from the article Jo-anne Wilkinson, which you recently created, substantially expanded, or brought to good article status. The fact was ... that Jo-anne Wilkinson and Graeme Dingle crossed the Bering Sea in a leaking boat? The nomination discussion and review may be seen at Template:Did you know nominations/Jo-anne Wilkinson. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Jo-anne Wilkinson), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

Z1720 (talk) 00:02, 25 March 2024 (UTC)

I have sent you a note about a page you started

Hello, Panamitsu. Thank you for your work on Le Snak. North8000, while examining this page as a part of our page curation process, had the following comments:

Nice work

To reply, leave a comment here and begin it with {{Re|North8000}}. Please remember to sign your reply with ~~~~. (Message delivered via the Page Curation tool, on behalf of the reviewer.)

North8000 (talk) 14:51, 27 March 2024 (UTC)

Concern regarding Draft:Leonard Cornwall Mitchell

  Hello, Panamitsu. This is a bot-delivered message letting you know that Draft:Leonard Cornwall Mitchell, a page you created, has not been edited in at least 5 months. Drafts that have not been edited for six months may be deleted, so if you wish to retain the page, please edit it again or request that it be moved to your userspace.

If the page has already been deleted, you can request it be undeleted so you can continue working on it.

Thank you for your submission to Wikipedia. FireflyBot (talk) 00:04, 1 April 2024 (UTC)

DYK for BrewGroup

On 3 April 2024, Did you know was updated with a fact from the article BrewGroup, which you recently created, substantially expanded, or brought to good article status. The fact was ... that Bell Tea, founded in 1898, is the oldest tea company in New Zealand? The nomination discussion and review may be seen at Template:Did you know nominations/BrewGroup. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, BrewGroup), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

Z1720 (talk) 12:02, 3 April 2024 (UTC)

DYK for Shel Kaphan

On 4 April 2024, Did you know was updated with a fact from the article Shel Kaphan, which you recently created, substantially expanded, or brought to good article status. The fact was ... that Shel Kaphan was the first employee of Amazon? The nomination discussion and review may be seen at Template:Did you know nominations/Shel Kaphan. You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Shel Kaphan), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

 — Amakuru (talk) 12:02, 4 April 2024 (UTC)

  Hook update
Your hook reached 7,565 views (630.4 per hour), making it one of the most viewed hooks of April 2024 – nice work!

GalliumBot (talkcontribs) (he/it) 03:28, 5 April 2024 (UTC)

DYK for Trumpet (ice cream)

On 5 April 2024, Did you know was updated with a fact from the article Trumpet (ice cream), which you recently created, substantially expanded, or brought to good article status. The fact was ... that the phrase "togs, togs, undies" was popularized in New Zealand by an advertisement for Trumpet ice cream cones? The nomination discussion and review may be seen at Template:Did you know nominations/Trumpet (ice cream). You are welcome to check how many pageviews the nominated article or articles got while on the front page (here's how, Trumpet (ice cream)), and the hook may be added to the statistics page after its run on the Main Page has completed. Finally, if you know of an interesting fact from another recently created article, then please feel free to suggest it on the Did you know talk page.

Cwmhiraeth (talk) 12:03, 5 April 2024 (UTC)