DEV Community

Cover image for Master "Can You Find the Odd One Out" with this Python trick
isolderea
isolderea

Posted on

1

Master "Can You Find the Odd One Out" with this Python trick

The Challenge

Spot the odd one out is always fun to solve but it does require good eyes and some time.

So i was thinking I need to find a fast way to solve all fast with code

Here comes Python

I did a reverse solution for Finding Waldo to solve this with Python

https://docs.opencv.org/4.x/d4/dc6/tutorial_py_template_matching.html

See the code below

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img_rgb = cv.imread('mario.png')
img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)
template = cv.imread('mario_coin.png',0)
w, h = template.shape[::-1]
res = cv.matchTemplate(img_gray,template,cv.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
cv.imwrite('res.png',img_rgb)

See the full video here
https://www.youtube.com/watch?v=G-6IWgu5PTI&ab_channel=ResterTest

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more