[Python] image processing

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    This is an assignment, i have put good effort since i am new to python programming:

    I am running the following function which takes in image and phrase (spaces will be removed so just text) as arguments, i have already been given all the import and preprocessing code, i just need to implement this function. I can only use getpixel, putpixel, load, and save. That is why coding this has been a hard task for me.

    def InsertoImage(srcImage, phrase):
    pix = srcImage.load()
    for index,value in enumerate(phrase):
    pix[10+index,15] = phrase[index]
    srcImage.save()
    pass


    This code is giving "system error" which says that "new style getargs format but argument is not tuple"

    C:\Users\Nave\Desktop\a1>a1_template.py lolmini.jpg Hi
    Traceback (most recent call last):
    File "C:\Users\Nave\Desktop\a1\a1_template.py", line 31, in <module>
    doLOLImage(srcImage, phrase)
    File "C:\Users\Nave\Desktop\a1\a1_template.py", line 23, in doLOLImage
    pix[10+index,15] = phrase[index]
    SystemError: new style getargs format but argument is not a tuple


    here is full code:

    from __future__ import division

    # letters, numbers, and punctation are dictionaries mapping (uppercase)
    # characters to Images representing that character
    # NOTE: There is no space character stored!
    from imageproc import letters, numbers, punctuation, preProcess

    # This is the function to implement
    def InserttoImage(srcImage, phrase):
    pix = srcImage.load()
    for index,value in enumerate(phrase):
    if value in letters:
    pix[10+index, 15] = letters[value]
    elif value in numbers:
    pix[10+index, 15] = numbers[value]
    elif value in punctuation:
    pix[10+index, 15] = punctuation[value]
    srcImage.save()
    pass

    # This code is performed when this script is called from the command line via:
    # 'python <name of this file>.py'
    if __name__ == '__main__':
    srcImage, phrase = preProcess()
    InserttoImage(srcImage, phrase)


    Thanks, letter, numbers, and punctuation are dictionaries which see the key element and open the image (font). But still there is an issue with pix[10+index, 15] as it is giving error:

    pix[10+index, 15] = letters[value]
    SystemError: new style getargs format but argument is not a tuple

    Continue reading...

Compartilhe esta Página