现有UIImage上的GPUImage哈里斯角落检测提供黑屏输出 [英] GPUImage Harris Corner Detection on an existing UIImage gives a black screen output

查看:67
本文介绍了现有UIImage上的GPUImage哈里斯角落检测提供黑屏输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地将十字线生成器和harris拐角检测过滤器添加到了GPUImageStillCamera输出以及GPUImageVideoCamera的实况视频上.

I've successfully added a crosshair generator and harris corner detection filter onto a GPUImageStillCamera output, as well as on live video from GPUImageVideoCamera.

我现在正在尝试在UIImageView上放置的照片上进行此处理,但是会不断得到黑屏作为输出.我一直在阅读关于布拉德·拉尔森(Brad Larson)的GPUImage项目在GitHub上列出的问题,但是它们似乎更多地与混合类型过滤器有关,按照那里的建议,我仍然面临着同样的问题.

I'm now trying to get this working on a photo set on a UIImageView, but continually get a black screen as the output. I have been reading the issues listed on GitHub against Brad Larson's GPUImage project, but they seemed to be more in relation to blend type filters, and following the suggestions there I still face the same problem.

我尝试更改每行代码以遵循我所看到的各种示例,并遵循Filter演示项目中的Brad的示例代码,但是结果始终是相同的.

I've tried altering every line of code to follow various examples I have seen, and to follow Brad's example code in the Filter demo projects, but the result is always the same.

我当前的代码是,一旦我拍了张照片(目前要检查以确保它不仅仅是一张黑照片):

My current code is, once I've taken a photo (which I check to make sure it is not just a black photo at this point):

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:self.photoView.image];

GPUImageHarrisCornerDetectionFilter *cornerFilter1 = [[GPUImageHarrisCornerDetectionFilter alloc] init];
[cornerFilter1 setThreshold:0.1f];
[cornerFilter1 forceProcessingAtSize:self.photoView.frame.size];

GPUImageCrosshairGenerator *crossGen = [[GPUImageCrosshairGenerator alloc] init];
crossGen.crosshairWidth = 15.0;
[crossGen forceProcessingAtSize:self.photoView.frame.size];

[cornerFilter1 setCornersDetectedBlock:^(GLfloat* cornerArray, NSUInteger cornersDetected, CMTime frameTime, BOOL endUpdating)
{
    [crossGen renderCrosshairsFromArray:cornerArray count:cornersDetected frameTime:frameTime];
}];


[stillImageSource addTarget:crossGen];
[crossGen addTarget:cornerFilter1];

[crossGen prepareForImageCapture];
[stillImageSource processImage];

UIImage *currentFilteredImage = [crossGen imageFromCurrentlyProcessedOutput];
UIImageWriteToSavedPhotosAlbum(currentFilteredImage, nil, nil, nil);
[self.photoView setImage:currentFilteredImage];

我在两个滤镜上都尝试过prepareForImageCapture,在两个滤镜上都没有尝试,以相反的顺序添加了两个目标,在两个滤镜上都调用了imageFromCurrentlyProcessedOutput,我尝试了没有十字准线发生器的尝试,我尝试了使用本地.h文件中声明的变量和变量.我已经尝试过在每个过滤器上使用forceProcessingAtSize和不使用forceProcessingAtSize.

I've tried prepareForImageCapture on both filters, on neither, adding the two targets in the opposite order, calling imageFromCurrentlyProcessedOutput on either filter, I've tried it without the crosshair generator, I've tried using local variables and variables declared in the .h file. I've tried with and without forceProcessingAtSize on each of the filters.

我想不出没有尝试获得输出的任何其他信息.该应用程序在Xcode 5.0.1的iPhone 7.0上运行.标准滤镜可在照片上使用,例如SimpleImageFilter测试应用程序中包含的简单GPUImageSobelEdgeDetectionFilter.

I can't think of anything else that I haven't tried to get the output. The app is running on iPhone 7.0, in Xcode 5.0.1. The standard filters work on the photo, e.g. the simple GPUImageSobelEdgeDetectionFilter included in the SimpleImageFilter test app.

有什么建议吗?我将输出保存到相机胶卷中,以便可以检查不仅仅是我无法正确显示它.我怀疑这是一个愚蠢的错误,但是对于现在尝试其他方法却茫然不知所措.

Any suggestions? I am saving the output to the camera roll so I can check it's not just me failing to display it correctly. I suspect it's a stupid mistake somewhere but am at a loss as to what else to try now.

谢谢.

编辑后添加:拐角检测绝对有效,根据我设置的阈值,它返回6至511个拐角.

Edited to add: the corner detection is definitely working, as depending on the threshold I set, it returns between 6 and 511 corners.

推荐答案

上述问题是您没有按照正确的顺序链接过滤器.哈里斯拐角检测器接收输入图像,在其中找到拐角,并提供回调块以返回这些拐角. GPUImageCrosshairGenerator接收这些点并创建拐角的视觉表示.

The problem with the above is that you're not chaining filters in the proper order. The Harris corner detector takes in an input image, finds the corners within it, and provides the callback block to return those corners. The GPUImageCrosshairGenerator takes in those points and creates a visual representation of the corners.

以上代码中的内容是image-> GPUImageCrosshairGenerator-> GPUImageHarrisCornerDetectionFilter,它实际上不会做任何事情.

What you have in the above code is image->GPUImageCrosshairGenerator-> GPUImageHarrisCornerDetectionFilter, which won't really do anything.

答案中的代码确实直接从图像转到GPUImageHarrisCornerDetectionFilter,但是您不想使用该图像输出.如您所见,它产生的图像的拐角由黑色背景上的白点标识.而是使用回调块,该块将对其进行处理并返回一个标准化的角坐标数组供您使用.

The code in your answer does go directly from the image to the GPUImageHarrisCornerDetectionFilter, but you don't want to use the image output from that. As you saw, it produces an image where the corners are identified by white dots on a black background. Instead, use the callback block, which processes that and returns an array of normalized corner coordinates for you to use.

如果需要使这些可见,则可以采用该坐标数组并将其输入到GPUImageCrosshairGenerator中以创建可见的十字准线,但是该图像将需要与原始图像混合才能有意义.这是我在FilterShowcase示例中所做的.

If you need these to be visible, you could then take that array of coordinates and feed it into the GPUImageCrosshairGenerator to create visible crosshairs, but that image will need to be blended with your original image to make any sense. This is what I do in the FilterShowcase example.

这篇关于现有UIImage上的GPUImage哈里斯角落检测提供黑屏输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆