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

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

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

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

Unity

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

Q&A

0回答

1163閲覧

unityでWebカメラを実装しようとしたがエラーがでてしまい解決したい

himel

総合スコア0

C#

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

Unity

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

0グッド

1クリップ

投稿2021/10/24 06:02

以下のプログラムをUnity上の適当なオブジェクトにアタッチして、cam_frame(カメラの映像)をテクスチャとしてオブジェクトに反映させたのですが、以下のエラーが出てしまいました。
Object reference not set to an instance of an object webcam.Update () 写真のような操作は間違っているのでしょうか。ご教授していただけると幸いです。

イメージ説明

using System.Collections; using System.Collections.Generic; using UnityEngine; using OpenCvSharp; using OpenCvSharp.Aruco; public class webcam : MonoBehaviour { private int source = 0; private VideoCapture cam; public Mat cam_frame; private const PredefinedDictionaryName dictName = PredefinedDictionaryName.Dict4X4_50; private Dictionary ar_dict; private DetectorParameters detect_param; void Start () { cam = new VideoCapture(source); cam.Set(CaptureProperty.ConvertRgb,3); cam_frame = new Mat(); ar_dict = CvAruco.GetPredefinedDictionary(dictName); detect_param = DetectorParameters.Create(); } void Update () { Point2f[][] maker_corners; int[] maker_ids; Point2f[][] reject_points; cam.Read(cam_frame); CvAruco.DetectMarkers(cam_frame, ar_dict, out maker_corners, out maker_ids, detect_param, out reject_points); if(maker_ids.Length > 0){ CvAruco.DrawDetectedMarkers(cam_frame, maker_corners, maker_ids, new Scalar(0, 255, 0)); } } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class camtexture_cam : MonoBehaviour { public webcam _webcam; private Texture2D cam_Texture; void Start () { cam_Texture = new Texture2D( 640, 480, TextureFormat.YUY2, false ); this.GetComponent<Rendere>().material.mainTexture = cam_Texture; } void Update () { cam_Texture.LoadImage(_webcam.cam_frame.ImEncode()); } }

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問