trying to call python function using jupyter notebook, does not acknowledge function declaration

47 views Asked by At

I am running a function in a Python program I am writing on Jupyter notebook.

When I try to call it does not recognize the name in the function call.

Here is the function declaration:

def object_detection_api(img_path, threshold=0.5, rect_th=3, text_size=3,text_th=3): 
     boxes, pred_cls = get_prediction(img_path, threshold) 
     # Get predictions 
     img = cv2.imread(img_path) 
      # Read image with cv2 
     img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

etc.

Here is where I call it in the same python file, earlier in the code:

for images in os.listdir(folder_dir):

  # check if the image ends with png
 #if (images.endswith(".png")):
    #print(images)
  boxes, classes =  object_detection_api(, imagesthreshold=0.5, rect_th=3, text_size=3, text_th=3)

 print("boxes length: ", len(boxes))
 print("boxes type: ", type(boxes), " ", type(boxes))
 print("classes type: " , type(classes))

 #retrieve data from these results 

 #data.append(thisImageData)
 #thisImageData = {"quantity": 0, "area": 0}
 break

I tried to find a spelling mistake but I am just not saying it. Does not complain of the wrong arguments or wrong return types.

Error message:

NameError: name 'object_detection_api' is not defined

I don't know if I made an indent error or declaring it or messed up the scope somehow.

1

There are 1 answers

0
EmersuCC On

Try run your definition cell first to add your function to jupyter context, also, you need to check the return of object_detection_api,the call to object_detection_api within the loop has a syntax error: there is a comma before imagesthreshold=0.5 which should be part of the function arguments, try add image_path. Then run again your code