在 mac os x 上捕获相机列表无法编译

发布于 2024-10-19 02:21:32 字数 4972 浏览 4 评论 0原文

所以我在学校有一个作业要列出 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架构下编译解决了大部分错误(剩下很少)。

So I've got a homework at school to list cameras available on mac OS X but I have to do it in C++ under xcode. I created such code:

#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;
}

It does not compile. It show lots of strange errors about SeqGrabComponentType but I am mac C++ nube and do not know what to do - how to make my app compile please help?

Update:

Errors list:

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

Update:

Half of problem solution: Compiling under i386 architecture solves most errors (few left).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱冒险 2024-10-26 02:21:33

正如您所发现的,针对 i386 进行编译比针对 x64 进行编译有很大帮助。

对于其余的,我添加

   ComponentInstance    seqGrabber;
   SGChannel            videoChannel;

到您的代码中,并且它编译成功。

As you found, compiling for i386 as opposed to x64 helps a lot.

For the rest, I added

   ComponentInstance    seqGrabber;
   SGChannel            videoChannel;

to your code, and it compiled successfully.

意中人 2024-10-26 02:21:32

尝试添加 #import 并与 QuickTime.framework 链接。

Try to add #import <QuickTime/QuickTimeComponents.h> and link with QuickTime.framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文