https://rikutyan.com/pc/programming-pc/184/
上記URLを参考に、リアルタイムでARマーカを認識し、その位置をリアルタイムでグラフで表示する!にチャレンジしていますが
マーカを読み込んだ瞬間に、止まってしまいます、(ワンショットでとます)
すみませんが、常に位置をグラフで表示する、アドバイスいただけると助かります。
よろしくお願いいたします
# チャレンジ内容 import numpy as np import cv2 import matplotlib.pyplot as plt aruco = cv2.aruco cap = cv2.VideoCapture(0) dictionary = aruco.getPredefinedDictionary(aruco.DICT_4X4_50) while True: ret, img = cap.read() cv2.imshow('img',img) corners, ids, rejectedImgPoints = aruco.detectMarkers(img, dictionary) # 座標データ格納用変数 p = np.empty((4, 2)) _corners = [np.empty((1, 4, 2))] * 4 if ids is None: print("None dayo") else: print(ids.ravel()) # 0 ~ 3番のARマーカーの座標取得 for i, c in zip(ids.ravel(), corners): if i <= 3: _corners[i] = c.copy() # トリミング用の座標値の取得 p[0] = _corners[0][0][2] p[1] = _corners[1][0][3] p[2] = _corners[2][0][0] p[3] = _corners[3][0][1] print(p) pt1 = np.float32([p[0], p[1], p[2], p[3]]) pt2 = np.float32([[0, 0], [150, 0], [150, 150], [0, 150]]) # 画像の変形 gPT = cv2.getPerspectiveTransform(pt1, pt2) dst = cv2.warpPerspective(img, gPT, (150, 150)) # 変形後の画像でArUcoの再定義 corners, ids, rejectedImgPoint = aruco.detectMarkers(dst, dictionary) aruco.drawDetectedMarkers(dst, corners, ids, (0, 255, 0)) if ids is not None: x = np.zeros(len(ids)) y = np.zeros(len(ids)) for i in range(len(ids)): c = corners[i][0] x_avg = sum(c[:, 0]) / 4 y_avg = sum(c[:, 1]) / 4 x[i], y[i] = x_avg, y_avg plt.imshow(dst) plt.figure(figsize=(5, 5)) plt.xlim(0, 150) plt.ylim(150, 0) plt.grid(True) plt.scatter(x, y, marker="o", c="b") plt.show() key = cv2.waitKey(1) if key == 27: # ESC break cap.release() cv2.destroyAllWindows()

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。