提供されている画像内の形を認識する方法を学習しています。私は、幾何学的物体に存在する辺の数によって形状を認識することができます。しかし、今私は画像内の正方形と長方形を区別する方法があるのだろうか? ここに私のコードです。現在、幾何学図形に輪郭を描いています。opencv2 pythonを使用した画像の長方形と正方形の区別
import cv2
raw_image = cv2.imread('test1.png')
cv2.imshow('Original Image', raw_image)
cv2.waitKey(0)
bilateral_filtered_image = cv2.bilateralFilter(raw_image, 5, 175, 175)
cv2.imshow('Bilateral', bilateral_filtered_image)
cv2.waitKey(0)
edge_detected_image = cv2.Canny(bilateral_filtered_image, 75, 200)
cv2.imshow('Edge', edge_detected_image)
cv2.waitKey(0)
_, contours, hierarchy = cv2.findContours(edge_detected_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contour_list = []
for contour in contours:
approx = cv2.approxPolyDP(contour,0.01*cv2.arcLength(contour,True),True)
area = cv2.contourArea(contour)
if ((len(approx) >= 3)):
contour_list.append(contour)
cv2.drawContours(raw_image, contour_list, -1, (0,0,0), 2)
cv2.imshow('Objects Detected',raw_image)
cv2.waitKey(0)
いくつかのサンプル入力画像、好ましくはバイナリ画像をアップロードできる方が良いでしょう。また、あなたの図は回転していますか? – ZdaR
はいシェイプはお互いに回転することができ、同じイメージ内に複数のシェイプがある可能性があります – HrishikeshKulkarni
裾、多分両側の等価性をチェックしてください。これは、四角形と四角形を区別するものです。 –