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()