gpt4 book ai didi

ios - 将 UIImage 加载到 float 组以供 DeepLearningKit 使用

转载 作者:行者123 更新时间:2023-11-29 01:16:46 25 4
gpt4 key购买 nike

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

有人可以帮我吗?有没有办法为 UIImage 创建位图表示?此外,我必须将 channel 从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com