Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

二個のArUcoマーカーを角として領域を切り取る

実際のところ

重心を使いましたが、気になる人は内側の角にするのもよさそう。

import cv2
import numpy as np

aruco = cv2.aruco
dictionary = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)


img_src = cv2.imread("target.png", 1)

corners, ids, rejectedImgPoints = aruco.detectMarkers( img_src, dictionary )
print(corners, ids)


center_42 = np.mean(corners[1][0],axis=0)
cent_42_x = int(center_42[0])
cent_42_y = int(center_42[1])

center_2 = np.mean(corners[0][0],axis=0)
cent_2_x = int(center_2[0])
cent_2_y = int(center_2[1])



print( center_42, center_2 )

im_new = img_src[cent_42_y:cent_2_y, cent_42_x:cent_2_x, :]

cv2.imwrite("result.png", im_new)