###前提・実現したいこと
動画からテンプレートマッチングにより入力画像の中心座標を求めてそれを三角測量の式を用いてX,Y,Zを出しています。
X,Y,Zを求める計算と同じタイミングでグラフにプロットされるようにしたい。
###発生している問題・エラーメッセージ
Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation)
というエラーコードが出てしまいます。
###該当のソースコード
Python
1#グラフ 2# グラフの初期化 3def init_plot(d): 4 fig = plt.figure() 5 ax = fig.add_subplot(111, projection='3d') 6 7 ax.set_xlabel("X-axis") 8 ax.set_ylabel("Y-axis") 9 ax.set_zlabel("Z-axis") 10 ax.set_xlim(-30, 30) 11 ax.set_ylim(-40, 20) 12 ax.set_zlim(100, 200) 13 14 # 最初に描画データを与えておく必要あり 15 l1, = ax.plot(d[:,0], d[:,1], d[:,2], "o", color="g", ms=16, mew=0.5) # 初期データ用 16 l2, = ax.plot([0], [0], [0], "x", color="r", ms=8, mew=0.5) # 追加データ用 初回はダミーをセット 17 return l1,l2 # 呼出元で利用 18 19# グラフの描画更新 20def update_plot(lines,d): 21 lines.set_data(d[:,0],d[:,1]) # x,y 22 lines.set_3d_properties(d[:,2]) # z 23 plt.pause(.01) 24 25if __name__ == "__main__": 26 27 # 最初から表示するデータ 28 d = genfromtxt("Planned.csv", delimiter=",") 29 30 # グラフの初期化 31 l1,l2 = init_plot(d) # l1=初期データ, l2=追加データ用 32 update_plot(l1,d) 33 34 time.sleep(1) 35 36 # データ追加し描画更新 37 a = np.array([[X,Y,Z]]) # 追加データ 38 update_plot(l2,a) 39 40 time.sleep(1) 41 42 # ループで追加 43 for i in range(113): 44 a = np.vstack((a,[X,Y,Z])) 45 update_plot(l2,a) 46 47 time.sleep(0.5) 48 49 # 最後に確認表示できるように 50 plt.show() 51 52# テンプレート画像読み込み 53img_obj = cv2.imread('1027.jpg', cv2.IMREAD_COLOR) 54 55if img_obj is None: # テンプレート画像が取得できない場合 56 print u'画像が取得できません。' 57 sys.exit() 58 59# 映像取得(カメラ映像) 60src = cv2.VideoCapture('0deg_10fps_x20 ver3.avi') 61 62if not src.isOpened(): # カメラ映像が取得できない場合 63 print u'映像が取得できません。' 64 sys.exit() 65 66retval, frame = src.read() 67height1, width1, channels1 = img_obj.shape 68height2, width2, channels2 = frame.shape 69 70rec = cv2.VideoWriter('0deg_10fps_x20 改.avi', cv.CV_FOURCC('X','V','I','D'), 6, (width2, height2)) 71 72f = open('result.csv', 'ab') #csvファイルが無ければ作る、の'a'を指定します 73 74csvWriter = csv.writer(f) 75val = 0 76 77while True: 78 79 retval, frame = src.read() # 1フレーム取得 80 81 if frame is None: 82 break 83 84 # テンプレート・マッチングにより相互相関係数を計算 85 img_ccoeff1 = cv2.matchTemplate(frame, img_obj, cv2.TM_CCOEFF_NORMED) 86 87 # [-1, 1] を [0, 1] へ 88 cv2.normalize(img_ccoeff1,img_ccoeff1, 0, 1, cv2.NORM_MINMAX) 89 90 # 相互相関係数の最小値・最大値とその座標を抽出 91 cMin, cMax, pMin, pMax1 = cv2.minMaxLoc(img_ccoeff1) 92 93 # 検出領域の中心座標 94 detect = (pMax1[0] + width1/2, pMax1[1] + height1/2) 95再追記終わり 96 97 x = pMax1[0] + width1/2, pMax1[1] + height1/2 98 99 x1 = (((round(((pMax1[0] + width1/2)-385)*0.327,2))), (round(((pMax1[1] + height1/2)-290)*0.327,2))) 100 x2 = (round(((pMax1[0] + width1/2)-385)*0.327,2)) 101 y2 = (round(((pMax1[1] + height1/2)-290)*0.327,2)) 102 103 104 a = np.array([x2,y2]) 105 106 text1 = "" + str(x1) + "" 107 text2 = "" + str(x2) + "" 108 text3 = "" + str(y2) + "" 109 110 cv2.putText(frame, text1, ((pMax1[0] + width1/2)-65, (pMax1[1] + height1/2)-30), cv2.FONT_HERSHEY_COMPLEX, 0.7, (0, 255, 0), 2, cv2.CV_AA) 111 cv2.putText(frame, "L1", ((pMax1[0] + width1/2)-70, (pMax1[1] + height1/2)-60), cv2.FONT_HERSHEY_COMPLEX, 0.7, (0, 255, 0), 2, cv2.CV_AA) 112 113 114 # 探索画像から検出領域を抽出 115 img_crop = frame[pMax1[1]:pMax1[1]+height1, pMax1[0]:pMax1[0]+width1].copy() 116 117 # 検出領域に赤色の円と十字を描画 118 cv2.circle(frame, detect, width1/2, (0, 0, 255), 1) 119 cv2.line(frame,((pMax1[0] + width1/2) - 25, pMax1[1] + height1/2), ((pMax1[0] + width1/2) + 25 , pMax1[1] + height1/2), (0, 0, 255), 1) 120 cv2.line(frame,((pMax1[0] + width1/2), (pMax1[1] + height1/2 )-25), ((pMax1[0] + width1/2), (pMax1[1] + height1/2) + 25), (0, 0, 255), 1) 121 122 x1 = (((round(((pMax1[0] + width1/2)-385)*0.327,2))), (round(((pMax1[1] + height1/2)-290)*0.327,2))) 123 x2 = (round(((pMax1[0] + width1/2)-385)*0.327,2)) 124 y2 = (round(((pMax1[1] + height1/2)-290)*0.327,2)) 125 126 y1 = (round(((pMax2[0] + width1/2)-385)*0.327,2), round(((pMax2[1] + height1/2)-290)*0.327,2)) 127 x3 = (round(((pMax2[0] + width1/2)-385)*0.327,2)) 128 y3 = (round(((pMax2[1] + height1/2)-290)*0.327,2)) 129 130 X = (round((50/(l-50))*((x2 + x3)/2),2)) 131 Y = (round((50/(l-50))*((y2 + y3)/2),2)) 132 Z = ((round(50/(l-50)*213,2))) 133 134追記 135
このX,Y,Zをax1(X,Y,Z),ax2(X,Y),ax3(Y,Z)にプロットしたいです。
###試したこと
matplotlibでリアルタイム描画を参考にしてコードを考えてみましたが上手くいきませんでした。
URL先ではsin関数を描画していますが、散布図でプロットしたいです。
###補足情報(言語/FW/ツール等のバージョンなど)
windows10,python2.7,matplotlib,spyder

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/10 00:39
2017/07/10 08:13
2017/07/10 09:03
2017/07/11 00:03
2017/07/11 01:37
2017/07/11 02:03
2017/07/11 03:00
2017/07/11 03:21
2017/07/11 04:23
2017/07/11 09:07 編集
2017/07/11 08:16
2017/07/11 09:07