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

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

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

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

OpenCV

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

Unity

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

Q&A

1回答

1590閲覧

中心座標の抽出方法を知りたい。

takaku

総合スコア0

C#

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

OpenCV

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

Unity

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

0グッド

0クリップ

投稿2021/11/25 10:10

Unityでopencvを用いてマーカー読み取りをおこなっています。Webカメラの設定、マーカーの読み取りはできたのですが、マーカーの中心座標を読み取るためにはどうしたら良いかと思い質問しました。

Point2f[][] corners; はマーカーの角4点にあたるもので、corners[:,0].mean(),corners[:,1].mean()でできないかと試しましたができませんでした。コードにするのが難しくご教示していただけると幸いです。

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using OpenCvSharp; 5using OpenCvSharp.Aruco; 6using UnityEngine.UI; 7 8public class AR : MonoBehaviour 9{ 10 11 [SerializeField] private RawImage _renderer; 12 13 private int _width = 1920; 14 private int _height = 1080; 15 private int _fps = 30; 16 private WebCamTexture _webcamTexture; 17 18 private const PredefinedDictionaryName dictName = PredefinedDictionaryName.Dict6X6_250; 19 private Dictionary ar_dict; 20 private DetectorParameters detect_param; 21 22 private void Start() 23 { 24 WebCamDevice[] devices = WebCamTexture.devices; 25 _webcamTexture = new WebCamTexture(devices[0].name, this._width, this._height, this._fps); 26 _webcamTexture.Play(); 27 28 29 } 30 31 32 void OnDestroy() 33 { 34 if (_webcamTexture != null) 35 { 36 if (_webcamTexture.isPlaying) _webcamTexture.Stop(); 37 _webcamTexture = null; 38 } 39 } 40 41 private void Update() 42 { 43 Armaker(_webcamTexture); 44 } 45 46 private void Armaker(WebCamTexture tex) 47 { 48 49 ar_dict = CvAruco.GetPredefinedDictionary(dictName); 50 detect_param = DetectorParameters.Create(); 51 Mat cam_frame = OpenCvSharp.Unity.TextureToMat(tex); 52 53 Point2f[][] corners; 54 int[] ids; 55 Point2f[][] reject_Points; 56 57 Mat grayMat = new Mat(); 58 Cv2.CvtColor(cam_frame, grayMat, ColorConversionCodes.BGR2GRAY); 59 60 CvAruco.DetectMarkers(grayMat, ar_dict, out corners, out ids, detect_param, out reject_Points); 61 CvAruco.DrawDetectedMarkers(cam_frame, corners, ids); 62 63 _renderer.texture = OpenCvSharp.Unity.MatToTexture(cam_frame); 64 } 65} 66

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

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

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

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

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

guest

回答1

0

Even if you calculate the average position of 4 corner points on the image, it is not match to the position where the center of marker appears in the image, generally.

I think that, you should use the intersection of 2 diagonals for more accuracy.

投稿2021/11/26 04:34

編集2021/11/26 04:34
fana

総合スコア11654

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問