Пожалуйста, помогите мне с идентификацией объекта обнаруженного края изображения с использованием контуров. это часть моего кода, используя это, я могу отделить некоторые изображения, но с большими подробными изображениями. как я могу это изменитьИдентификация объекта при обнаружении края изображения?
import numpy as np
import cv2
# load image
img = cv2.imread('res/test6.jpg', 1)
# convert the image to grayscale, blur it, and detect edges
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 35, 125)
height, width = edged.shape
# find contours of object
ret, thresh = cv2.threshold(edged, 127, 255, 0)
contours = cv2.findContours(thresh, 1, 2)
cnts = contours[1]
for cnt in cnts:
# find and draw a rectangle around object
x, y, w, h = cv2.boundingRect(cnt)
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
# line parameter
x1 = x + w/2
y1 = y + h
x2 = x + w/2
y2 = height
# mark pixel depth with arrow
cv2.arrowedLine(img, (x2, y2), (x1, y1), (255, 0, 0), 4)
distance = (y2 - y1) * 0.03 + 4
cv2.putText(img, str(distance) + "m", (x1 + 5, y1 + 50), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 255)
print height, width
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import numpy as np
import cv2
# load image
img = cv2.imread('res/test6.jpg', 1)
# convert the image to grayscale, blur it, and detect edges
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 35, 125)
height, width = edged.shape
# find contours of object
ret, thresh = cv2.threshold(edged, 127, 255, 0)
contours = cv2.findContours(thresh, 1, 2)
cnts = contours[1]
for cnt in cnts:
# find and draw a rectangle around object
x, y, w, h = cv2.boundingRect(cnt)
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
# line parameter
x1 = x + w/2
y1 = y + h
x2 = x + w/2
y2 = height
# mark pixel depth with arrow
cv2.arrowedLine(img, (x2, y2), (x1, y1), (255, 0, 0), 4)
distance = (y2 - y1) * 0.03 + 4
cv2.putText(img, str(distance) + "m", (x1 + 5, y1 + 50), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 255)
print height, width
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Что я хочу, это ограничить идентификацию объектов.
Как любой может помочь вам, не зная ваших изображений ... пожалуйста, прочитайте [ask], затем улучшите свой вопрос – Piglet
Я добавил несколько изображений –
, вы должны объяснить, какой результат вы ожидаете и какой вывод вы получите вместо этого. изображение, которое вы предоставили, настолько перегружено оверлеями, что оно не помогает понять вашу проблему. – Piglet