Reputation: 1
I'm in the process of developing a Flask Python application that's able to find a logo within different background images. The goal is to have a solution that states "yes, the logo is in the background", or "no, it doesn't look like the logo is in the background". I'm utilizing the SIFT package to match keypoints between the logo and the image with the logo in the background.
I want to figure out how I can write an IF statement that's able to deliver the message above depending on the keypoints. Is there anyone that can give me guidance on the first steps of doing this? I'll attach the code to this message (note that the function should have an indent there):
@app.route('/identify/<filename>')
def identify(filename):
""" After uploading the image,
show the identification of the uploaded image
"""
# TODO: Logic to load the uploaded image filename and identify other images
image_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
image_url = url_for('images', filename=filename)
background_image = cv2.imread(image_path)
background_image = cv2.cvtColor(background_image, cv2.COLOR_BGR2RGB)
#still need to figure out how to load a second photo of the user's choice
#loading in the photo to find within the uploaded photo
logo = cv2.imread("chevy-open-road-logo-300.png")
logo = cv2.cvtColor(logo, cv2.COLOR_BGR2RGB)
#creating a copy and implementing a SIFT Image Matching method
background_image_copy = background_image.copy()
#sift
sift = cv2.xfeatures2d.SIFT_create()
background_keypoints, background_descriptors = sift.detectAndCompute(background_image_copy, None)
logo_keypoints, logo_descriptors = sift.detectAndCompute(logo, None)
#feature matching
bf = cv2.BFMatcher(cv2.NORM_L1, crossCheck=True)
matches = bf.match(background_descriptors,logo_descriptors)
matches = sorted(matches, key = lambda x:x.distance)
#img = BytesIO()
image_match = cv2.drawMatches(background_image_copy, background_keypoints, logo, logo_keypoints, matches[:45], logo, flags=2)
plt.imshow(image_match), plt.show()
'''
#Converting the plot to PNG image
plt.savefig(img, format='png', bbox_inches='tight')
img.seek(0)
plot_url = base64.b64encode(img.getvalue()).decode()
'''
'''
#Printing the number of keypoints detected in the training image
x = str(len(background_keypoints))
#Printing the number of keypoints detected in the logo image
y = str((len(logo_keypoints)))
# Printing total number of matching points between the training and logo images
z = str((len(matches)))
'''
return render_template('identify.html',
image = image_url#, plot_url=plot_url
#x=x, y=y, z=z
)
Upvotes: 0
Views: 126