Python NameError: name 'a' is not defined

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

currently a college student project. Python and recognition and object using the opencv. 2개의 사진을 촬영후 두 객체인식 박스의 차 값을 갖고 싶어 배열로 선언 후 진행할까 했습니다.

- Source code omitted -

if len(body):
    for (x,y,w,h) in body:
        cv2.rectangle(img1,(x,y),(x+w,y+h),(0,0,255),2)
        a = [(x+w),(y+h)]


if len(body):
    for (a,b,c,d) in body:
        cv2.rectangle(img2,(a,b),(a+c,b+d),(0,0,255),2)
        b = [(a+c),(b+d)]


if a[0] - b[0] <= [-5] or a[1] - b[1] >= [5]:
    print ("Out")
    break

Since it's the first question, I omitted a lot of source code. Here, an error appears in the conditional statement, indicating that a is not declared.

  File "test3.py", line 49, in <module>
    if a[0] - b[0] <= [-5] or a[1] - b[1] >= [5]:
NameError: name 'a' is not defined

What am I missing?

python

2022-09-20 14:33

1 Answers

If len (body) conditions are not followed, a is not defined. That's why I got an error saying I don't know a.


2022-09-20 14:33

If you have any answers or tips


© 2022 pinfo. All rights reserved.