Python program Error

This is my Python Code :-(In uipath getting the error " Load Python Script: Error loading Python script")
import os
import cv2
import numpy as np

def matchTemplate():
folder = ‘Fwd_images’
large_image = ‘mainImage.png’
# large_image = cv2.imread(f’0.jpg’)
filename = f’{large_image}.txt’
file = open(filename,‘w’)

large_image = cv2.imread(large_image)

method = cv2.TM_SQDIFF_NORMED


# Read the images from the file
for imagefile in os.listdir(folder):
    small_image = cv2.imread(f'{folder}/{imagefile}')

    result = cv2.matchTemplate(small_image, large_image, method)
    
#     print(loc)
    # We want the minimum squared difference
    mn,_,mnLoc,_ = cv2.minMaxLoc(result)
#     print(mn,imagefile,bn)
    if mn < 0.20:

        # Draw the rectangle:
        # Extract the coordinates of our best match
        MPx,MPy = mnLoc

        # Step 2: Get the size of the template. This is the same size as the match.
        trows,tcols = small_image.shape[:2]

        # Step 3: Draw the rectangle on large_image
        cv2.rectangle(large_image, (MPx,MPy),(MPx+tcols,MPy+trows),(0,255,0),2)
        file.write(imagefile.split('.')[0]+'\n')
        out_image=imagefile.split('.')[0]

        # Display the original image with the rectangle around the match.
#         cv2.imshow('output',large_image)

        # The image is only displayed if we call this
#         cv2.waitKey(0)
        
        
file.close()    
notepad_out=os.system(f'Notepad {filename}')
return notepad_out

matchTemplate()

can i see your code uipath code?

@m.sable Run the code in cmd prompt and check exactly what issue is there in it.

Also, You will have to use invoke python method activity to call the method matchTemplate() instead of calling itself in the python code.

run the code in cmd but in uipath show the error in load pyhton script

@m.sable Please take a screenshot of UiPath code and post here so that we can help you out.

1 Like

@m.sable You have taken screenshot of python code. I want to check the UiPath activities that you developed to run this.

1 Like

hey,
@m.sable
pass the Input Parameters what ever the function you are calling!

yes, i pass the input parameters after that he shows the same Error(“Load Python Script: Error loading Python script”)

1 Like

screen shot the entire error!
@m.sable

1 Like

click on Deatils and drag to the end send screen shot again!

image drag this to end!!
@m.sable and send screen shot!

1 Like

horizontal one buddy!

1 Like