Answer the question
In order to leave comments, you need to log in
How to find a specific object in an image?
There is a neural network that classifies images of road signs 200x200.
How can we now find these signs in a 1920x1080 image? I tried to cut along the contours, but along with the signs, any garbage is also saved.
import cv2
from PIL import Image
image = cv2.imread("C:/Users/pikro/PycharmProjects/ML/road_sign/test.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edged = cv2.Canny(image, 10, 200)
_, cnts, _ = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
idx = 0
rects = sorted([cv2.boundingRect(c) for c in cnts], key=lambda x: x[0])
for x, y, w, h in rects:
if w > 100 and h > 100:
idx += 1
new_img = image[y - 3:y + h + 3, x - 3:x + w + 3]
cv2.imwrite("C:/Users/pikro/PycharmProjects/ML/road_sign/crop/" + str(idx) + '.png', new_img)
cv2.imshow("im", image)
cv2.waitKey(0)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question