LoginSignup
1
0

More than 3 years have passed since last update.

【解決】openFrameworks + Xcode10 で ofVideoGrabber が正常に動かなかった件

Last updated at Posted at 2020-05-01

使用環境

  • openFrameworks (0.10.0)
  • Xcode 10.0.0
  • macOS Mojave (10.14.6)

背景

最近、ちょっと久しぶりに openFrameworks を触っています。
やっぱり oF は楽しくもあり難しくもあるなあ、なんて感じる今日この頃です。

さてそんな折、videoGrabber を使ってカメラ映像を取得しようとしたのですが、なぜか動作しない...。
Build 自体は正常に終わるのですが、どうも内部の方でエラーが発生している様子でした。

結果から言うと、無事に解決しました
なので備忘録がてら、今回は「解決編」としてまとめます。誰かのお役に立てば幸いです。

症状

Build は正常に終わるが、実行中に一部 Thread でエラーが発生する。

今回のサンプルは下記の通り。ofVideoGrabber を使い、カメラ画像をそのまま描画するプログラムです(一部省略)。

main.cpp
#include "ofMain.h"
#include "ofApp.h"

//========================================================================
int main( ){
    ofSetupOpenGL(1024,768,OF_WINDOW);          // <-------- setup the GL context

    // this kicks off the running of my app
    // can be OF_WINDOW or OF_FULLSCREEN
    // pass in width and height too:
    ofRunApp(new ofApp());

}
ofApp.h
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

    public:
        void setup();
        void update();
        void draw();

        ...

        ofVideoGrabber camera;
};
ofApp.cpp
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofBackground(255);
    ofSetVerticalSync(true);

    camera.initGrabber(320, 240);
}

//--------------------------------------------------------------
void ofApp::update(){
    camera.update();
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(255);
    camera.draw(0, 0);
}
...

上記を実行すると、発生するエラーコードは下記の通り。

2020-05-01 16:01:43.478424+0900 testDebug[36039:1352826] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported
2020-05-01 16:01:43.478474+0900 testDebug[36039:1352826] MessageTracer: Falling back to default whitelist
2020-05-01 16:01:44.883159+0900 testDebug[36039:1352504] [] CMIO_Unit_ScopeElement.h:200:SafeGetElement Throwing err: -67454
2020-05-01 16:01:44.890902+0900 testDebug[36039:1352504] [] CMIOUnitFigBaseObjectImpl.c:246:CMIOUnitCreateFromDescription Invalid paramater
2020-05-01 16:01:44.936328+0900 testDebug[36039:1352504] [] CMIO_Unit_Input_Device.cpp:244:GetPropertyInfo CMIOUInputFromProcs::GetPropertyInfo() failed for id 102, Error: -67456
2020-05-01 16:01:44.958302+0900 testDebug[36039:1352826] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
(lldb) 

解決方法

対象のプロジェクト内にある openFrameworks-info.plist を編集してプロパティを追加する。

  1. Xcode から openFrameworks-info.plist を開く。このとき、右クリックから Open As --> Source Code を選択し、XML形式のソースコードの状態で開く。
  2. <dict> タグ以下にある <key> <string> 一覧の末尾に、下記を追記する。

    <key>NSCameraUsageDescription</key>
    <string>This app needs to access the camera</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs to access the microphone</string>
    
  3. 変更を保存し、プロパティキーが正常に追加されたことを確認する。右クリックから Open As --> Property List を選択し、追加したキーが反映されていたら正常。

  4. 再び Build & Run

解説

どうやら、カメラを利用するために必要なプロパティが足りてなかったことが原因だったようです。
(たしかにメッセージをよく見てみると GetPropertyInfo() failed for id 102, Error: -67456 と出ていた...。)

なにやら、本来(以前まで?)は自動生成されていたプロパティですが、Xcode10 では自動生成されないそうです。Xcode10 が i386 に対応してないことが理由だとか...?
とにかく、それらプロパティキーを手打ちで追加してあげる必要があったんですね。

ちなみに、音声入力についても同じような症状が起こるらしいです...(未確認)。
ですが上記と同じ方法で解消できるそうなので、お困りの方は是非試してみてください。

参考サイト

検索ワード

  • "CMIO_Unit_ScopeElement.h:200:SafeGetElement Throwing err: -67454"
  • openframeworks+Xcode10+camera+error

サイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0