【问题标题】:Capturing camera list on mac os x does not compile在 mac os x 上捕获相机列表无法编译
【发布时间】:2011-02-22 17:57:33
【问题描述】:

所以我在学校有一个家庭作业,列出了 mac OS X 上可用的相机,但我必须在 xcode 下用 C++ 完成。我创建了这样的代码:

#include <iostream>
#include <sstream>
#include <string.h>
#include <Quicktime/quicktime.h>
//#include <boost/lexical_cast.hpp>

using namespace std;

int main()
{

        int i = 0;
        int selectedIndex;

        cout << endl << "Let us select video device." << endl << "Available capture devices are:" << endl;


  // first get a video channel from the sequence grabber

   ComponentDescription    theDesc;
   Component               sgCompID;
   ComponentResult         result;
   theDesc.componentType           = SeqGrabComponentType;
   theDesc.componentSubType        = 0L;
   theDesc.componentManufacturer   = 'appl';
   theDesc.componentFlags          = 0L;
   theDesc.componentFlagsMask      = 0L;   
   sgCompID = FindNextComponent (NULL, &theDesc);
   seqGrabber = OpenComponent (sgCompID);
   result = SGInitialize (seqGrabber);
   result = SGNewChannel (seqGrabber, VideoMediaType, &videoChannel);
   SGDeviceList  theDevices;
   SGGetChannelDeviceList(videoChannel, sgDeviceListDontCheckAvailability | sgDeviceListIncludeInputs, &theDevices);

    if (theDevices)
    {
        int theDeviceIndex;
        for (theDeviceIndex = 0; theDeviceIndex != (*theDevices)->count; ++theDeviceIndex)
        {
            SGDeviceName theDeviceEntry = (*theDevices)->entry[theDeviceIndex];
            cout << i << ".1. " <<  theDeviceEntry.name << endl; 
            // name of device is a pstring in theDeviceEntry.name

        SGDeviceInputList theInputs = theDeviceEntry.inputs;
            if (theInputs != NULL)
            {
                int theInputIndex;
                for ( theInputIndex = 0; theInputIndex != (*theInputs)->count; ++theInputIndex)
                {
                    SGDeviceInputName theInput = (*theInputs)->entry[theInputIndex];
                    cout << i << ".2. " << theInput.name << endl;       
                    // name of input is a pstring in theInput.name
                }
            }
        }       
    } // i++ we need to add...


        selectedIndex = 999;
        if (i <= 0)
        {
                cout << "No devices found." << endl;
                return 999;
        }
        else if (i == 1)
        {
                cout << "Default device will be used.\n" << endl;
                selectedIndex = 0;
        }
        else
        {
                while (selectedIndex > i - 1 || selectedIndex < 0)
                {
                        try
                        {
                                cin >> selectedIndex;
                                //string s;
                                //getline(cin, s, '\n');
                                //selectedIndex = boost::lexical_cast<int>(s);
                        }
                        catch(std::exception& e)
                        {
                                cout << "Please input index from 0 to " << i - 1 << endl;
                                selectedIndex = 999;
                        }
                }
        }
        return selectedIndex;
}

它不编译。它显示了很多关于 SeqGrabComponentType 的奇怪错误,但我是 mac C++ nube 并且不知道该怎么做 - 如何让我的应用程序编译请帮忙?

更新:

错误列表:

camerasList: In function 'int main()':
camerasList:49: error: 'SeqGrabComponentType' was not declared in this scope
camerasList:55: error: 'seqGrabber' was not declared in this scope
camerasList:56: error: 'SGInitialize' was not declared in this scope
camerasList:57: error: 'videoChannel' was not declared in this scope
camerasList:57: error: 'SGNewChannel' was not declared in this scope
camerasList:58: error: 'SGDeviceList' was not declared in this scope
camerasList:58: error: expected `;' before 'theDevices'
camerasList:59: error: 'sgDeviceListDontCheckAvailability' was not declared in this scope
camerasList:59: error: 'sgDeviceListIncludeInputs' was not declared in this scope
camerasList:59: error: 'theDevices' was not declared in this scope
camerasList:59: error: 'SGGetChannelDeviceList' was not declared in this scope
camerasList:66: error: 'SGDeviceName' was not declared in this scope
camerasList:66: error: expected `;' before 'theDeviceEntry'
camerasList:67: error: 'theDeviceEntry' was not declared in this scope
camerasList:70: error: 'SGDeviceInputList' was not declared in this scope
camerasList:70: error: expected `;' before 'theInputs'
camerasList:71: error: 'theInputs' was not declared in this scope
camerasList:76: error: 'SGDeviceInputName' was not declared in this scope
camerasList:76: error: expected `;' before 'theInput'
camerasList:77: error: 'theInput' was not declared in this scope

更新:

问题解决了一半:在 i386 架构下编译解决了大部分错误(剩下的几个)。

【问题讨论】:

  • 你能提供一些错误吗?
  • 缺少任何定义的标头 SeqGrabComponentType 等
  • SeqGrabComponentType 已在 quicktime.h 中声明,但无法 goToDefenition...

标签: c++ macos camera device


【解决方案1】:

尝试添加#import &lt;QuickTime/QuickTimeComponents.h&gt; 并与 QuickTime.framework 链接。

【讨论】:

  • 它会在x64下编译吗?
  • 我很确定 Quicktime 不是 64 位的。
【解决方案2】:

如您所见,针对 i386 而非 x64 进行编译有很大帮助。

剩下的,我加了

   ComponentInstance    seqGrabber;
   SGChannel            videoChannel;

到你的代码,它编译成功。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 2016-10-12
    • 1970-01-01
    相关资源
    最近更新 更多