のようなイメージを持っていると私は棚から各書籍をトリミングしたいです。私はこのコードで始めました。
thresh = cv2.adaptiveThreshold(blur, 255, 1, 1, 11, 2)
cv2.imshow("Gray", gray)
cv2.waitKey(0)
cv2.imshow("Blurred", blur)
cv2.waitKey(0)
# detect edges in the image
edged = cv2.Canny(img, 10, 250)
cv2.imshow("Edged", edged)
cv2.waitKey(0)
# construct and apply a closing kernel to 'close' gaps between 'white'
# pixels
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 6))
closed = cv2.morphologyEx(edged, cv2.MORPH_CLOSE, kernel)
cv2.imshow("Closed", closed)
cv2.waitKey(0)
# loop over the contours
for contour in contours:
# peri = cv2.arcLength(contour, True)
# approx = cv2.approxPolyDP(contour, 0.02 * peri, True)
# r = cv2.boundingRect(contour)
if len(contour) >= 4:
index += 1
x, y, w, h = cv2.boundingRect(contour)
roi = img[y:y+h, x:x+w]
# cv2.imwrite("a/" + "book - " + str(index) + '.jpg', roi)
draw_contour = cv2.drawContours(img, [contour], -1, (255, 140, 240), 2)
total += 1
print contour
cv2.imshow("Drawed Contour", img)
cv2.waitKey(0)
私は棚から本のそれぞれにおけるバウンディングボックスを作成したが、残念ながらこれは私にoutputを与えます。ブックのサイド/コーナーにバウンディングボックスを描き、バウンディングボックスから切り抜きたいだけです。
私はhough transformを使用して長方形を検出し、方向とサイズでフィルタリングします。私は単純なエッジ検出器があなたのケースで動作するとは思わない。 –
よろしくお願いします。 – whaangbuu