How do I binarize a CGImage using OpenCV on iOS?(如何在 iOS 上使用 OpenCV 对 CGImage 进行二值化?)
问题描述
在我的 iOS 项目中,我有一个 RGB 格式的 CGImage,我想对其进行二值化(转换为黑白).我想使用 OpenCV 来做到这一点,但我是 OpenCV 的新手.我找到了一本关于 OpenCV 的书,但它不适用于 iPhone.
In my iOS project, I have a CGImage in RGB that I'd like to binarize (convert to black and white). I would like to use OpenCV to do this, but I'm new to OpenCV. I found a book on OpenCV, but it was not for iPhone.
如何在 iOS 上使用 OpenCV 对这样的图像进行二值化?
How can I binarize such an image using OpenCV on iOS?
推荐答案
如果你不想在你的 iOS 项目中设置 OpenCV,我的开源 GPUImage 框架内部有两个阈值过滤器,用于图像的二值化,一个简单阈值和一个基于像素附近局部亮度的自适应阈值.
If you don't want to set up OpenCV in your iOS project, my open source GPUImage framework has two threshold filters within it for binarization of images, a simple threshold and an adaptive one based on local luminance near a pixel.
您可以对图像应用一个简单的阈值,然后使用如下代码提取生成的二值化 UIImage:
You can apply a simple threshold to an image and then extract a resulting binarized UIImage using code like the following:
UIImage *inputImage = [UIImage imageNamed:@"inputimage.png"];
GPUImageLuminanceThresholdFilter *thresholdFilter = [[GPUImageLuminanceThresholdFilter alloc] init];
thresholdFilter.threshold = 0.5;
UIImage *thresholdFilter = [thresholdFilter imageByFilteringImage:inputImage];
(如果您的应用程序中不使用 ARC,请释放上述过滤器)
(release the above filter if not using ARC in your application)
如果您希望将此图像显示到屏幕上,可以将阈值输出发送到 GPUImageView.如果您愿意,您还可以使用这些过滤器处理实时视频,因为它们完全在 GPU 上运行.
If you wish to display this image to the screen instead, you can send the thresholded output to a GPUImageView. You can also process live video with these filters, if you wish, because they are run entirely on the GPU.
这篇关于如何在 iOS 上使用 OpenCV 对 CGImage 进行二值化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 上使用 OpenCV 对 CGImage 进行二值化?


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01