AttributeError: 'PhotoImage' object has no attribute 'shape'?

Ich bin derzeit dabei mit tkinter, opencv und mit Media Pipe Framework zu arbeiten. Dabei möchte ich Bilder Hochladen können und die hochgeladenen Bilder soll mithilfe von Mediapipe die Hand Landmarks erfassen. Mit Hand Landmarks meine ich alle 21 Positionen eines Hand zu erkennen (Hier findet ihr mehr Infos dazu: https://google.github.io/mediapipe/solutions/hands.html ). Leider bekomme ich mit meiner erstellten Implementierung folgende Fehlermeldung:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:/Users/bj/projects/pro1/pictureMp.py", line 31, in imageLandmarks
    height, width, _ = image.shape
AttributeError: 'PhotoImage' object has no attribute 'shape'

Was kann ich dagegen machen? Hier ist mein aktueller Code:

def imageLandmarks():
    global panelA
    with mpHands.Hands(static_image_mode=True, max_num_hands=2, min_detection_confidence=0.5) as hands:
        select_image.path = filedialog.askopenfilename()
        filename = os.path.basename(select_image.path)

        if len(select_image.path) > 0:
            image = cv2.imread(select_image.path)
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            image = Image.fromarray(image)
            image = ImageTk.PhotoImage(image)

            height, width, _ = image.shape
            results = hands.process(image)

            num_cords = 21
            landmarks = ['class']
            for val in range(1, num_cords + 1):
                landmarks += ['x{}'.format(val), 'y{}'.format(val), 'z{}'.format(val)]

                if results.multi_hand_landmarks:
                    for num, hand in enumerate(results.multi_hand_landmarks):
                        mpDraw.draw_landmarks(image, hand, mpHands.HAND_CONNECTIONS)
programmieren, Python, opencv, Tkinter
Primzahlengenerator: Ist die Funktion, die ich in Python programmiert bereits bekannt?

Im folgenden Python Programm werden alle ungeraden Primzahlen generiert.

Es verwendet die senkrechte "Mittellinie" des Pascalschen Dreiecks. Beispielzahlen, die verwendet werden: 2,6,20,70,252,924,3432,.....

2 \ 3 = 2 -> 3 - 2 = 1 -> Prim
6 \ 5 = 1 -> Prim
20 \ 7 = 6 -> 7 - 6 = 1 -> Prim
70 \ 9 = 7 bzw. 9 - 7 = 2 -> Rest ungleich 1 -> nicht Prim
252 \ 11 = 10 -> 11 - 10 = 1 -> Prim
# Programer: Peter Rasinger, Ferlach, Austria, 2005 - 2021
import math
import decimal
decimal.getcontext().prec = 2500000 #250000000000000000
decimal.getcontext()
def is_prim(a4,d4):
  f4 = a4 % d4
  g4 = d4 - f4
  if f4 == 1 or g4 == 1 and d4 != 1:
    return(1==1)
  else:
    return(1==2)
def calc_prim(f3,g3,h3): #f3 = x over x/2 : x \ 2 == 0 ... and g3 == x / 2 ... 6 over 3 = 20 = 6! / (3! * 3!), 8 over 4 = 70
             #h3 = steps to calulate (impair numbers)
  a3 = f3
  b3 = g3
  c3 = b3 + 1
  if is_prim(a3,c3):
    print(c3)
  for i3 in range(g3 + 2,(h3 * 2) + g3,2):
    r3 = a3 * 4
    s3 = r3 // i3
    a3 = r3 - s3
    b3 = i3
    c3 = b3 + 1
    if is_prim(a3,c3):
      print(c3)
  print(math.trunc((math.log(a3) // math.log(10)) + 1)," max digits used")
calc_prim(252,10,100) #252 = 10! / (5! * 5!) ... check 100 impairs ... startvalues for 11
#calc_prim(924,12,100) #924 = 12! / (6! * 6!) ......................... startvalues for 13
#calc_prim(2,2,5)
Mathematik, programmieren, Primzahlen, Python

Meistgelesene Beiträge zum Thema Python