質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

4328閲覧

Point2fで取得したマーカの角座標を使って中心座標を別スクリプトへ送りたい

akito0705

総合スコア23

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/12/01 15:32

LiveSketchScriptで取得したマーカの角座標を使ってMarkerTrackingへマーカの中心座標を送りたいです。
現状はそれぞれの変数を参照すること自体はできてますが、point2fの扱い方がわからずに数値が代入できていません。

LiveSketchScript側の

mt.WStartp = corners;

の部分で中心座標を出して、それをWStartpに入れたいです。

このまま実行すると

OpenCvSharp.Point2f[][] UnityEngine.Debug:Log(Object) MarkerTracking:Update() (at Assets/MarkerTracking.cs:26)

とコンソールに出てくるだけで、数値が全く入っていません。
point2fの中身を取得、計算するにはどうすればいいのでしょうか?

よろしくお願いします。

MarkerTracking

1using OpenCvSharp; 2using OpenCvSharp.Demo; 3using System.Collections; 4using System.Collections.Generic; 5using UnityEngine; 6 7public class MarkerTracking : MonoBehaviour 8{ 9 LiveSketchScript LSS; 10 public Point2f[][] WStartp, WEndo, CStartp, CEndp; 11 //DefaultTrackableEventHandler DTE; 12 bool Count = false; 13 Vector2 WposST, WposED, CposST, CposED,Ccal; 14 float Dist; 15 // Start is called before the first frame update 16 void Start() 17 { 18 //DTE = this.gameObject.GetComponent<DefaultTrackableEventHandler>(); 19 } 20 21 // Update is called once per frame 22 void Update() 23 { 24 if (WStartp != null) 25 { 26 Debug.Log(WStartp); 27 } 28 if (Input.GetKeyDown("return")) 29 { 30 Debug.Log(WStartp); 31 if (Count == false) 32 { 33 //WposST = GameObject.Find("WorldMarker").transform.position; 34 //CposST = this.gameObject.transform.position; 35 36 Count = true; 37 } 38 else if(Count) 39 { 40 Ccal = CposED - (WposED - WposST); 41 Dist = Vector3.Distance(CposST, Ccal); 42 Debug.Log(Dist); 43 Count = false; 44 } 45 } 46 if(Count) 47 { 48 WposED = GameObject.Find("WorldMarker").transform.position; 49 CposED = this.gameObject.transform.position; 50 } 51 } 52} 53

LiveSketchScript

1namespace OpenCvSharp.Demo 2{ 3 using UnityEngine; 4 using OpenCvSharp; 5 using Aruco; 6 7 public class LiveSketchScript : WebCamera 8 { 9 MarkerTracking mt; 10 protected override void Awake() 11 { 12 base.Awake(); 13 this.forceFrontalCamera = true; 14 var thread_mgr = GameObject.Find("SampleRaw") as GameObject; 15 mt = thread_mgr.GetComponent<MarkerTracking>(); 16 } 17 18 // Our sketch generation function 19 protected override bool ProcessTexture(WebCamTexture input, ref Texture2D output) 20 { 21 22 // Create default parameres for detection 23 DetectorParameters detectorParameters = DetectorParameters.Create(); 24 25 // Dictionary holds set of all available markers 26 Dictionary dictionary = CvAruco.GetPredefinedDictionary(PredefinedDictionaryName.Dict6X6_250); 27 28 // Variables to hold results 29 Point2f[][] corners; 30 int[] ids; 31 Point2f[][] rejectedImgPoints; 32 33 // Create Opencv image from unity texture 34 Mat mat = Unity.TextureToMat(input); 35 36 // Convert image to grasyscale 37 Mat grayMat = new Mat(); 38 Cv2.CvtColor(mat, grayMat, ColorConversionCodes.BGR2GRAY); 39 40 // Detect and draw markers 41 CvAruco.DetectMarkers(grayMat, dictionary, out corners, out ids, detectorParameters, out rejectedImgPoints); 42 CvAruco.DrawDetectedMarkers(mat, corners, ids); 43 44 mt.WStartp = corners; 45 46 output = Unity.MatToTexture(mat); 47 48 49 return true; 50 } 51 } 52}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

エラーではなくマーカが認識できていないだけでした

投稿2019/12/01 16:14

akito0705

総合スコア23

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問