我想在iOS上使用DeepLearningKit。我想使用UIImage对象进行分类。该示例应用程序仅使用从json文件加载的float数组。因此,我必须将UIImage的位图表示形式创建为float数组,并将其用于classify-method。

有人可以帮我吗?有没有一种方法可以为UIImage创建位图表示形式?此外,我必须将通道从RGB交换到BGR。

谢谢

最佳答案

向UIImage添加了扩展,该扩展允许直接设置和获取RGB(A)像素-关键方法:

public func setPixelColorAtPoint(point:CGPoint, color: RawColorType) -> UIImage?
func getPixelColorAtLocation(point:CGPoint)->UIColor?


其中RawColorType定义为

public typealias RawColorType = (newRedColor:UInt8, newgreenColor:UInt8, newblueColor:UInt8,  newalphaValue:UInt8)


这样,您应该能够在位图表示形式和UIImage之间来回转换。写了一篇博客文章,提供了更多背景信息:http://deeplearningkit.org/tutorials-for-ios-os-x-and-tvos/tutorial-image-handling-in-deeplearningkit/

关于ios - 将UIImage加载到float数组以供DeepLearningKit使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35088440/

10-12 23:09