在一个应用程序中使用两个库访问 iPhone 相机

发布于 2024-12-18 08:53:05 字数 250 浏览 0 评论 0原文

我的 iOS 应用程序应该同时执行以下两个任务:

  1. 使用 ZBar SDK 扫描 QR 标签,
  2. 使用 QCAR SDK 扫描增强现实标记。

或者换句话说:我正在寻找被 AR 标记包围的 QR 标签。

这两个任务都应该“实时”运行。我的第一个天真的方法表明,将两个 SDK 组合在一个应用程序中将导致第一个初始化的 SDK 在初始化第二个 SDK 时停止工作。

有人有建议吗?谢谢。

My iOS app is supposed to perform the following two tasks at the same time:

  1. scan for QR tags using the ZBar SDK,
  2. scan for augmented reality markers using the QCAR SDK.

Or in other words: I'm looking for QR tags surrounded by AR marker.

Both tasks should run in "real time". My first naive approach showed that combining both SDKs in one app will cause the SDK which was initialized first to stop working when the second SDK is initialized.

Does anybody have suggestions? Thanks.

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

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

发布评论

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

评论(2

烟酒忠诚 2024-12-25 08:53:06

我设法完成了这件事。如果有人想知道:

QCAR 仅适用于完全摄像头访问。因此,必须按照其文档中所示对其进行初始化和启动。幸运的是,它提供了对处理后的相机图像作为原始 RGB 数据的访问。我使用此代码将原始数据转换为 UIImage:

QCAR::setFrameFormat(QCAR::GRAYSCALE, true);
const QCAR::Image *image = state.getFrame().getImage(1); // 0: YUV, 1: Grayscale image
const char *data = (const char *)image->getPixels();
int width = image->getWidth(); int height = image->getHeight();

CGColorSpace *colorSpace = CGColorSpaceCreateDeviceGray();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGDataProvider *provider = CGDataProviderCreateWithData(NULL, data, width*height, NULL);
CGColorRenderingIntent intent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height, 8, 8, width * 1, colorSpace, bitmapInfo, provider, NULL, NO, intent);
myUIImage = [UIImage imageWithCGImage:imageRef];

现在,您可以使用 ZBar 的 ZBarImageScanner 类,如下所示:

ZBarImageScanner *imageScanner = [[ZBarImageScanner alloc] init];
ZBarImage *image = [[ZBarImage alloc] initWithCGImage:myUIImage.CGImage];
int result = [imageScanner scanImage:image];

if (result > 0) {
 ZBarSymbolSet *symbols = imageScanner.results;
 for(ZBarSymbol *symbol in symbols) {
  NSLog(@"%@", symbol.data);
 }
}

I managed to get that done. In case someone likes to know:

QCAR only works with full camera access. Therefore, it has to be initialized and started as shown in its documentation. Luckily, it provides access to the processed camera image as raw RGB data. I used this code to convert the raw data into an UIImage:

QCAR::setFrameFormat(QCAR::GRAYSCALE, true);
const QCAR::Image *image = state.getFrame().getImage(1); // 0: YUV, 1: Grayscale image
const char *data = (const char *)image->getPixels();
int width = image->getWidth(); int height = image->getHeight();

CGColorSpace *colorSpace = CGColorSpaceCreateDeviceGray();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGDataProvider *provider = CGDataProviderCreateWithData(NULL, data, width*height, NULL);
CGColorRenderingIntent intent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height, 8, 8, width * 1, colorSpace, bitmapInfo, provider, NULL, NO, intent);
myUIImage = [UIImage imageWithCGImage:imageRef];

Now, you can use ZBar's ZBarImageScanner class like this:

ZBarImageScanner *imageScanner = [[ZBarImageScanner alloc] init];
ZBarImage *image = [[ZBarImage alloc] initWithCGImage:myUIImage.CGImage];
int result = [imageScanner scanImage:image];

if (result > 0) {
 ZBarSymbolSet *symbols = imageScanner.results;
 for(ZBarSymbol *symbol in symbols) {
  NSLog(@"%@", symbol.data);
 }
}
茶花眉 2024-12-25 08:53:06

您一次只能运行一个相机会话,因此您需要弄清楚如何让 ZBar 和 QCar 使用同一个相机会话。

You can only have one camera session running at a time so you'll need to figure out how to get ZBar and QCar to use the same one.

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