如何将 UIImage 与 ARToolKitPlus 结合使用? (UIImage 到 CVImageBufferRef 转换)

发布于 2024-11-19 02:20:06 字数 848 浏览 6 评论 0原文

我有两种检测 AR 标记的算法(ARToolKit 和 Infi)。我让他们在 iPhone 上实时检测标记。在这个阶段我想比较他们的速度和准确性。我想准备一系列图像并测试它们的识别能力。 我可以使用 infi 做到这一点,但我无法将 ARToolKit 与 UIImage 一起使用。

ARToolKit 使用 CVImageBuffer 来识别标记:

- (Marker *)detectMarkerInImageBuffer:(CVImageBufferRef)imageBuffer {

    /*We lock the buffer and get the address of the first pixel*/
    CVPixelBufferLockBaseAddress(imageBuffer,0);
    unsigned char *baseAddress = (unsigned char *) CVPixelBufferGetBaseAddress(imageBuffer);
    tracker->calc(baseAddress);

如何使用/转换 UIImage 来实现 baseAddress,以便我可以将其发送到 tracker->calc ?

使用 infi,我首先从缓冲区创建 IplImage 或将 UIImage 转换为 IplImage然后在这两种情况下:

Buffer* buffer = new Buffer();

buffer->setBuffer( (unsigned char *) iplImg->imageData, iplImg->width, iplImg->height);

I have two algorithms, that detects AR markers (ARToolKit and Infi). I have them working on iPhone in real time detecting markers. At this stage i would like to compare their speed and accuracy. I would like to prepare a series of images and test recognition on them.
I can do that with infi, but i can't manage to use ARToolKit with UIImage.

ARToolKit uses CVImageBuffer to recognize markers:

- (Marker *)detectMarkerInImageBuffer:(CVImageBufferRef)imageBuffer {

    /*We lock the buffer and get the address of the first pixel*/
    CVPixelBufferLockBaseAddress(imageBuffer,0);
    unsigned char *baseAddress = (unsigned char *) CVPixelBufferGetBaseAddress(imageBuffer);
    tracker->calc(baseAddress);

How can I use/convert UIImage to achieve baseAddress, so i can send it to tracker->calc ?

With infi I first create IplImage from buffer or convert UIImage to IplImage and then in both cases:

Buffer* buffer = new Buffer();

buffer->setBuffer( (unsigned char *) iplImg->imageData, iplImg->width, iplImg->height);

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

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

发布评论

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

评论(1

铁轨上的流浪者 2024-11-26 02:20:06

我在这里找到了答案:如何将 UIImage 数组导出为电影?

这就是我正在寻找的

- (CVPixelBufferRef) pixelBufferFromCGImage: (CGImageRef) image
{
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
        [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
        [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
        nil];
    CVPixelBufferRef pxbuffer = NULL;
    CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, frameSize.width,
        frameSize.height, kCVPixelFormatType_32ARGB, (CFDictionaryRef) options, 
        &pxbuffer);
    NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);

    CVPixelBufferLockBaseAddress(pxbuffer, 0);
    void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer);
    NSParameterAssert(pxdata != NULL);

    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(pxdata, frameSize.width,
        frameSize.height, 8, 4*frameSize.width, rgbColorSpace, 
        kCGImageAlphaNoneSkipFirst);
    NSParameterAssert(context);
    CGContextConcatCTM(context, frameTransform);
    CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), 
        CGImageGetHeight(image)), image);
    CGColorSpaceRelease(rgbColorSpace);
    CGContextRelease(context);

    CVPixelBufferUnlockBaseAddress(pxbuffer, 0);

    return pxbuffer;
}

I found an answer here: How do I export UIImage array as a movie?

That is what i was looking for

- (CVPixelBufferRef) pixelBufferFromCGImage: (CGImageRef) image
{
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
        [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
        [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
        nil];
    CVPixelBufferRef pxbuffer = NULL;
    CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, frameSize.width,
        frameSize.height, kCVPixelFormatType_32ARGB, (CFDictionaryRef) options, 
        &pxbuffer);
    NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);

    CVPixelBufferLockBaseAddress(pxbuffer, 0);
    void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer);
    NSParameterAssert(pxdata != NULL);

    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(pxdata, frameSize.width,
        frameSize.height, 8, 4*frameSize.width, rgbColorSpace, 
        kCGImageAlphaNoneSkipFirst);
    NSParameterAssert(context);
    CGContextConcatCTM(context, frameTransform);
    CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), 
        CGImageGetHeight(image)), image);
    CGColorSpaceRelease(rgbColorSpace);
    CGContextRelease(context);

    CVPixelBufferUnlockBaseAddress(pxbuffer, 0);

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