所以我在学校做了一个功课,列出了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架构下进行编译可以解决大多数错误(很少剩下)。
答案 0 :(得分:0)
尝试添加#import <QuickTime/QuickTimeComponents.h>
并与QuickTime.framework链接。
答案 1 :(得分:0)
正如您所发现的,编译i386而不是x64有很大帮助。
其余的,我添加了
ComponentInstance seqGrabber;
SGChannel videoChannel;
代码,并且编译成功。